2020-09-08 08:38:23 +00:00
|
|
|
package neofs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-10-26 14:46:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-09-08 08:38:23 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseUnbind(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:38:23 +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:38:23 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 10:06:08 +00:00
|
|
|
_, err := ParseUnbind(createNotifyEventFromItems(prms))
|
2020-09-08 08:38:23 +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 := ParseUnbind(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:38:23 +00:00
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong second parameter", func(t *testing.T) {
|
2021-10-22 10:06:08 +00:00
|
|
|
_, err := ParseUnbind(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:38:23 +00:00
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("correct", func(t *testing.T) {
|
2021-10-22 10:06:08 +00:00
|
|
|
ev, err := ParseUnbind(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:38:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-05-31 18:09:02 +00:00
|
|
|
e := ev.(Unbind)
|
2020-09-08 08:38:23 +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:38:23 +00:00
|
|
|
})
|
|
|
|
}
|