[#337] container: Remove unused events

Done in TrueCloudLab/frostfs-contract#16.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-05-11 18:14:00 +03:00 committed by Evgenii Stratonikov
parent bcdb0f330d
commit b480df4985
7 changed files with 2 additions and 409 deletions

View file

@ -79,13 +79,6 @@ type NetworkState interface {
HomomorphicHashDisabled() (bool, error)
}
const (
putNotification = "containerPut"
deleteNotification = "containerDelete"
setEACLNotification = "setEACL"
)
// New creates a container contract processor instance.
func New(p *Params) (*Processor, error) {
switch {
@ -121,66 +114,12 @@ func New(p *Params) (*Processor, error) {
// ListenerNotificationParsers for the 'event.Listener' event producer.
func (cp *Processor) ListenerNotificationParsers() []event.NotificationParserInfo {
if !cp.notaryDisabled {
return nil
}
var (
parsers = make([]event.NotificationParserInfo, 0, 3)
p event.NotificationParserInfo
)
p.SetScriptHash(cp.cnrClient.ContractAddress())
// container put
p.SetType(event.TypeFromString(putNotification))
p.SetParser(containerEvent.ParsePut)
parsers = append(parsers, p)
// container delete
p.SetType(event.TypeFromString(deleteNotification))
p.SetParser(containerEvent.ParseDelete)
parsers = append(parsers, p)
// set eACL
p.SetType(event.TypeFromString(setEACLNotification))
p.SetParser(containerEvent.ParseSetEACL)
parsers = append(parsers, p)
return parsers
}
// ListenerNotificationHandlers for the 'event.Listener' event producer.
func (cp *Processor) ListenerNotificationHandlers() []event.NotificationHandlerInfo {
if !cp.notaryDisabled {
return nil
}
var (
handlers = make([]event.NotificationHandlerInfo, 0, 3)
h event.NotificationHandlerInfo
)
h.SetScriptHash(cp.cnrClient.ContractAddress())
// container put
h.SetType(event.TypeFromString(putNotification))
h.SetHandler(cp.handlePut)
handlers = append(handlers, h)
// container delete
h.SetType(event.TypeFromString(deleteNotification))
h.SetHandler(cp.handleDelete)
handlers = append(handlers, h)
// set eACL
h.SetType(event.TypeFromString(setEACLNotification))
h.SetHandler(cp.handleSetEACL)
handlers = append(handlers, h)
return handlers
}
// ListenerNotaryParsers for the 'event.Listener' notary event producer.

View file

@ -44,45 +44,6 @@ func (d Delete) NotaryRequest() *payload.P2PNotaryRequest {
const expectedItemNumDelete = 3
// ParseDelete from notification into container event structure.
//
// Expects 3 stack items.
func ParseDelete(e *state.ContainedNotificationEvent) (event.Event, error) {
var (
ev Delete
err error
)
params, err := event.ParseStackArray(e)
if err != nil {
return nil, fmt.Errorf("could not parse stack items from notify event: %w", err)
}
if ln := len(params); ln != expectedItemNumDelete {
return nil, event.WrongNumberOfParameters(expectedItemNumDelete, ln)
}
// parse container
ev.ContainerIDValue, err = client.BytesFromStackItem(params[0])
if err != nil {
return nil, fmt.Errorf("could not get container: %w", err)
}
// parse signature
ev.SignatureValue, err = client.BytesFromStackItem(params[1])
if err != nil {
return nil, fmt.Errorf("could not get signature: %w", err)
}
// parse session token
ev.TokenValue, err = client.BytesFromStackItem(params[2])
if err != nil {
return nil, fmt.Errorf("could not get session token: %w", err)
}
return ev, nil
}
// DeleteSuccess structures notification event of successful container removal
// thrown by Container contract.
type DeleteSuccess struct {

View file

@ -10,66 +10,6 @@ import (
"github.com/stretchr/testify/require"
)
func TestParseDelete(t *testing.T) {
var (
containerID = []byte("containreID")
signature = []byte("signature")
token = []byte("token")
)
t.Run("wrong number of parameters", func(t *testing.T) {
prms := []stackitem.Item{
stackitem.NewMap(),
}
_, err := ParseDelete(createNotifyEventFromItems(prms))
require.EqualError(t, err, event.WrongNumberOfParameters(3, len(prms)).Error())
})
t.Run("wrong container parameter", func(t *testing.T) {
_, err := ParseDelete(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("wrong signature parameter", func(t *testing.T) {
_, err := ParseDelete(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewByteArray(containerID),
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("wrong session token parameter", func(t *testing.T) {
_, err := ParseDelete(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewByteArray(containerID),
stackitem.NewByteArray(signature),
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("correct behavior", func(t *testing.T) {
ev, err := ParseDelete(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewByteArray(containerID),
stackitem.NewByteArray(signature),
stackitem.NewByteArray(token),
}))
require.NoError(t, err)
require.Equal(t, Delete{
ContainerIDValue: containerID,
SignatureValue: signature,
TokenValue: token,
}, ev)
})
}
func TestParseDeleteSuccess(t *testing.T) {
t.Run("wrong number of parameters", func(t *testing.T) {
prms := []stackitem.Item{

View file

@ -1,11 +1,6 @@
package container
import (
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/network/payload"
)
@ -54,48 +49,3 @@ func (x SetEACL) NotaryRequest() *payload.P2PNotaryRequest {
}
const expectedItemNumEACL = 4
// ParseSetEACL parses SetEACL notification event from list of stack items.
//
// Expects 4 stack items.
func ParseSetEACL(e *state.ContainedNotificationEvent) (event.Event, error) {
var (
ev SetEACL
err error
)
params, err := event.ParseStackArray(e)
if err != nil {
return nil, fmt.Errorf("could not parse stack items from notify event: %w", err)
}
if ln := len(params); ln != expectedItemNumEACL {
return nil, event.WrongNumberOfParameters(expectedItemNumEACL, ln)
}
// parse table
ev.TableValue, err = client.BytesFromStackItem(params[0])
if err != nil {
return nil, fmt.Errorf("could not parse binary table: %w", err)
}
// parse signature
ev.SignatureValue, err = client.BytesFromStackItem(params[1])
if err != nil {
return nil, fmt.Errorf("could not parse table signature: %w", err)
}
// parse public key
ev.PublicKeyValue, err = client.BytesFromStackItem(params[2])
if err != nil {
return nil, fmt.Errorf("could not parse binary public key: %w", err)
}
// parse session token
ev.TokenValue, err = client.BytesFromStackItem(params[3])
if err != nil {
return nil, fmt.Errorf("could not get session token: %w", err)
}
return ev, nil
}

View file

@ -1,90 +1,10 @@
package container
import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/stretchr/testify/require"
)
func TestParseEACL(t *testing.T) {
var (
binaryTable = []byte("table")
signature = []byte("signature")
publicKey = []byte("pubkey")
token = []byte("token")
)
t.Run("wrong number of parameters", func(t *testing.T) {
items := []stackitem.Item{
stackitem.NewMap(),
stackitem.NewMap(),
}
_, err := ParseSetEACL(createNotifyEventFromItems(items))
require.EqualError(t, err, event.WrongNumberOfParameters(4, len(items)).Error())
})
t.Run("wrong container parameter", func(t *testing.T) {
_, err := ParseSetEACL(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewMap(),
stackitem.NewMap(),
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("wrong signature parameter", func(t *testing.T) {
_, err := ParseSetEACL(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewByteArray(binaryTable),
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("wrong key parameter", func(t *testing.T) {
_, err := ParseSetEACL(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewByteArray(binaryTable),
stackitem.NewByteArray(signature),
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("wrong session token parameter", func(t *testing.T) {
_, err := ParseSetEACL(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewByteArray(binaryTable),
stackitem.NewByteArray(signature),
stackitem.NewByteArray(publicKey),
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("correct behavior", func(t *testing.T) {
ev, err := ParseSetEACL(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewByteArray(binaryTable),
stackitem.NewByteArray(signature),
stackitem.NewByteArray(publicKey),
stackitem.NewByteArray(token),
}))
require.NoError(t, err)
e := ev.(SetEACL)
require.Equal(t, binaryTable, e.Table())
require.Equal(t, signature, e.Signature())
require.Equal(t, publicKey, e.PublicKey())
require.Equal(t, token, e.SessionToken())
})
}
func createNotifyEventFromItems(items []stackitem.Item) *state.ContainedNotificationEvent {
return &state.ContainedNotificationEvent{
NotificationEvent: state.NotificationEvent{

View file

@ -65,49 +65,6 @@ func (x PutNamed) Zone() string {
return x.zone
}
// ParsePut from notification into container event structure.
func ParsePut(e *state.ContainedNotificationEvent) (event.Event, error) {
var (
ev Put
err error
)
params, err := event.ParseStackArray(e)
if err != nil {
return nil, fmt.Errorf("could not parse stack items from notify event: %w", err)
}
if ln := len(params); ln != expectedItemNumPut {
return nil, event.WrongNumberOfParameters(expectedItemNumPut, ln)
}
// parse container
ev.rawContainer, err = client.BytesFromStackItem(params[0])
if err != nil {
return nil, fmt.Errorf("could not get container: %w", err)
}
// parse signature
ev.signature, err = client.BytesFromStackItem(params[1])
if err != nil {
return nil, fmt.Errorf("could not get signature: %w", err)
}
// parse public key
ev.publicKey, err = client.BytesFromStackItem(params[2])
if err != nil {
return nil, fmt.Errorf("could not get public key: %w", err)
}
// parse session token
ev.token, err = client.BytesFromStackItem(params[3])
if err != nil {
return nil, fmt.Errorf("could not get sesison token: %w", err)
}
return ev, nil
}
// PutSuccess structures notification event of successful container creation
// thrown by Container contract.
type PutSuccess struct {

View file

@ -10,80 +10,6 @@ import (
"github.com/stretchr/testify/require"
)
func TestParsePut(t *testing.T) {
var (
containerData = []byte("containerData")
signature = []byte("signature")
publicKey = []byte("pubkey")
token = []byte("token")
)
t.Run("wrong number of parameters", func(t *testing.T) {
prms := []stackitem.Item{
stackitem.NewMap(),
stackitem.NewMap(),
}
_, err := ParsePut(createNotifyEventFromItems(prms))
require.EqualError(t, err, event.WrongNumberOfParameters(expectedItemNumPut, len(prms)).Error())
})
t.Run("wrong container parameter", func(t *testing.T) {
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("wrong signature parameter", func(t *testing.T) {
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewByteArray(containerData),
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("wrong key parameter", func(t *testing.T) {
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewByteArray(containerData),
stackitem.NewByteArray(signature),
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("wrong session token parameter", func(t *testing.T) {
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewByteArray(containerData),
stackitem.NewByteArray(signature),
stackitem.NewByteArray(publicKey),
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("correct behavior", func(t *testing.T) {
ev, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewByteArray(containerData),
stackitem.NewByteArray(signature),
stackitem.NewByteArray(publicKey),
stackitem.NewByteArray(token),
}))
require.NoError(t, err)
require.Equal(t, Put{
rawContainer: containerData,
signature: signature,
publicKey: publicKey,
token: token,
}, ev)
})
}
func TestParsePutSuccess(t *testing.T) {
t.Run("wrong number of parameters", func(t *testing.T) {
prms := []stackitem.Item{