Merge pull request #3140 from nspcc-dev/fix-wildcard-trusts-deserialization

smartcontract: fix wildcard trusts deserialization
This commit is contained in:
Roman Khimov 2023-09-25 12:01:20 +03:00 committed by GitHub
commit 3628b824e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -55,6 +55,16 @@ func TestContractStateToFromSI(t *testing.T) {
t.Run("Convertible", func(t *testing.T) { t.Run("Convertible", func(t *testing.T) {
contractDecoded := new(Contract) contractDecoded := new(Contract)
testserdes.ToFromStackItem(t, contract, contractDecoded) testserdes.ToFromStackItem(t, contract, contractDecoded)
t.Run("preserve wildcard trusts", func(t *testing.T) {
contract.Manifest.Trusts.Value = nil
require.True(t, contract.Manifest.Trusts.IsWildcard())
actual := new(Contract)
item, err := contract.ToStackItem()
require.NoError(t, err)
require.NoError(t, actual.FromStackItem(item))
require.True(t, actual.Manifest.Trusts.IsWildcard())
})
}) })
t.Run("JSON", func(t *testing.T) { t.Run("JSON", func(t *testing.T) {
contractDecoded := new(Contract) contractDecoded := new(Contract)

View file

@ -250,7 +250,7 @@ func (m *Manifest) FromStackItem(item stackitem.Item) error {
m.Permissions[i] = *p m.Permissions[i] = *p
} }
if _, ok := str[6].(stackitem.Null); ok { if _, ok := str[6].(stackitem.Null); ok {
m.Trusts.Restrict() m.Trusts = WildPermissionDescs{Value: nil} // wildcard by default
} else { } else {
if str[6].Type() != stackitem.ArrayT { if str[6].Type() != stackitem.ArrayT {
return errors.New("invalid Trusts stackitem type") return errors.New("invalid Trusts stackitem type")