2020-09-08 08:37:58 +00:00
|
|
|
package neofs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
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"
|
2020-10-26 14:46:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-09-08 08:37:58 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseBind(t *testing.T) {
|
|
|
|
var (
|
2021-05-31 18:09:02 +00:00
|
|
|
user = []byte{0x1, 0x2, 0x3}
|
|
|
|
publicKeys = [][]byte{
|
|
|
|
[]byte("key1"),
|
|
|
|
[]byte("key2"),
|
|
|
|
[]byte("key3"),
|
2020-09-08 08:37:58 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
t.Run("wrong number of parameters", func(t *testing.T) {
|
2020-10-26 14:46:15 +00:00
|
|
|
prms := []stackitem.Item{
|
|
|
|
stackitem.NewMap(),
|
2020-09-08 08:37:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 10:06:08 +00:00
|
|
|
_, err := ParseBind(createNotifyEventFromItems(prms))
|
2020-09-08 08:37:58 +00:00
|
|
|
require.EqualError(t, err, event.WrongNumberOfParameters(2, len(prms)).Error())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong first parameter", func(t *testing.T) {
|
2021-10-22 10:06:08 +00:00
|
|
|
_, err := ParseBind(createNotifyEventFromItems([]stackitem.Item{
|
2020-10-26 14:46:15 +00:00
|
|
|
stackitem.NewMap(),
|
2021-10-22 10:06:08 +00:00
|
|
|
}))
|
2020-09-08 08:37:58 +00:00
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong second parameter", func(t *testing.T) {
|
2021-10-22 10:06:08 +00:00
|
|
|
_, err := ParseBind(createNotifyEventFromItems([]stackitem.Item{
|
2021-05-31 18:09:02 +00:00
|
|
|
stackitem.NewByteArray(user),
|
2020-10-26 14:46:15 +00:00
|
|
|
stackitem.NewMap(),
|
2021-10-22 10:06:08 +00:00
|
|
|
}))
|
2020-09-08 08:37:58 +00:00
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("correct", func(t *testing.T) {
|
2021-10-22 10:06:08 +00:00
|
|
|
ev, err := ParseBind(createNotifyEventFromItems([]stackitem.Item{
|
2021-05-31 18:09:02 +00:00
|
|
|
stackitem.NewByteArray(user),
|
2020-10-26 14:46:15 +00:00
|
|
|
stackitem.NewArray([]stackitem.Item{
|
2021-05-31 18:09:02 +00:00
|
|
|
stackitem.NewByteArray(publicKeys[0]),
|
|
|
|
stackitem.NewByteArray(publicKeys[1]),
|
|
|
|
stackitem.NewByteArray(publicKeys[2]),
|
2020-10-26 14:46:15 +00:00
|
|
|
}),
|
2021-10-22 10:06:08 +00:00
|
|
|
}))
|
2020-09-08 08:37:58 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-05-31 18:09:02 +00:00
|
|
|
e := ev.(Bind)
|
2020-09-08 08:37:58 +00:00
|
|
|
|
2021-05-31 18:09:02 +00:00
|
|
|
require.Equal(t, user, e.User())
|
|
|
|
require.Equal(t, publicKeys, e.Keys())
|
2020-09-08 08:37:58 +00:00
|
|
|
})
|
|
|
|
}
|
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),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|