Skip to content

Commit

Permalink
manifest: add compatibility test for Permissions and Trust serialization
Browse files Browse the repository at this point in the history
We already have tests for Permission deserialisation, so port the first
part of neo-project/neo#2948.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
  • Loading branch information
AnnaShaleva committed Nov 18, 2023
1 parent dd48f81 commit fdcc369
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/smartcontract/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit fdcc369

Please sign in to comment.