From 91a559c21abb3c2b22f529cf09789f9ca4a39b31 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Fri, 8 Oct 2021 17:55:41 -0400 Subject: [PATCH 01/14] implement ext_default_child_storage_storage_kill_version_3 --- lib/runtime/constants.go | 4 +- lib/runtime/wasmer/imports.go | 75 ++++++++++++++++++++++++++---- lib/runtime/wasmer/imports_test.go | 39 ++++++++++++++++ 3 files changed, 107 insertions(+), 11 deletions(-) diff --git a/lib/runtime/constants.go b/lib/runtime/constants.go index 643ffb4c28..c0cc273434 100644 --- a/lib/runtime/constants.go +++ b/lib/runtime/constants.go @@ -47,7 +47,9 @@ const ( // v0.8 test API wasm HOST_API_TEST_RUNTIME = "hostapi_runtime" HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" - HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/master/test/hostapi_runtime.compact.wasm?raw=true" + //HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/master/test/hostapi_runtime.compact.wasm?raw=true" + // TODO use above url once below branch has been merged + HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/ed/impl_ext_default_child_storage_storage_kill_version_3/test/hostapi_runtime.compact.wasm?raw=true" // v0.8 substrate runtime with modified name and babe C=(1, 1) DEV_RUNTIME = "dev_runtime" diff --git a/lib/runtime/wasmer/imports.go b/lib/runtime/wasmer/imports.go index 3fa88f3fe3..f1642f8133 100644 --- a/lib/runtime/wasmer/imports.go +++ b/lib/runtime/wasmer/imports.go @@ -62,7 +62,7 @@ package wasmer // extern void ext_default_child_storage_set_version_1(void *context, int64_t a, int64_t b, int64_t c); // extern void ext_default_child_storage_storage_kill_version_1(void *context, int64_t a); // extern int32_t ext_default_child_storage_storage_kill_version_2(void *context, int64_t a, int64_t b); -// extern int64_t ext_default_child_storage_storage_kill_version_3(void *context, int64_t a, int64_t b); +// extern int32_t ext_default_child_storage_storage_kill_version_3(void *context, int64_t a, int64_t b); // extern void ext_default_child_storage_clear_prefix_version_1(void *context, int64_t a, int64_t b); // extern int32_t ext_default_child_storage_exists_version_1(void *context, int64_t a, int64_t b); // @@ -87,6 +87,7 @@ package wasmer // extern int32_t ext_offchain_random_seed_version_1(void *context); // extern int64_t ext_offchain_submit_transaction_version_1(void *context, int64_t a); // extern int64_t ext_offchain_timestamp_version_1(void *context); +// extern void ext_offchain_sleep_until_version_1(void *context, int64_t a); // // extern void ext_storage_append_version_1(void *context, int64_t a, int64_t b); // extern int64_t ext_storage_changes_root_version_1(void *context, int64_t a); @@ -1146,21 +1147,66 @@ func ext_default_child_storage_storage_kill_version_2(context unsafe.Pointer, ch return 0 } +type NoneRemain uint32 +type SomeRemain uint32 + +func (nr NoneRemain) Index() uint { + return 0 +} +func (sr SomeRemain) Index() uint { + return 1 +} + //export ext_default_child_storage_storage_kill_version_3 -func ext_default_child_storage_storage_kill_version_3(context unsafe.Pointer, childStorageKeySpan, _ C.int64_t) C.int64_t { - logger.Debug("[ext_default_child_storage_storage_kill_version_3] executing...") - logger.Warn("[ext_default_child_storage_storage_kill_version_3] somewhat unimplemented") - // TODO: need to use `limit` parameter +func ext_default_child_storage_storage_kill_version_3(context unsafe.Pointer, childStorageKeySpan, lim C.int64_t) C.int32_t { + logger.Debug("executing...") instanceContext := wasm.IntoInstanceContext(context) ctx := instanceContext.Data().(*runtime.Context) storage := ctx.Storage - childStorageKey := asMemorySlice(instanceContext, childStorageKeySpan) - storage.DeleteChild(childStorageKey) - // TODO: this function returns a `KillStorageResult` which may be `AllRemoved` (0) or `SomeRemaining` (1) - return 0 + limitBytes := asMemorySlice(instanceContext, lim) + buf := &bytes.Buffer{} + buf.Write(limitBytes) + + limit, err := optional.NewBytes(true, nil).Decode(buf) + if err != nil { + logger.Warn("cannot generate limit", "error", err) + } + + deleted, all, err := storage.DeleteChildLimit(childStorageKey, limit) + if err != nil { + logger.Warn("cannot get child storage", "error", err) + return 0 + } + + vdt, err := scale.NewVaryingDataType(NoneRemain(0), SomeRemain(0)) + if err != nil { + logger.Warn("cannot create new varying data type", "error", err) + } + + if all { + err = vdt.Set(NoneRemain(deleted)) + } else { + err = vdt.Set(SomeRemain(deleted)) + } + if err != nil { + logger.Warn("cannot set varying data type", "error", err) + } + + encoded, err := scale.Marshal(vdt) + if err != nil { + logger.Warn("problem marshaling varying data type", "error", err) + } + + out, err := toWasmMemorySized(instanceContext, encoded, 5) + if err != nil { + logger.Warn("failed to allocate", "error", err) + return 0 + } + + return C.int32_t(out) } //export ext_allocator_free_version_1 @@ -1564,6 +1610,12 @@ func ext_offchain_timestamp_version_1(context unsafe.Pointer) C.int64_t { return 0 } +//export ext_offchain_sleep_until_version_1 +func ext_offchain_sleep_until_version_1(_ unsafe.Pointer, deadline C.int64_t) { + logger.Trace("executing...") + logger.Warn("unimplemented") +} + func storageAppend(storage runtime.Storage, key, valueToAppend []byte) error { nextLength := big.NewInt(1) var valueRes []byte @@ -2179,7 +2231,10 @@ func ImportsNodeRuntime() (*wasm.Imports, error) { //nolint if err != nil { return nil, err } - + _, err = imports.Append("ext_offchain_sleep_until_version_1", ext_offchain_sleep_until_version_1, C.ext_offchain_sleep_until_version_1) + if err != nil { + return nil, err + } _, err = imports.Append("ext_sandbox_instance_teardown_version_1", ext_sandbox_instance_teardown_version_1, C.ext_sandbox_instance_teardown_version_1) if err != nil { return nil, err diff --git a/lib/runtime/wasmer/imports_test.go b/lib/runtime/wasmer/imports_test.go index 46c3a0c1ff..50531f756a 100644 --- a/lib/runtime/wasmer/imports_test.go +++ b/lib/runtime/wasmer/imports_test.go @@ -1182,6 +1182,45 @@ func Test_ext_default_child_storage_storage_kill_version_2_limit_none(t *testing require.Nil(t, child) } +func Test_ext_default_child_storage_storage_kill_version_3(t *testing.T) { + inst := NewTestInstance(t, runtime.HOST_API_TEST_RUNTIME) + + tr := trie.NewEmptyTrie() + tr.Put([]byte(`key2`), []byte(`value2`)) + tr.Put([]byte(`key1`), []byte(`value1`)) + tr.Put([]byte(`key3`), []byte(`value3`)) + err := inst.ctx.Storage.SetChild(testChildKey, tr) + require.NoError(t, err) + + testLimitBytes := make([]byte, 4) + binary.LittleEndian.PutUint32(testLimitBytes, uint32(2)) + optLimit2 := optional.NewBytes(true, testLimitBytes) + + testCases := []struct { + key []byte + limit *optional.Bytes + expected []byte + }{ + {key: []byte(`fakekey`), limit: optLimit2, expected: []byte{0, 0, 0, 0, 0}}, + {key: testChildKey, limit: optLimit2, expected: []byte{1, 2, 0, 0, 0}}, + {key: testChildKey, limit: nil, expected: []byte{0, 1, 0, 0, 0}}, + } + + for _, test := range testCases { + encChildKey, err := scale.Marshal(test.key) + require.NoError(t, err) + encOptLimit, err := test.limit.Encode() + require.NoError(t, err) + res, err := inst.Exec("rtm_ext_default_child_storage_storage_kill_version_3", append(encChildKey, encOptLimit...)) + require.NoError(t, err) + + ptr := binary.LittleEndian.Uint32(res) + mem := inst.vm.Memory.Data()[ptr : ptr+5] + + require.Equal(t, test.expected, mem) + } +} + func Test_ext_storage_append_version_1(t *testing.T) { inst := NewTestInstance(t, runtime.HOST_API_TEST_RUNTIME) From bde6f4d25979adb1b0f63d675898ab6118e9c945 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Fri, 8 Oct 2021 18:03:56 -0400 Subject: [PATCH 02/14] go fmt --- lib/runtime/constants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/runtime/constants.go b/lib/runtime/constants.go index c0cc273434..3ec7ab3a46 100644 --- a/lib/runtime/constants.go +++ b/lib/runtime/constants.go @@ -45,8 +45,8 @@ const ( POLKADOT_RUNTIME_URL = "https://github.com/noot/polkadot/blob/noot/v0.8.25/polkadot_runtime.wasm?raw=true" // v0.8 test API wasm - HOST_API_TEST_RUNTIME = "hostapi_runtime" - HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" + HOST_API_TEST_RUNTIME = "hostapi_runtime" + HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" //HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/master/test/hostapi_runtime.compact.wasm?raw=true" // TODO use above url once below branch has been merged HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/ed/impl_ext_default_child_storage_storage_kill_version_3/test/hostapi_runtime.compact.wasm?raw=true" From 72c3a4a1b001e7cbf3a590ec27913087b6392694 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Mon, 11 Oct 2021 14:07:20 -0400 Subject: [PATCH 03/14] address PR comments --- lib/runtime/constants.go | 4 +--- lib/runtime/wasmer/imports.go | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/runtime/constants.go b/lib/runtime/constants.go index 3ec7ab3a46..c9d24016dc 100644 --- a/lib/runtime/constants.go +++ b/lib/runtime/constants.go @@ -47,9 +47,7 @@ const ( // v0.8 test API wasm HOST_API_TEST_RUNTIME = "hostapi_runtime" HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" - //HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/master/test/hostapi_runtime.compact.wasm?raw=true" - // TODO use above url once below branch has been merged - HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/ed/impl_ext_default_child_storage_storage_kill_version_3/test/hostapi_runtime.compact.wasm?raw=true" + HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/master/test/hostapi_runtime.compact.wasm?raw=true" // v0.8 substrate runtime with modified name and babe C=(1, 1) DEV_RUNTIME = "dev_runtime" diff --git a/lib/runtime/wasmer/imports.go b/lib/runtime/wasmer/imports.go index f1642f8133..fc340e1570 100644 --- a/lib/runtime/wasmer/imports.go +++ b/lib/runtime/wasmer/imports.go @@ -1178,7 +1178,7 @@ func ext_default_child_storage_storage_kill_version_3(context unsafe.Pointer, ch deleted, all, err := storage.DeleteChildLimit(childStorageKey, limit) if err != nil { logger.Warn("cannot get child storage", "error", err) - return 0 + return C.int32_t(0) } vdt, err := scale.NewVaryingDataType(NoneRemain(0), SomeRemain(0)) @@ -1193,11 +1193,13 @@ func ext_default_child_storage_storage_kill_version_3(context unsafe.Pointer, ch } if err != nil { logger.Warn("cannot set varying data type", "error", err) + return C.int32_t(0) } encoded, err := scale.Marshal(vdt) if err != nil { logger.Warn("problem marshaling varying data type", "error", err) + return C.int32_t(0) } out, err := toWasmMemorySized(instanceContext, encoded, 5) From f946c807158cc05cfb9c03abebb263bd0fad6312 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Mon, 11 Oct 2021 14:09:09 -0400 Subject: [PATCH 04/14] lint --- lib/runtime/constants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/runtime/constants.go b/lib/runtime/constants.go index c9d24016dc..643ffb4c28 100644 --- a/lib/runtime/constants.go +++ b/lib/runtime/constants.go @@ -45,8 +45,8 @@ const ( POLKADOT_RUNTIME_URL = "https://github.com/noot/polkadot/blob/noot/v0.8.25/polkadot_runtime.wasm?raw=true" // v0.8 test API wasm - HOST_API_TEST_RUNTIME = "hostapi_runtime" - HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" + HOST_API_TEST_RUNTIME = "hostapi_runtime" + HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/master/test/hostapi_runtime.compact.wasm?raw=true" // v0.8 substrate runtime with modified name and babe C=(1, 1) From 8155b82a7e0c9f6889641fc5f10a585f1f8bf97e Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Mon, 11 Oct 2021 14:28:12 -0400 Subject: [PATCH 05/14] remove unused receivers --- lib/runtime/wasmer/imports.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/runtime/wasmer/imports.go b/lib/runtime/wasmer/imports.go index fc340e1570..6c3dd1de9d 100644 --- a/lib/runtime/wasmer/imports.go +++ b/lib/runtime/wasmer/imports.go @@ -1150,10 +1150,10 @@ func ext_default_child_storage_storage_kill_version_2(context unsafe.Pointer, ch type NoneRemain uint32 type SomeRemain uint32 -func (nr NoneRemain) Index() uint { +func (NoneRemain) Index() uint { return 0 } -func (sr SomeRemain) Index() uint { +func (SomeRemain) Index() uint { return 1 } From 710b47291b104789e8e33dcff4bd7efcd851b24f Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Tue, 12 Oct 2021 13:05:03 -0400 Subject: [PATCH 06/14] skip tests with wasm errors --- lib/runtime/wasmer/exports_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/runtime/wasmer/exports_test.go b/lib/runtime/wasmer/exports_test.go index 1a3c3eeee8..a35faeffa8 100644 --- a/lib/runtime/wasmer/exports_test.go +++ b/lib/runtime/wasmer/exports_test.go @@ -63,6 +63,8 @@ func createTestExtrinsic(t *testing.T, rt runtime.Instance, genHash common.Hash, } func TestInstance_Version_NodeRuntime_v098(t *testing.T) { +// todo ed remove skip, testing wasm dependancies + t.Skip() expected := runtime.NewVersionData( []byte("node"), []byte("substrate-node"), @@ -1048,6 +1050,8 @@ func TestInstance_ExecuteBlock_PolkadotBlock1089328(t *testing.T) { } func TestInstance_DecodeSessionKeys(t *testing.T) { + // todo ed, remove skip when wasm blob works + t.Skip() keys := "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d34309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc3852042602634309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc3852042602634309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc38520426026" pubkeys, err := common.HexToBytes(keys) require.NoError(t, err) From 0c8181a41e35aabc970595053b5ee352d16b860b Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Tue, 12 Oct 2021 15:42:31 -0400 Subject: [PATCH 07/14] use updated test wasm --- lib/runtime/constants.go | 4 +++- lib/runtime/wasmer/exports_test.go | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/runtime/constants.go b/lib/runtime/constants.go index 643ffb4c28..c0cc273434 100644 --- a/lib/runtime/constants.go +++ b/lib/runtime/constants.go @@ -47,7 +47,9 @@ const ( // v0.8 test API wasm HOST_API_TEST_RUNTIME = "hostapi_runtime" HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" - HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/master/test/hostapi_runtime.compact.wasm?raw=true" + //HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/master/test/hostapi_runtime.compact.wasm?raw=true" + // TODO use above url once below branch has been merged + HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/ed/impl_ext_default_child_storage_storage_kill_version_3/test/hostapi_runtime.compact.wasm?raw=true" // v0.8 substrate runtime with modified name and babe C=(1, 1) DEV_RUNTIME = "dev_runtime" diff --git a/lib/runtime/wasmer/exports_test.go b/lib/runtime/wasmer/exports_test.go index a35faeffa8..64b3b739bd 100644 --- a/lib/runtime/wasmer/exports_test.go +++ b/lib/runtime/wasmer/exports_test.go @@ -63,8 +63,7 @@ func createTestExtrinsic(t *testing.T, rt runtime.Instance, genHash common.Hash, } func TestInstance_Version_NodeRuntime_v098(t *testing.T) { -// todo ed remove skip, testing wasm dependancies - t.Skip() + // todo ed, this fails with new branch, determine why expected := runtime.NewVersionData( []byte("node"), []byte("substrate-node"), @@ -75,7 +74,12 @@ func TestInstance_Version_NodeRuntime_v098(t *testing.T) { 2, ) - instance := NewTestInstance(t, runtime.NODE_RUNTIME_v098) + instance := NewTestInstance(t, runtime.NODE_RUNTIME_v098) // original + //instance := NewTestInstance(t, runtime.HOST_API_TEST_RUNTIME) + //instance := NewTestInstance(t, runtime.POLKADOT_RUNTIME_v0910 ) + //instance := NewTestInstance(t, runtime.POLKADOT_RUNTIME ) + //instance := NewTestInstance(t, runtime.NODE_RUNTIME ) + //instance := NewTestInstance(t, runtime.DEV_RUNTIME ) version, err := instance.Version() require.Nil(t, err) @@ -1051,7 +1055,7 @@ func TestInstance_ExecuteBlock_PolkadotBlock1089328(t *testing.T) { func TestInstance_DecodeSessionKeys(t *testing.T) { // todo ed, remove skip when wasm blob works - t.Skip() + //t.Skip() keys := "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d34309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc3852042602634309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc3852042602634309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc38520426026" pubkeys, err := common.HexToBytes(keys) require.NoError(t, err) From 0737ef9b2e4338874e9459b4311ea58ab93144d0 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Wed, 13 Oct 2021 15:54:16 -0400 Subject: [PATCH 08/14] change func to return i64 --- lib/runtime/wasmer/imports.go | 15 +++++++-------- lib/runtime/wasmer/imports_test.go | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/runtime/wasmer/imports.go b/lib/runtime/wasmer/imports.go index 6c3dd1de9d..aeec4cf079 100644 --- a/lib/runtime/wasmer/imports.go +++ b/lib/runtime/wasmer/imports.go @@ -62,7 +62,7 @@ package wasmer // extern void ext_default_child_storage_set_version_1(void *context, int64_t a, int64_t b, int64_t c); // extern void ext_default_child_storage_storage_kill_version_1(void *context, int64_t a); // extern int32_t ext_default_child_storage_storage_kill_version_2(void *context, int64_t a, int64_t b); -// extern int32_t ext_default_child_storage_storage_kill_version_3(void *context, int64_t a, int64_t b); +// extern int64_t ext_default_child_storage_storage_kill_version_3(void *context, int64_t a, int64_t b); // extern void ext_default_child_storage_clear_prefix_version_1(void *context, int64_t a, int64_t b); // extern int32_t ext_default_child_storage_exists_version_1(void *context, int64_t a, int64_t b); // @@ -1158,9 +1158,8 @@ func (SomeRemain) Index() uint { } //export ext_default_child_storage_storage_kill_version_3 -func ext_default_child_storage_storage_kill_version_3(context unsafe.Pointer, childStorageKeySpan, lim C.int64_t) C.int32_t { +func ext_default_child_storage_storage_kill_version_3(context unsafe.Pointer, childStorageKeySpan, lim C.int64_t) C.int64_t { logger.Debug("executing...") - instanceContext := wasm.IntoInstanceContext(context) ctx := instanceContext.Data().(*runtime.Context) storage := ctx.Storage @@ -1178,7 +1177,7 @@ func ext_default_child_storage_storage_kill_version_3(context unsafe.Pointer, ch deleted, all, err := storage.DeleteChildLimit(childStorageKey, limit) if err != nil { logger.Warn("cannot get child storage", "error", err) - return C.int32_t(0) + return C.int64_t(0) } vdt, err := scale.NewVaryingDataType(NoneRemain(0), SomeRemain(0)) @@ -1193,22 +1192,22 @@ func ext_default_child_storage_storage_kill_version_3(context unsafe.Pointer, ch } if err != nil { logger.Warn("cannot set varying data type", "error", err) - return C.int32_t(0) + return C.int64_t(0) } encoded, err := scale.Marshal(vdt) if err != nil { logger.Warn("problem marshaling varying data type", "error", err) - return C.int32_t(0) + return C.int64_t(0) } - out, err := toWasmMemorySized(instanceContext, encoded, 5) + out, err := toWasmMemoryOptional(instanceContext, encoded) if err != nil { logger.Warn("failed to allocate", "error", err) return 0 } - return C.int32_t(out) + return C.int64_t(out) } //export ext_allocator_free_version_1 diff --git a/lib/runtime/wasmer/imports_test.go b/lib/runtime/wasmer/imports_test.go index 50531f756a..dca03f17b9 100644 --- a/lib/runtime/wasmer/imports_test.go +++ b/lib/runtime/wasmer/imports_test.go @@ -1200,8 +1200,9 @@ func Test_ext_default_child_storage_storage_kill_version_3(t *testing.T) { key []byte limit *optional.Bytes expected []byte + errMsg string }{ - {key: []byte(`fakekey`), limit: optLimit2, expected: []byte{0, 0, 0, 0, 0}}, + {key: []byte(`fakekey`), limit: optLimit2, expected: []byte{0, 0, 0, 0, 0}, errMsg: "Failed to call the `rtm_ext_default_child_storage_storage_kill_version_3` exported function."}, {key: testChildKey, limit: optLimit2, expected: []byte{1, 2, 0, 0, 0}}, {key: testChildKey, limit: nil, expected: []byte{0, 1, 0, 0, 0}}, } @@ -1212,12 +1213,20 @@ func Test_ext_default_child_storage_storage_kill_version_3(t *testing.T) { encOptLimit, err := test.limit.Encode() require.NoError(t, err) res, err := inst.Exec("rtm_ext_default_child_storage_storage_kill_version_3", append(encChildKey, encOptLimit...)) + if test.errMsg != "" { + require.Error(t, err) + require.EqualError(t, err, test.errMsg) + continue + } + require.NoError(t, err) - ptr := binary.LittleEndian.Uint32(res) - mem := inst.vm.Memory.Data()[ptr : ptr+5] + buf := &bytes.Buffer{} + buf.Write(res) - require.Equal(t, test.expected, mem) + read, err := new(optional.Bytes).Decode(buf) + require.NoError(t, err) + require.Equal(t, test.expected, read.Value()) } } From 0e2dacc14a2d0a45b4fe2ddb835fd89cc3cd0332 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Wed, 13 Oct 2021 15:57:57 -0400 Subject: [PATCH 09/14] remove todos --- lib/runtime/wasmer/exports_test.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/runtime/wasmer/exports_test.go b/lib/runtime/wasmer/exports_test.go index 64b3b739bd..1a3c3eeee8 100644 --- a/lib/runtime/wasmer/exports_test.go +++ b/lib/runtime/wasmer/exports_test.go @@ -63,7 +63,6 @@ func createTestExtrinsic(t *testing.T, rt runtime.Instance, genHash common.Hash, } func TestInstance_Version_NodeRuntime_v098(t *testing.T) { - // todo ed, this fails with new branch, determine why expected := runtime.NewVersionData( []byte("node"), []byte("substrate-node"), @@ -74,12 +73,7 @@ func TestInstance_Version_NodeRuntime_v098(t *testing.T) { 2, ) - instance := NewTestInstance(t, runtime.NODE_RUNTIME_v098) // original - //instance := NewTestInstance(t, runtime.HOST_API_TEST_RUNTIME) - //instance := NewTestInstance(t, runtime.POLKADOT_RUNTIME_v0910 ) - //instance := NewTestInstance(t, runtime.POLKADOT_RUNTIME ) - //instance := NewTestInstance(t, runtime.NODE_RUNTIME ) - //instance := NewTestInstance(t, runtime.DEV_RUNTIME ) + instance := NewTestInstance(t, runtime.NODE_RUNTIME_v098) version, err := instance.Version() require.Nil(t, err) @@ -1054,8 +1048,6 @@ func TestInstance_ExecuteBlock_PolkadotBlock1089328(t *testing.T) { } func TestInstance_DecodeSessionKeys(t *testing.T) { - // todo ed, remove skip when wasm blob works - //t.Skip() keys := "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d34309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc3852042602634309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc3852042602634309a9d2a24213896ff06895db16aade8b6502f3a71cf56374cc38520426026" pubkeys, err := common.HexToBytes(keys) require.NoError(t, err) From 0c887b3222dda4acf1ba5901855ebc4c95815add Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Wed, 13 Oct 2021 16:22:31 -0400 Subject: [PATCH 10/14] lint --- lib/runtime/constants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/runtime/constants.go b/lib/runtime/constants.go index c0cc273434..3ec7ab3a46 100644 --- a/lib/runtime/constants.go +++ b/lib/runtime/constants.go @@ -45,8 +45,8 @@ const ( POLKADOT_RUNTIME_URL = "https://github.com/noot/polkadot/blob/noot/v0.8.25/polkadot_runtime.wasm?raw=true" // v0.8 test API wasm - HOST_API_TEST_RUNTIME = "hostapi_runtime" - HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" + HOST_API_TEST_RUNTIME = "hostapi_runtime" + HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" //HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/master/test/hostapi_runtime.compact.wasm?raw=true" // TODO use above url once below branch has been merged HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/ed/impl_ext_default_child_storage_storage_kill_version_3/test/hostapi_runtime.compact.wasm?raw=true" From 249885560ff0a982cb5f112b22ab8018e7218a46 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Thu, 14 Oct 2021 15:43:11 -0400 Subject: [PATCH 11/14] make vdt's private --- lib/runtime/wasmer/imports.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/runtime/wasmer/imports.go b/lib/runtime/wasmer/imports.go index aeec4cf079..cb06d9c4fb 100644 --- a/lib/runtime/wasmer/imports.go +++ b/lib/runtime/wasmer/imports.go @@ -1147,13 +1147,13 @@ func ext_default_child_storage_storage_kill_version_2(context unsafe.Pointer, ch return 0 } -type NoneRemain uint32 -type SomeRemain uint32 +type noneRemain uint32 +type someRemain uint32 -func (NoneRemain) Index() uint { +func (noneRemain) Index() uint { return 0 } -func (SomeRemain) Index() uint { +func (someRemain) Index() uint { return 1 } @@ -1180,15 +1180,15 @@ func ext_default_child_storage_storage_kill_version_3(context unsafe.Pointer, ch return C.int64_t(0) } - vdt, err := scale.NewVaryingDataType(NoneRemain(0), SomeRemain(0)) + vdt, err := scale.NewVaryingDataType(noneRemain(0), someRemain(0)) if err != nil { logger.Warn("cannot create new varying data type", "error", err) } if all { - err = vdt.Set(NoneRemain(deleted)) + err = vdt.Set(noneRemain(deleted)) } else { - err = vdt.Set(SomeRemain(deleted)) + err = vdt.Set(someRemain(deleted)) } if err != nil { logger.Warn("cannot set varying data type", "error", err) From 51df32610e4d2445055930198ce5ddeb7a78e0a7 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Mon, 18 Oct 2021 15:22:48 -0400 Subject: [PATCH 12/14] update host api url to specific commit --- lib/runtime/constants.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/runtime/constants.go b/lib/runtime/constants.go index 3ec7ab3a46..8c8311266d 100644 --- a/lib/runtime/constants.go +++ b/lib/runtime/constants.go @@ -47,9 +47,7 @@ const ( // v0.8 test API wasm HOST_API_TEST_RUNTIME = "hostapi_runtime" HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" - //HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/master/test/hostapi_runtime.compact.wasm?raw=true" - // TODO use above url once below branch has been merged - HOST_API_TEST_RUNTIME_URL = "https://github.com/noot/polkadot-spec/blob/ed/impl_ext_default_child_storage_storage_kill_version_3/test/hostapi_runtime.compact.wasm?raw=true" + HOST_API_TEST_RUNTIME_URL = "https://github.com/ChainSafe/polkadot-spec/blob/5edcd0122ed55deee20ce07440b90ea51f6b687b/test/hostapi_runtime.compact.wasm?raw=true" // v0.8 substrate runtime with modified name and babe C=(1, 1) DEV_RUNTIME = "dev_runtime" From 630dd4ba428715446df8094eb8de14a22b923cd4 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Mon, 18 Oct 2021 15:38:19 -0400 Subject: [PATCH 13/14] go fmt --- lib/runtime/constants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/runtime/constants.go b/lib/runtime/constants.go index 8c8311266d..6cc08601d9 100644 --- a/lib/runtime/constants.go +++ b/lib/runtime/constants.go @@ -45,8 +45,8 @@ const ( POLKADOT_RUNTIME_URL = "https://github.com/noot/polkadot/blob/noot/v0.8.25/polkadot_runtime.wasm?raw=true" // v0.8 test API wasm - HOST_API_TEST_RUNTIME = "hostapi_runtime" - HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" + HOST_API_TEST_RUNTIME = "hostapi_runtime" + HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" HOST_API_TEST_RUNTIME_URL = "https://github.com/ChainSafe/polkadot-spec/blob/5edcd0122ed55deee20ce07440b90ea51f6b687b/test/hostapi_runtime.compact.wasm?raw=true" // v0.8 substrate runtime with modified name and babe C=(1, 1) From 207a32d3f8fcb5500daae29e5693a4aa52a2ad48 Mon Sep 17 00:00:00 2001 From: Edward Mack Date: Tue, 19 Oct 2021 13:53:01 -0400 Subject: [PATCH 14/14] update host api test runtime url --- lib/runtime/constants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/runtime/constants.go b/lib/runtime/constants.go index 83e7ae3360..fb63ab3917 100644 --- a/lib/runtime/constants.go +++ b/lib/runtime/constants.go @@ -47,7 +47,7 @@ const ( // v0.8 test API wasm HOST_API_TEST_RUNTIME = "hostapi_runtime" HOST_API_TEST_RUNTIME_FP = "hostapi_runtime.compact.wasm" - HOST_API_TEST_RUNTIME_URL = "https://github.com/ChainSafe/polkadot-spec/blob/5edcd0122ed55deee20ce07440b90ea51f6b687b/test/hostapi_runtime.compact.wasm?raw=true" + HOST_API_TEST_RUNTIME_URL = "https://github.com/ChainSafe/polkadot-spec/blob/f9f8c94397d155c4f2edc9c59828dc4ef2c62dd3/test/hostapi_runtime.compact.wasm?raw=true" // v0.8 substrate runtime with modified name and babe C=(1, 1) DEV_RUNTIME = "dev_runtime"