From c534569970c7bc3ef397c39387e7873e7e519501 Mon Sep 17 00:00:00 2001 From: loloicci Date: Wed, 22 Mar 2023 16:19:03 +0900 Subject: [PATCH] feat: implement ValidateDynamicLinkInterface to vm --- lib.go | 10 ++++++++++ lib_test.go | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib.go b/lib.go index 55de51ea..3167de79 100644 --- a/lib.go +++ b/lib.go @@ -808,6 +808,16 @@ func (vm *VM) CallCallablePoint( return data, events, attributes, gasUsed, nil } +// returns: result, systemerr +// +// result: serialized Option which None means true, Some(e) means false and the reason is e. +func (vm *VM) ValidateDynamicLinkInterface( + checksum Checksum, + expectedInterface []byte, +) ([]byte, error) { + return api.ValidateDynamicLinkInterface(vm.cache, checksum, expectedInterface) +} + func (vm *VM) GetCache() *Cache { return &vm.cache } diff --git a/lib_test.go b/lib_test.go index 95f43fba..e7be4fee 100644 --- a/lib_test.go +++ b/lib_test.go @@ -379,3 +379,24 @@ func TestCallCallablePoint(t *testing.T) { require.Equal(t, 0, len(events)) require.Equal(t, attrsIn, attributes) } + +func TestValidateDynamicLinkInterafce(t *testing.T) { + vm := withVM(t) + + // Create contract + checksum := createTestContract(t, vm, EVENTS_TEST_CONTRACT) + + correctInterface := []byte(`[{"name":"add_event_dyn","ty":{"params":["I32","I32","I32"],"results":[]}},{"name":"add_events_dyn","ty":{"params":["I32","I32"],"results":[]}},{"name":"add_attribute_dyn","ty":{"params":["I32","I32","I32"],"results":[]}},{"name":"add_attributes_dyn","ty":{"params":["I32","I32"],"results":[]}}]`) + res, err := vm.ValidateDynamicLinkInterface(checksum, correctInterface) + require.NoError(t, err) + require.Equal(t, []byte(`null`), res) + + wrongInterface := []byte(`[{"name":"add_event","ty":{"params":["I32","I32","I32"],"results":[]}},{"name":"add_events","ty":{"params":["I32","I32"],"results":[]}},{"name":"add_attribute","ty":{"params":["I32","I32","I32"],"results":[]}},{"name":"add_attributes","ty":{"params":["I32","I32"],"results":[]}}]`) + res, err = vm.ValidateDynamicLinkInterface(checksum, wrongInterface) + require.NoError(t, err) + require.Contains(t, string(res), `following functions are not implemented`) + require.Contains(t, string(res), `add_event`) + require.Contains(t, string(res), `add_events`) + require.Contains(t, string(res), `add_attribute`) + require.Contains(t, string(res), `add_attributes`) +}