Documentation
¶
Index ¶
- Constants
- Variables
- func GetAbsolutePath(targetDir string) string
- func GetRuntimeBlob(testRuntimeFilePath, testRuntimeURL string) (n int64, err error)
- func GetRuntimeVars(targetRuntime string) (string, string, func() (*wasm.Imports, error))
- func RegisterImports() (*wasm.Imports, error)
- type API_Item
- type Ctx
- type FreeingBumpHeapAllocator
- type Runtime
- func NewRuntime(code []byte, s Storage, ks *keystore.Keystore, ...) (*Runtime, error)
- func NewRuntimeFromFile(fp string, s Storage, ks *keystore.Keystore, ...) (*Runtime, error)
- func NewTestRuntime(t *testing.T, targetRuntime string) *Runtime
- func NewTestRuntimeWithTrie(t *testing.T, targetRuntime string, tt *trie.Trie) *Runtime
- func (r *Runtime) ApplyExtrinsic(data types.Extrinsic) ([]byte, error)
- func (r *Runtime) BabeConfiguration() (*types.BabeConfiguration, error)
- func (r *Runtime) Exec(function string, data []byte) ([]byte, error)
- func (r *Runtime) FinalizeBlock() (*types.Header, error)
- func (r *Runtime) GrandpaAuthorities() ([]*types.AuthorityData, error)
- func (r *Runtime) InherentExtrinsics(data []byte) ([]byte, error)
- func (r *Runtime) InitializeBlock(header *types.Header) error
- func (r *Runtime) Load(location, length int32) []byte
- func (r *Runtime) Stop()
- func (r *Runtime) Store(data []byte, location int32)
- func (r *Runtime) ValidateTransaction(e types.Extrinsic) (*transaction.Validity, error)
- type Storage
- type TestRuntimeStorage
- func (trs TestRuntimeStorage) ClearStorage(key []byte) error
- func (trs TestRuntimeStorage) Entries() map[string][]byte
- func (trs TestRuntimeStorage) GetBalance(key [32]byte) (uint64, error)
- func (trs TestRuntimeStorage) GetStorage(key []byte) ([]byte, error)
- func (trs TestRuntimeStorage) GetStorageFromChild(keyToChild, key []byte) ([]byte, error)
- func (trs TestRuntimeStorage) SetBalance(key [32]byte, balance uint64) error
- func (trs TestRuntimeStorage) SetStorage(key []byte, value []byte) error
- func (trs TestRuntimeStorage) SetStorageChild(keyToChild []byte, child *trie.Trie) error
- func (trs TestRuntimeStorage) SetStorageIntoChild(keyToChild, key, value []byte) error
- func (trs TestRuntimeStorage) StorageRoot() (common.Hash, error)
- func (trs TestRuntimeStorage) TrieAsString() string
- type Version
- type VersionAPI
Constants ¶
const ( POLKADOT_RUNTIME_c768a7e4c70e = "polkadot_runtime" POLKADOT_RUNTIME_FP_c768a7e4c70e = "substrate_test_runtime.compact.wasm" POLKADOT_RUNTIME_URL_c768a7e4c70e = "" /* 167-byte string literal not displayed */ TEST_RUNTIME = "test_runtime" TESTS_FP = "test_wasm.wasm" TEST_WASM_URL = "https://github.com/ChainSafe/gossamer-test-wasm/blob/noot/target/wasm32-unknown-unknown/release/test_wasm.wasm?raw=true" SIMPLE_WASM_FP = "simple.wasm" SIMPLE_RUNTIME_URL = "https://github.com//wasmerio/go-ext-wasm/blob/master/wasmer/test/testdata/examples/simple.wasm?raw=true" )
nolint
const HeadsQty = 22
HeadsQty 22
const MaxPossibleAllocation = 16777216 // 2^24 bytes
MaxPossibleAllocation 2^24 bytes
Variables ¶
var ( // CoreVersion is the runtime API call Core_version CoreVersion = "Core_version" // CoreInitializeBlock is the runtime API call Core_initialize_block CoreInitializeBlock = "Core_initialize_block" // CoreExecuteBlock is the runtime API call Core_execute_block CoreExecuteBlock = "Core_execute_block" // Metadata_metadata is the runtime API call Metadata_metadata Metadata_metadata = "Metadata_metadata" // TaggedTransactionQueueValidateTransaction is the runtime API call TaggedTransactionQueue_validate_transaction TaggedTransactionQueueValidateTransaction = "TaggedTransactionQueue_validate_transaction" // AuraAPIAuthorities is the runtime API call AuraApi_authorities AuraAPIAuthorities = "AuraApi_authorities" // TODO: deprecated with newest runtime, should be Grandpa_authorities // BabeAPIConfiguration is the runtime API call BabeApi_configuration BabeAPIConfiguration = "BabeApi_configuration" // BlockBuilderInherentExtrinsics is the runtime API call BlockBuilder_inherent_extrinsics BlockBuilderInherentExtrinsics = "BlockBuilder_inherent_extrinsics" // BlockBuilderApplyExtrinsic is the runtime API call BlockBuilder_apply_extrinsic BlockBuilderApplyExtrinsic = "BlockBuilder_apply_extrinsic" // BlockBuilderFinalizeBlock is the runtime API call BlockBuilder_finalize_block BlockBuilderFinalizeBlock = "BlockBuilder_finalize_block" )
var ErrCannotValidateTx = errors.New("could not validate transaction")
ErrCannotValidateTx is returned if the call to runtime function TaggedTransactionQueueValidateTransaction fails
var ErrInvalidTransaction = &json2.Error{Code: 1010, Message: "Invalid Transaction"}
ErrInvalidTransaction is returned if the call to runtime function TaggedTransactionQueueValidateTransaction fails with
value of [1, 0, x]
var ErrUnknownTransaction = &json2.Error{Code: 1011, Message: "Unknown Transaction Validity"}
ErrUnknownTransaction is returned if the call to runtime function TaggedTransactionQueueValidateTransaction fails with
value of [1, 1, x]
var TestAuthorityDataKey, _ = common.HexToBytes("0xe3b47b6c84c0493481f97c5197d2554f")
TestAuthorityDataKey is the location of authority data in the storage trie
Functions ¶
func GetAbsolutePath ¶
GetAbsolutePath returns the completePath for a given targetDir
func GetRuntimeBlob ¶
GetRuntimeBlob checks if the test wasm @testRuntimeFilePath exists and if not, it fetches it from @testRuntimeURL
func GetRuntimeVars ¶
GetRuntimeVars returns the testRuntimeFilePath and testRuntimeURL
func RegisterImports ¶
RegisterImports registers the wasm imports for the old version of the substrate test runtime.
Types ¶
type FreeingBumpHeapAllocator ¶
type FreeingBumpHeapAllocator struct {
TotalSize uint32
// contains filtered or unexported fields
}
FreeingBumpHeapAllocator struct
func NewAllocator ¶
func NewAllocator(mem *wasm.Memory, ptrOffset uint32) *FreeingBumpHeapAllocator
NewAllocator Creates a new allocation heap which follows a freeing-bump strategy. The maximum size which can be allocated at once is 16 MiB.
Arguments ¶
- `mem` - A wasm.Memory to the available memory which is used as the heap.
- `ptrOffset` - The pointers returned by `Allocate()` start from this offset on. The pointer offset needs to be aligned to a multiple of 8, hence a padding might be added to align `ptrOffset` properly.
* returns a pointer to an initilized FreeingBumpHeapAllocator
func (*FreeingBumpHeapAllocator) Allocate ¶
func (fbha *FreeingBumpHeapAllocator) Allocate(size uint32) (uint32, error)
Allocate determines if there is space available in WASM heap to grow the heap by 'size'. If there is space
available it grows the heap to fit give 'size'. The heap grows is chunks of Powers of 2, so the growth becomes the next highest power of 2 of the requested size.
func (*FreeingBumpHeapAllocator) Deallocate ¶
func (fbha *FreeingBumpHeapAllocator) Deallocate(pointer uint32) error
Deallocate deallocates the memory located at pointer address
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime struct
func NewRuntime ¶
func NewRuntime(code []byte, s Storage, ks *keystore.Keystore, registerImports func() (*wasm.Imports, error)) (*Runtime, error)
NewRuntime instantiates a runtime from raw wasm bytecode
func NewRuntimeFromFile ¶
func NewRuntimeFromFile(fp string, s Storage, ks *keystore.Keystore, registerImports func() (*wasm.Imports, error)) (*Runtime, error)
NewRuntimeFromFile instantiates a runtime from a .wasm file
func NewTestRuntime ¶
NewTestRuntime will create a new runtime (polkadot/test)
func NewTestRuntimeWithTrie ¶
NewTestRuntimeWithTrie will create a new runtime (polkadot/test) with the supplied trie as the storage
func (*Runtime) ApplyExtrinsic ¶
ApplyExtrinsic calls runtime API function BlockBuilder_apply_extrinsic
func (*Runtime) BabeConfiguration ¶
func (r *Runtime) BabeConfiguration() (*types.BabeConfiguration, error)
BabeConfiguration gets the configuration data for BABE from the runtime
func (*Runtime) FinalizeBlock ¶
FinalizeBlock calls runtime API function BlockBuilder_finalize_block
func (*Runtime) GrandpaAuthorities ¶
func (r *Runtime) GrandpaAuthorities() ([]*types.AuthorityData, error)
GrandpaAuthorities returns the genesis authorities from the runtime TODO: this seems to be out-of-date, the call is now named Grandpa_authorities and takes a block number.
func (*Runtime) InherentExtrinsics ¶
InherentExtrinsics calls runtime API function BlockBuilder_inherent_extrinsics
func (*Runtime) InitializeBlock ¶
InitializeBlock calls runtime API function Core_initialize_block
func (*Runtime) ValidateTransaction ¶
ValidateTransaction runs the extrinsic through runtime function TaggedTransactionQueue_validate_transaction and returns *Validity
type Storage ¶
type Storage interface {
SetStorage(key []byte, value []byte) error
GetStorage(key []byte) ([]byte, error)
StorageRoot() (common.Hash, error)
SetStorageChild(keyToChild []byte, child *trie.Trie) error
SetStorageIntoChild(keyToChild, key, value []byte) error
GetStorageFromChild(keyToChild, key []byte) ([]byte, error)
ClearStorage(key []byte) error
Entries() map[string][]byte
SetBalance(key [32]byte, balance uint64) error
GetBalance(key [32]byte) (uint64, error)
}
Storage interface
type TestRuntimeStorage ¶
type TestRuntimeStorage struct {
// contains filtered or unexported fields
}
TestRuntimeStorage holds trie pointer
func NewTestRuntimeStorage ¶
func NewTestRuntimeStorage(tr *trie.Trie) *TestRuntimeStorage
NewTestRuntimeStorage creates new instance of TestRuntimeStorage
func (TestRuntimeStorage) ClearStorage ¶
func (trs TestRuntimeStorage) ClearStorage(key []byte) error
ClearStorage is a dummy test func
func (TestRuntimeStorage) Entries ¶
func (trs TestRuntimeStorage) Entries() map[string][]byte
Entries is a dummy test func
func (TestRuntimeStorage) GetBalance ¶
func (trs TestRuntimeStorage) GetBalance(key [32]byte) (uint64, error)
GetBalance gets the balance for an account with the given public key
func (TestRuntimeStorage) GetStorage ¶
func (trs TestRuntimeStorage) GetStorage(key []byte) ([]byte, error)
GetStorage is a dummy test func
func (TestRuntimeStorage) GetStorageFromChild ¶
func (trs TestRuntimeStorage) GetStorageFromChild(keyToChild, key []byte) ([]byte, error)
GetStorageFromChild is a dummy test func
func (TestRuntimeStorage) SetBalance ¶
func (trs TestRuntimeStorage) SetBalance(key [32]byte, balance uint64) error
SetBalance sets the balance for an account with the given public key
func (TestRuntimeStorage) SetStorage ¶
func (trs TestRuntimeStorage) SetStorage(key []byte, value []byte) error
SetStorage is a dummy test func
func (TestRuntimeStorage) SetStorageChild ¶
func (trs TestRuntimeStorage) SetStorageChild(keyToChild []byte, child *trie.Trie) error
SetStorageChild is a dummy test func
func (TestRuntimeStorage) SetStorageIntoChild ¶
func (trs TestRuntimeStorage) SetStorageIntoChild(keyToChild, key, value []byte) error
SetStorageIntoChild is a dummy test func
func (TestRuntimeStorage) StorageRoot ¶
func (trs TestRuntimeStorage) StorageRoot() (common.Hash, error)
StorageRoot is a dummy test func
func (TestRuntimeStorage) TrieAsString ¶
func (trs TestRuntimeStorage) TrieAsString() string
TrieAsString is a dummy test func
type Version ¶
type Version struct {
Spec_name []byte
Impl_name []byte
Authoring_version int32
Spec_version int32
Impl_version int32
}
Version struct
type VersionAPI ¶
VersionAPI struct that holds Runtime Version info and API array
func (*VersionAPI) Decode ¶
func (v *VersionAPI) Decode(in []byte) error
Decode to scale decode []byte to VersionAPI struct