2021-05-18 07:40:21 +00:00
|
|
|
package rolemanagement
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
2021-10-22 10:06:08 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
|
2021-05-18 07:40:21 +00:00
|
|
|
"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) {
|
2021-10-22 10:06:08 +00:00
|
|
|
_, err := ParseDesignate(createNotifyEventFromItems([]stackitem.Item{}))
|
2021-05-18 07:40:21 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
t.Run("invalid item type", func(t *testing.T) {
|
|
|
|
args := []stackitem.Item{stackitem.NewMap(), stackitem.Make(123)}
|
2021-10-22 10:06:08 +00:00
|
|
|
_, err := ParseDesignate(createNotifyEventFromItems(args))
|
2021-05-18 07:40:21 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
t.Run("good", func(t *testing.T) {
|
|
|
|
args := []stackitem.Item{stackitem.Make(int(noderoles.NeoFSAlphabet)), stackitem.Make(123)}
|
2021-10-22 10:06:08 +00:00
|
|
|
e, err := ParseDesignate(createNotifyEventFromItems(args))
|
2021-05-18 07:40:21 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, noderoles.NeoFSAlphabet, e.(Designate).Role)
|
|
|
|
})
|
|
|
|
}
|
2021-10-22 10:06:08 +00:00
|
|
|
|
|
|
|
func createNotifyEventFromItems(items []stackitem.Item) *subscriptions.NotificationEvent {
|
|
|
|
return &subscriptions.NotificationEvent{
|
|
|
|
NotificationEvent: state.NotificationEvent{
|
|
|
|
Item: stackitem.NewArray(items),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|