core: temp manifest.Extra marshalling fix
Manifest.Extra still serialized as JSON message with undefined order of items, so it affects contract states dumps.
This commit is contained in:
parent
5e9d05b9af
commit
0f1473897b
4 changed files with 10 additions and 22 deletions
|
@ -1,6 +1,7 @@
|
||||||
package compiler
|
package compiler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
||||||
|
@ -265,7 +266,7 @@ func _deploy(data interface{}, isUpdate bool) {}
|
||||||
Trusts: manifest.WildUint160s{
|
Trusts: manifest.WildUint160s{
|
||||||
Value: []util.Uint160{},
|
Value: []util.Uint160{},
|
||||||
},
|
},
|
||||||
Extra: nil,
|
Extra: json.RawMessage("null"),
|
||||||
}
|
}
|
||||||
require.ElementsMatch(t, expected.ABI.Methods, actual.ABI.Methods)
|
require.ElementsMatch(t, expected.ABI.Methods, actual.ABI.Methods)
|
||||||
require.Equal(t, expected.ABI.Events, actual.ABI.Events)
|
require.Equal(t, expected.ABI.Events, actual.ABI.Events)
|
||||||
|
|
|
@ -481,7 +481,7 @@ func TestContractUpdate(t *testing.T) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
cs1.Manifest.Extra = "update me"
|
cs1.Manifest.Extra = []byte(`"update me"`)
|
||||||
manif1, err = json.Marshal(cs1.Manifest)
|
manif1, err = json.Marshal(cs1.Manifest)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cs1.UpdateCounter++
|
cs1.UpdateCounter++
|
||||||
|
@ -504,7 +504,7 @@ func TestContractUpdate(t *testing.T) {
|
||||||
cs1.NEF.Checksum = cs1.NEF.CalculateChecksum()
|
cs1.NEF.Checksum = cs1.NEF.CalculateChecksum()
|
||||||
nef1b, err = cs1.NEF.Bytes()
|
nef1b, err = cs1.NEF.Bytes()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cs1.Manifest.Extra = "update me once more"
|
cs1.Manifest.Extra = []byte(`"update me once more"`)
|
||||||
manif1, err = json.Marshal(cs1.Manifest)
|
manif1, err = json.Marshal(cs1.Manifest)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
cs1.UpdateCounter++
|
cs1.UpdateCounter++
|
||||||
|
|
|
@ -34,7 +34,7 @@ type Manifest struct {
|
||||||
// Trusts is a set of hashes to a which contract trusts.
|
// Trusts is a set of hashes to a which contract trusts.
|
||||||
Trusts WildUint160s `json:"trusts"`
|
Trusts WildUint160s `json:"trusts"`
|
||||||
// Extra is an implementation-defined user data.
|
// Extra is an implementation-defined user data.
|
||||||
Extra interface{} `json:"extra"`
|
Extra json.RawMessage `json:"extra"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewManifest returns new manifest with necessary fields initialized.
|
// NewManifest returns new manifest with necessary fields initialized.
|
||||||
|
@ -48,6 +48,7 @@ func NewManifest(name string) *Manifest {
|
||||||
Groups: []Group{},
|
Groups: []Group{},
|
||||||
Permissions: []Permission{},
|
Permissions: []Permission{},
|
||||||
SupportedStandards: []string{},
|
SupportedStandards: []string{},
|
||||||
|
Extra: json.RawMessage("null"),
|
||||||
}
|
}
|
||||||
m.Trusts.Restrict()
|
m.Trusts.Restrict()
|
||||||
return m
|
return m
|
||||||
|
@ -143,11 +144,7 @@ func (m *Manifest) ToStackItem() (stackitem.Item, error) {
|
||||||
}
|
}
|
||||||
extra := stackitem.Make("null")
|
extra := stackitem.Make("null")
|
||||||
if m.Extra != nil {
|
if m.Extra != nil {
|
||||||
e, err := json.Marshal(m.Extra)
|
extra = stackitem.NewByteArray(m.Extra)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
extra = stackitem.NewByteArray(e)
|
|
||||||
}
|
}
|
||||||
return stackitem.NewStruct([]stackitem.Item{
|
return stackitem.NewStruct([]stackitem.Item{
|
||||||
stackitem.Make(m.Name),
|
stackitem.Make(m.Name),
|
||||||
|
@ -238,8 +235,6 @@ func (m *Manifest) FromStackItem(item stackitem.Item) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if string(extra) == "null" {
|
m.Extra = extra
|
||||||
return nil
|
return nil
|
||||||
}
|
|
||||||
return json.Unmarshal(extra, &m.Extra)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,7 +278,7 @@ func TestManifestToStackItem(t *testing.T) {
|
||||||
Trusts: WildUint160s{
|
Trusts: WildUint160s{
|
||||||
Value: []util.Uint160{{1, 2, 3}},
|
Value: []util.Uint160{{1, 2, 3}},
|
||||||
},
|
},
|
||||||
Extra: "some extra data",
|
Extra: []byte(`even not a json allowed`),
|
||||||
}
|
}
|
||||||
check(t, expected)
|
check(t, expected)
|
||||||
})
|
})
|
||||||
|
@ -335,14 +335,6 @@ func TestManifest_FromStackItemErrors(t *testing.T) {
|
||||||
stackitem.NewArray([]stackitem.Item{}),
|
stackitem.NewArray([]stackitem.Item{}),
|
||||||
stackitem.NewArray([]stackitem.Item{}),
|
stackitem.NewArray([]stackitem.Item{}),
|
||||||
stackitem.Null{}}),
|
stackitem.Null{}}),
|
||||||
"invalid extra": stackitem.NewStruct([]stackitem.Item{
|
|
||||||
stackitem.NewByteArray([]byte{}),
|
|
||||||
stackitem.NewArray([]stackitem.Item{}),
|
|
||||||
stackitem.NewArray([]stackitem.Item{}),
|
|
||||||
stackitem.NewStruct([]stackitem.Item{stackitem.NewArray([]stackitem.Item{}), stackitem.NewArray([]stackitem.Item{})}),
|
|
||||||
stackitem.NewArray([]stackitem.Item{}),
|
|
||||||
stackitem.NewArray([]stackitem.Item{}),
|
|
||||||
stackitem.NewByteArray([]byte("not a json"))}),
|
|
||||||
}
|
}
|
||||||
for name, errCase := range errCases {
|
for name, errCase := range errCases {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue