2021-11-26 12:19:20 +00:00
|
|
|
package subnetevents_test
|
2021-11-25 19:12:31 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2021-11-26 12:19:20 +00:00
|
|
|
. "github.com/nspcc-dev/neofs-node/pkg/morph/event/subnet"
|
2021-11-25 19:12:31 +00:00
|
|
|
subnetid "github.com/nspcc-dev/neofs-sdk-go/subnet/id"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseRemoveNode(t *testing.T) {
|
|
|
|
t.Run("wrong number of arguments", func(t *testing.T) {
|
|
|
|
_, err := ParseRemoveNode(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 := ParseRemoveNode(createNotifyEventFromItems(args))
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
subnetID := subnetid.ID{}
|
2022-06-15 08:08:10 +00:00
|
|
|
subnetID.SetNumeric(123)
|
2021-11-25 19:12:31 +00:00
|
|
|
|
2022-06-15 08:08:10 +00:00
|
|
|
rawSubnetID := subnetID.Marshal()
|
2021-11-25 19:12:31 +00:00
|
|
|
|
|
|
|
priv, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pub := priv.PublicKey()
|
|
|
|
|
|
|
|
t.Run("good", func(t *testing.T) {
|
|
|
|
args := []stackitem.Item{stackitem.NewByteArray(rawSubnetID), stackitem.Make(pub.Bytes())}
|
|
|
|
|
|
|
|
e, err := ParseRemoveNode(createNotifyEventFromItems(args))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
gotRaw := e.(RemoveNode).SubnetworkID()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, rawSubnetID, gotRaw)
|
|
|
|
require.Equal(t, pub.Bytes(), e.(RemoveNode).Node())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-07-28 16:22:32 +00:00
|
|
|
func createNotifyEventFromItems(items []stackitem.Item) *state.ContainedNotificationEvent {
|
|
|
|
return &state.ContainedNotificationEvent{
|
2021-11-25 19:12:31 +00:00
|
|
|
NotificationEvent: state.NotificationEvent{
|
|
|
|
Item: stackitem.NewArray(items),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|