forked from TrueCloudLab/neoneo-go
core: avoid nil
values during natives manifest marshalling
This commit is contained in:
parent
cba259dc47
commit
61fd7bd6ba
3 changed files with 12 additions and 0 deletions
|
@ -140,6 +140,7 @@ func NewContractMD(name string, id int32) *ContractMD {
|
||||||
// Therefore values are taken from C# node.
|
// Therefore values are taken from C# node.
|
||||||
c.NEF.Header.Compiler = "neo-core-v3.0"
|
c.NEF.Header.Compiler = "neo-core-v3.0"
|
||||||
c.NEF.Header.Magic = nef.Magic
|
c.NEF.Header.Magic = nef.Magic
|
||||||
|
c.NEF.Tokens = []nef.MethodToken{} // avoid `nil` result during JSON marshalling
|
||||||
c.Hash = state.CreateContractHash(util.Uint160{}, 0, c.Name)
|
c.Hash = state.CreateContractHash(util.Uint160{}, 0, c.Name)
|
||||||
c.Manifest = *manifest.DefaultManifest(name)
|
c.Manifest = *manifest.DefaultManifest(name)
|
||||||
|
|
||||||
|
|
|
@ -294,6 +294,9 @@ func (c *nep17TokenNative) addTokens(ic *interop.Context, h util.Uint160, amount
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDescriptor(name string, ret smartcontract.ParamType, ps ...manifest.Parameter) *manifest.Method {
|
func newDescriptor(name string, ret smartcontract.ParamType, ps ...manifest.Parameter) *manifest.Method {
|
||||||
|
if len(ps) == 0 {
|
||||||
|
ps = []manifest.Parameter{}
|
||||||
|
}
|
||||||
return &manifest.Method{
|
return &manifest.Method{
|
||||||
Name: name,
|
Name: name,
|
||||||
Parameters: ps,
|
Parameters: ps,
|
||||||
|
|
|
@ -69,6 +69,14 @@ func TestEncodeDecodeBinary(t *testing.T) {
|
||||||
expected.Header.Magic = Magic
|
expected.Header.Magic = Magic
|
||||||
testserdes.EncodeDecodeBinary(t, expected, &File{})
|
testserdes.EncodeDecodeBinary(t, expected, &File{})
|
||||||
})
|
})
|
||||||
|
t.Run("positive with empty tokens", func(t *testing.T) {
|
||||||
|
expected.Script = script
|
||||||
|
// Check `Tokens` won't be deserialized to `nil`. We expect them to be non-nil slice in the related code.
|
||||||
|
expected.Tokens = []MethodToken{}
|
||||||
|
expected.Checksum = expected.CalculateChecksum()
|
||||||
|
expected.Header.Magic = Magic
|
||||||
|
testserdes.EncodeDecodeBinary(t, expected, &File{})
|
||||||
|
})
|
||||||
t.Run("invalid reserved bytes", func(t *testing.T) {
|
t.Run("invalid reserved bytes", func(t *testing.T) {
|
||||||
expected.Script = script
|
expected.Script = script
|
||||||
expected.Tokens = expected.Tokens[:0]
|
expected.Tokens = expected.Tokens[:0]
|
||||||
|
|
Loading…
Reference in a new issue