mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-30 15:01:35 +00:00
9097a1a23d
MarshalJSON should be defined on structure (not pointer), as we use structures to marshal parameters (e.g. in NotificationEvent and Invoke of RPC result package) and never use pointers for that purpose. Also added marshalling of nil array into `[]` instead of `null` to follow C# implementation.
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package native
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestEncodeDecodeBinary(t *testing.T) {
|
|
expected := &BlockedAccounts{
|
|
util.Uint160{1, 2, 3},
|
|
util.Uint160{4, 5, 6},
|
|
}
|
|
actual := new(BlockedAccounts)
|
|
testserdes.EncodeDecodeBinary(t, expected, actual)
|
|
|
|
expected = &BlockedAccounts{}
|
|
actual = new(BlockedAccounts)
|
|
testserdes.EncodeDecodeBinary(t, expected, actual)
|
|
}
|
|
|
|
func TestBytesFromBytes(t *testing.T) {
|
|
expected := BlockedAccounts{
|
|
util.Uint160{1, 2, 3},
|
|
util.Uint160{4, 5, 6},
|
|
}
|
|
actual, err := BlockedAccountsFromBytes(expected.Bytes())
|
|
require.NoError(t, err)
|
|
require.Equal(t, expected, actual)
|
|
|
|
expected = BlockedAccounts{}
|
|
actual, err = BlockedAccountsFromBytes(expected.Bytes())
|
|
require.NoError(t, err)
|
|
require.Equal(t, expected, actual)
|
|
}
|
|
|
|
func TestToStackItem(t *testing.T) {
|
|
u1 := util.Uint160{1, 2, 3}
|
|
u2 := util.Uint160{4, 5, 6}
|
|
expected := BlockedAccounts{u1, u2}
|
|
actual := stackitem.NewArray([]stackitem.Item{
|
|
stackitem.NewByteArray(u1.BytesLE()),
|
|
stackitem.NewByteArray(u2.BytesLE()),
|
|
})
|
|
require.Equal(t, expected.ToStackItem(), actual)
|
|
|
|
expected = BlockedAccounts{}
|
|
actual = stackitem.NewArray([]stackitem.Item{})
|
|
require.Equal(t, expected.ToStackItem(), actual)
|
|
}
|
|
|
|
func TestMarshallJSON(t *testing.T) {
|
|
ba := &BlockedAccounts{}
|
|
p := smartcontract.ParameterFromStackItem(ba.ToStackItem(), make(map[stackitem.Item]bool))
|
|
actual, err := json.Marshal(p)
|
|
require.NoError(t, err)
|
|
expected := `{"type":"Array","value":[]}`
|
|
require.Equal(t, expected, string(actual))
|
|
}
|