2021-07-17 12:54:52 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncodeDecodeDeposit(t *testing.T) {
|
|
|
|
d := &Deposit{Amount: big.NewInt(100500), Till: 888}
|
|
|
|
depo := new(Deposit)
|
2021-07-17 15:37:33 +00:00
|
|
|
testserdes.ToFromStackItem(t, d, depo)
|
2021-07-17 12:54:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDepositFromStackItem(t *testing.T) {
|
|
|
|
var d Deposit
|
|
|
|
|
|
|
|
item := stackitem.Make(42)
|
2021-07-17 15:37:33 +00:00
|
|
|
require.Error(t, d.FromStackItem(item))
|
2021-07-17 12:54:52 +00:00
|
|
|
|
|
|
|
item = stackitem.NewStruct(nil)
|
2021-07-17 15:37:33 +00:00
|
|
|
require.Error(t, d.FromStackItem(item))
|
2021-07-17 12:54:52 +00:00
|
|
|
|
|
|
|
item = stackitem.NewStruct([]stackitem.Item{
|
|
|
|
stackitem.NewStruct(nil),
|
|
|
|
stackitem.NewStruct(nil),
|
|
|
|
})
|
2021-07-17 15:37:33 +00:00
|
|
|
require.Error(t, d.FromStackItem(item))
|
2021-07-17 12:54:52 +00:00
|
|
|
|
|
|
|
item = stackitem.NewStruct([]stackitem.Item{
|
|
|
|
stackitem.Make(777),
|
|
|
|
stackitem.NewStruct(nil),
|
|
|
|
})
|
2021-07-17 15:37:33 +00:00
|
|
|
require.Error(t, d.FromStackItem(item))
|
2021-07-17 12:54:52 +00:00
|
|
|
|
|
|
|
item = stackitem.NewStruct([]stackitem.Item{
|
|
|
|
stackitem.Make(777),
|
|
|
|
stackitem.Make(-1),
|
|
|
|
})
|
2021-07-17 15:37:33 +00:00
|
|
|
require.Error(t, d.FromStackItem(item))
|
2021-07-17 12:54:52 +00:00
|
|
|
item = stackitem.NewStruct([]stackitem.Item{
|
|
|
|
stackitem.Make(777),
|
|
|
|
stackitem.Make("somenonu64value"),
|
|
|
|
})
|
2021-07-17 15:37:33 +00:00
|
|
|
require.Error(t, d.FromStackItem(item))
|
2021-07-17 12:54:52 +00:00
|
|
|
item = stackitem.NewStruct([]stackitem.Item{
|
|
|
|
stackitem.Make(777),
|
|
|
|
stackitem.Make(888),
|
|
|
|
})
|
2021-07-17 15:37:33 +00:00
|
|
|
require.NoError(t, d.FromStackItem(item))
|
2021-07-17 12:54:52 +00:00
|
|
|
}
|