frostfs-node/pkg/morph/event/rolemanagement/designate_test.go
Pavel Karpy c167ae26f9 [] morph/event: Change notification parser's signature
Parsers should have original notification
structure to be able to construct internal
event structure that contains necessary
for unique nonce calculation information.
So notification parsers take raw notification
structure instead of slice of stack items.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2021-11-19 09:58:03 +03:00

37 lines
1.2 KiB
Go

package rolemanagement
import (
"testing"
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/stretchr/testify/require"
)
func TestParseRoleUpdate(t *testing.T) {
t.Run("wrong number of arguments", func(t *testing.T) {
_, err := ParseDesignate(createNotifyEventFromItems([]stackitem.Item{}))
require.Error(t, err)
})
t.Run("invalid item type", func(t *testing.T) {
args := []stackitem.Item{stackitem.NewMap(), stackitem.Make(123)}
_, err := ParseDesignate(createNotifyEventFromItems(args))
require.Error(t, err)
})
t.Run("good", func(t *testing.T) {
args := []stackitem.Item{stackitem.Make(int(noderoles.NeoFSAlphabet)), stackitem.Make(123)}
e, err := ParseDesignate(createNotifyEventFromItems(args))
require.NoError(t, err)
require.Equal(t, noderoles.NeoFSAlphabet, e.(Designate).Role)
})
}
func createNotifyEventFromItems(items []stackitem.Item) *subscriptions.NotificationEvent {
return &subscriptions.NotificationEvent{
NotificationEvent: state.NotificationEvent{
Item: stackitem.NewArray(items),
},
}
}