From fdcc369d605111806834498d000880b3485a65d1 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 8 Nov 2023 16:08:24 +0300 Subject: [PATCH] manifest: add compatibility test for Permissions and Trust serialization We already have tests for Permission deserialisation, so port the first part of https://github.com/neo-project/neo/pull/2948. Signed-off-by: Anna Shaleva --- pkg/smartcontract/manifest/manifest_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/smartcontract/manifest/manifest_test.go b/pkg/smartcontract/manifest/manifest_test.go index 82fcc13b4..2b9b20bae 100644 --- a/pkg/smartcontract/manifest/manifest_test.go +++ b/pkg/smartcontract/manifest/manifest_test.go @@ -305,6 +305,25 @@ func TestManifestToStackItem(t *testing.T) { } check(t, expected) }) + + t.Run("compat", func(t *testing.T) { + // Compatibility test with NeoC#, see https://github.com/neo-project/neo/pull/2948. + var mJSON = `{"name":"CallOracleContract-6","groups":[],"features":{},"supportedstandards":[],"abi":{"methods":[{"name":"request","parameters":[{"name":"url","type":"String"},{"name":"filter","type":"String"},{"name":"gasForResponse","type":"Integer"}],"returntype":"Void","offset":0,"safe":false},{"name":"callback","parameters":[{"name":"url","type":"String"},{"name":"userData","type":"Any"},{"name":"responseCode","type":"Integer"},{"name":"response","type":"ByteArray"}],"returntype":"Void","offset":86,"safe":false},{"name":"getStoredUrl","parameters":[],"returntype":"String","offset":129,"safe":false},{"name":"getStoredResponseCode","parameters":[],"returntype":"Integer","offset":142,"safe":false},{"name":"getStoredResponse","parameters":[],"returntype":"ByteArray","offset":165,"safe":false}],"events":[]},"permissions":[{"contract":"0xfe924b7cfe89ddd271abaf7210a80a7e11178758","methods":"*"},{"contract":"*","methods":"*"}],"trusts":["0xfe924b7cfe89ddd271abaf7210a80a7e11178758","*"],"extra":{}}` + c := NewManifest("Test") + require.NoError(t, json.Unmarshal([]byte(mJSON), c)) + + si, err := c.ToStackItem() + require.NoError(t, err) + actual := new(Manifest) + require.NoError(t, actual.FromStackItem(si)) + require.NotEqual(t, actual.Permissions[0].Contract.Type, PermissionWildcard) + require.True(t, actual.Permissions[0].Methods.IsWildcard()) + require.Equal(t, actual.Permissions[1].Contract.Type, PermissionWildcard) + require.True(t, actual.Permissions[1].Methods.IsWildcard()) + + require.NotEqual(t, actual.Trusts.Value[0].Type, PermissionWildcard) + require.Equal(t, actual.Trusts.Value[1].Type, PermissionWildcard) + }) } func TestManifest_FromStackItemErrors(t *testing.T) {