2020-09-02 13:05: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-09-02 13:05:31 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseDelete(t *testing.T) {
|
|
|
|
var (
|
|
|
|
containerID = []byte("containreID")
|
|
|
|
signature = []byte("signature")
|
2021-05-26 10:55:58 +00:00
|
|
|
token = []byte("token")
|
2020-09-02 13:05: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(),
|
2020-09-02 13:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err := ParseDelete(prms)
|
2021-05-26 10:55:58 +00:00
|
|
|
require.EqualError(t, err, event.WrongNumberOfParameters(3, len(prms)).Error())
|
2020-09-02 13:05:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong container parameter", func(t *testing.T) {
|
2021-01-28 15:01:10 +00:00
|
|
|
_, err := ParseDelete([]stackitem.Item{
|
2020-10-26 14:46:15 +00:00
|
|
|
stackitem.NewMap(),
|
2020-09-02 13:05: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 := ParseDelete([]stackitem.Item{
|
|
|
|
stackitem.NewByteArray(containerID),
|
|
|
|
stackitem.NewMap(),
|
2020-09-02 13:05:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
2021-05-26 10:55:58 +00:00
|
|
|
t.Run("wrong session token parameter", func(t *testing.T) {
|
|
|
|
_, err := ParseDelete([]stackitem.Item{
|
|
|
|
stackitem.NewByteArray(containerID),
|
|
|
|
stackitem.NewByteArray(signature),
|
|
|
|
stackitem.NewMap(),
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
2020-09-02 13:05:31 +00:00
|
|
|
t.Run("correct behavior", func(t *testing.T) {
|
2020-10-26 14:46:15 +00:00
|
|
|
ev, err := ParseDelete([]stackitem.Item{
|
|
|
|
stackitem.NewByteArray(containerID),
|
|
|
|
stackitem.NewByteArray(signature),
|
2021-05-26 10:55:58 +00:00
|
|
|
stackitem.NewByteArray(token),
|
2020-09-02 13:05:31 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, Delete{
|
|
|
|
containerID: containerID,
|
|
|
|
signature: signature,
|
2021-05-26 10:55:58 +00:00
|
|
|
token: token,
|
2020-09-02 13:05:31 +00:00
|
|
|
}, ev)
|
|
|
|
})
|
|
|
|
}
|