2020-06-15 18:13:32 +00:00
|
|
|
package native
|
|
|
|
|
|
|
|
import (
|
2020-06-23 13:11:49 +00:00
|
|
|
"encoding/json"
|
2020-06-15 18:13:32 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
2020-06-23 13:11:49 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
2020-06-15 18:13:32 +00:00
|
|
|
"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)
|
|
|
|
}
|
2020-06-23 13:11:49 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|