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
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
||||
|
@ -265,7 +266,7 @@ func _deploy(data interface{}, isUpdate bool) {}
|
|||
Trusts: manifest.WildUint160s{
|
||||
Value: []util.Uint160{},
|
||||
},
|
||||
Extra: nil,
|
||||
Extra: json.RawMessage("null"),
|
||||
}
|
||||
require.ElementsMatch(t, expected.ABI.Methods, actual.ABI.Methods)
|
||||
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)
|
||||
require.NoError(t, err)
|
||||
cs1.UpdateCounter++
|
||||
|
@ -504,7 +504,7 @@ func TestContractUpdate(t *testing.T) {
|
|||
cs1.NEF.Checksum = cs1.NEF.CalculateChecksum()
|
||||
nef1b, err = cs1.NEF.Bytes()
|
||||
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)
|
||||
require.NoError(t, err)
|
||||
cs1.UpdateCounter++
|
||||
|
|
|
@ -34,7 +34,7 @@ type Manifest struct {
|
|||
// Trusts is a set of hashes to a which contract trusts.
|
||||
Trusts WildUint160s `json:"trusts"`
|
||||
// Extra is an implementation-defined user data.
|
||||
Extra interface{} `json:"extra"`
|
||||
Extra json.RawMessage `json:"extra"`
|
||||
}
|
||||
|
||||
// NewManifest returns new manifest with necessary fields initialized.
|
||||
|
@ -48,6 +48,7 @@ func NewManifest(name string) *Manifest {
|
|||
Groups: []Group{},
|
||||
Permissions: []Permission{},
|
||||
SupportedStandards: []string{},
|
||||
Extra: json.RawMessage("null"),
|
||||
}
|
||||
m.Trusts.Restrict()
|
||||
return m
|
||||
|
@ -143,11 +144,7 @@ func (m *Manifest) ToStackItem() (stackitem.Item, error) {
|
|||
}
|
||||
extra := stackitem.Make("null")
|
||||
if m.Extra != nil {
|
||||
e, err := json.Marshal(m.Extra)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
extra = stackitem.NewByteArray(e)
|
||||
extra = stackitem.NewByteArray(m.Extra)
|
||||
}
|
||||
return stackitem.NewStruct([]stackitem.Item{
|
||||
stackitem.Make(m.Name),
|
||||
|
@ -238,8 +235,6 @@ func (m *Manifest) FromStackItem(item stackitem.Item) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if string(extra) == "null" {
|
||||
m.Extra = extra
|
||||
return nil
|
||||
}
|
||||
return json.Unmarshal(extra, &m.Extra)
|
||||
}
|
||||
|
|
|
@ -278,7 +278,7 @@ func TestManifestToStackItem(t *testing.T) {
|
|||
Trusts: WildUint160s{
|
||||
Value: []util.Uint160{{1, 2, 3}},
|
||||
},
|
||||
Extra: "some extra data",
|
||||
Extra: []byte(`even not a json allowed`),
|
||||
}
|
||||
check(t, expected)
|
||||
})
|
||||
|
@ -335,14 +335,6 @@ func TestManifest_FromStackItemErrors(t *testing.T) {
|
|||
stackitem.NewArray([]stackitem.Item{}),
|
||||
stackitem.NewArray([]stackitem.Item{}),
|
||||
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 {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue