frostfs-node/pkg/morph/event/reputation/put_test.go
Evgenii Stratonikov 07465849a4 [#1637] go.mod: Update neo-go to v0.99.1
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
2022-07-28 20:11:45 +03:00

92 lines
2.2 KiB
Go

package reputation
import (
"math/big"
"testing"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-sdk-go/reputation"
reputationtest "github.com/nspcc-dev/neofs-sdk-go/reputation/test"
"github.com/stretchr/testify/require"
)
func TestParsePut(t *testing.T) {
var (
peerID = reputationtest.PeerID()
value reputation.GlobalTrust
trust reputation.Trust
trustValue float64 = 0.64
epoch uint64 = 42
)
trust.SetValue(trustValue)
trust.SetPeer(peerID)
value.SetTrust(trust)
rawValue := value.Marshal()
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(3, len(prms)).Error())
})
t.Run("wrong epoch parameter", func(t *testing.T) {
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("wrong peerID parameter", func(t *testing.T) {
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewBigInteger(new(big.Int).SetUint64(epoch)),
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("wrong value parameter", func(t *testing.T) {
_, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewBigInteger(new(big.Int).SetUint64(epoch)),
stackitem.NewByteArray(peerID.PublicKey()),
stackitem.NewMap(),
}))
require.Error(t, err)
})
t.Run("correct behavior", func(t *testing.T) {
ev, err := ParsePut(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewBigInteger(new(big.Int).SetUint64(epoch)),
stackitem.NewByteArray(peerID.PublicKey()),
stackitem.NewByteArray(rawValue),
}))
require.NoError(t, err)
require.Equal(t, Put{
epoch: epoch,
peerID: peerID,
value: value,
}, ev)
})
}
func createNotifyEventFromItems(items []stackitem.Item) *state.ContainedNotificationEvent {
return &state.ContainedNotificationEvent{
NotificationEvent: state.NotificationEvent{
Item: stackitem.NewArray(items),
},
}
}