2022-12-23 17:35:35 +00:00
|
|
|
package frostfs
|
2020-09-08 08:37:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/morph/event"
|
2021-10-22 10:06:08 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
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/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
|
|
|
|
2022-07-28 16:22:32 +00:00
|
|
|
func createNotifyEventFromItems(items []stackitem.Item) *state.ContainedNotificationEvent {
|
|
|
|
return &state.ContainedNotificationEvent{
|
2021-10-22 10:06:08 +00:00
|
|
|
NotificationEvent: state.NotificationEvent{
|
|
|
|
Item: stackitem.NewArray(items),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|