Skip to content

Commit

Permalink
feat: implement ValidateDynamicLinkInterface to vm
Browse files Browse the repository at this point in the history
  • Loading branch information
loloicci committed Mar 28, 2023
1 parent e954498 commit c534569
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,16 @@ func (vm *VM) CallCallablePoint(
return data, events, attributes, gasUsed, nil
}

// returns: result, systemerr
//
// result: serialized Option<String> 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
}
Expand Down
21 changes: 21 additions & 0 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}

0 comments on commit c534569

Please sign in to comment.