forked from TrueCloudLab/frostfs-node
[#296] morph: Add parser unit tests
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
1309622b20
commit
ea10abb42a
1 changed files with 48 additions and 0 deletions
48
pkg/morph/event/utils_test.go
Normal file
48
pkg/morph/event/utils_test.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
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")
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue