frostfs-node/pkg/morph/event/utils_test.go
Dmitrii Stepanov ea10abb42a [] morph: Add parser unit tests
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-05-10 09:40:26 +03:00

48 lines
1.4 KiB
Go

package event
import (
"math/big"
"testing"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/stretchr/testify/require"
)
func TestParseStackArray(t *testing.T) {
t.Run("success", func(t *testing.T) {
arr := &stackitem.Array{}
arr.Append(stackitem.NewBigInteger(big.NewInt(1)))
arr.Append(stackitem.NewBigInteger(big.NewInt(2)))
ev := &state.ContainedNotificationEvent{
Container: util.Uint256{67},
NotificationEvent: state.NotificationEvent{
ScriptHash: util.Uint160{69},
Name: "name",
Item: arr,
},
}
items, err := ParseStackArray(ev)
require.NoError(t, err, "failed to parse event items")
require.Equal(t, 2, len(items), "invalid length")
require.Equal(t, stackitem.NewBigInteger(big.NewInt(1)), items[0], "invalid item 0")
require.Equal(t, stackitem.NewBigInteger(big.NewInt(2)), items[1], "invalid item 0")
})
t.Run("empty stack error", func(t *testing.T) {
arr := &stackitem.Array{}
ev := &state.ContainedNotificationEvent{
Container: util.Uint256{67},
NotificationEvent: state.NotificationEvent{
ScriptHash: util.Uint160{69},
Name: "name",
Item: arr,
},
}
items, err := ParseStackArray(ev)
require.ErrorIs(t, err, errEmptyStackArray, "invalid empty array error")
require.Equal(t, 0, len(items), "items was returned")
})
}