2020-08-11 11:46:31 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-10-26 14:46:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-08-11 11:46:31 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParsePut(t *testing.T) {
|
|
|
|
var (
|
|
|
|
containerData = []byte("containerData")
|
|
|
|
signature = []byte("signature")
|
2021-05-19 14:16:48 +00:00
|
|
|
publicKey = []byte("pubkey")
|
2021-05-25 15:52:55 +00:00
|
|
|
token = []byte("token")
|
2020-08-11 11:46:31 +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(),
|
|
|
|
stackitem.NewMap(),
|
2020-08-11 11:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err := ParsePut(prms)
|
2021-05-25 09:15:24 +00:00
|
|
|
require.EqualError(t, err, event.WrongNumberOfParameters(expectedItemNumPut, len(prms)).Error())
|
2020-08-11 11:46:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong container parameter", func(t *testing.T) {
|
2020-10-26 14:46:15 +00:00
|
|
|
_, err := ParsePut([]stackitem.Item{
|
|
|
|
stackitem.NewMap(),
|
2020-08-11 11:46:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong signature parameter", func(t *testing.T) {
|
2020-10-26 14:46:15 +00:00
|
|
|
_, err := ParsePut([]stackitem.Item{
|
|
|
|
stackitem.NewByteArray(containerData),
|
|
|
|
stackitem.NewMap(),
|
2020-08-11 11:46:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong key parameter", func(t *testing.T) {
|
2020-10-26 14:46:15 +00:00
|
|
|
_, err := ParsePut([]stackitem.Item{
|
|
|
|
stackitem.NewByteArray(containerData),
|
|
|
|
stackitem.NewByteArray(signature),
|
|
|
|
stackitem.NewMap(),
|
2020-08-11 11:46:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
2021-05-25 15:52:55 +00:00
|
|
|
t.Run("wrong session token parameter", func(t *testing.T) {
|
|
|
|
_, err := ParsePut([]stackitem.Item{
|
|
|
|
stackitem.NewByteArray(containerData),
|
|
|
|
stackitem.NewByteArray(signature),
|
|
|
|
stackitem.NewByteArray(publicKey),
|
|
|
|
stackitem.NewMap(),
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
2020-08-11 11:46:31 +00:00
|
|
|
t.Run("correct behavior", func(t *testing.T) {
|
2020-10-26 14:46:15 +00:00
|
|
|
ev, err := ParsePut([]stackitem.Item{
|
|
|
|
stackitem.NewByteArray(containerData),
|
|
|
|
stackitem.NewByteArray(signature),
|
2021-05-19 14:16:48 +00:00
|
|
|
stackitem.NewByteArray(publicKey),
|
2021-05-25 15:52:55 +00:00
|
|
|
stackitem.NewByteArray(token),
|
2020-08-11 11:46:31 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, Put{
|
|
|
|
rawContainer: containerData,
|
|
|
|
signature: signature,
|
2021-05-19 14:16:48 +00:00
|
|
|
publicKey: publicKey,
|
2021-05-25 15:52:55 +00:00
|
|
|
token: token,
|
2020-08-11 11:46:31 +00:00
|
|
|
}, ev)
|
|
|
|
})
|
|
|
|
}
|