[#1513] Upgrade NeoFS SDK Go with changed netmap package

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-06-09 02:18:26 +03:00 committed by LeL
parent 24b4c1ecf4
commit 21d2f8f861
70 changed files with 878 additions and 992 deletions

View file

@ -10,12 +10,12 @@ import (
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
)
type UpdatePeer struct {
publicKey *keys.PublicKey
status netmap.NodeState
online bool
// For notary notifications only.
// Contains raw transactions of notary request.
@ -25,8 +25,8 @@ type UpdatePeer struct {
// MorphEvent implements Neo:Morph Event interface.
func (UpdatePeer) MorphEvent() {}
func (s UpdatePeer) Status() netmap.NodeState {
return s.status
func (s UpdatePeer) Online() bool {
return s.online
}
func (s UpdatePeer) PublicKey() *keys.PublicKey {
@ -73,7 +73,13 @@ func ParseUpdatePeer(e *subscriptions.NotificationEvent) (event.Event, error) {
return nil, fmt.Errorf("could not get node status: %w", err)
}
ev.status = netmap.NodeStateFromV2(v2netmap.NodeState(st))
switch v2netmap.NodeState(st) {
default:
return nil, fmt.Errorf("unsupported node state %d", st)
case v2netmap.Offline:
case v2netmap.Online:
ev.online = true
}
return ev, nil
}

View file

@ -7,9 +7,8 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
netmapv2 "github.com/nspcc-dev/neofs-api-go/v2/netmap"
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
)
var errNilPubKey = errors.New("could not parse public key: public key is nil")
@ -27,10 +26,6 @@ func (s *UpdatePeer) setPublicKey(v []byte) (err error) {
return
}
func (s *UpdatePeer) setStatus(v uint32) {
s.status = netmap.NodeStateFromV2(netmapv2.NodeState(v))
}
const (
// UpdateStateNotaryEvent is method name for netmap state updating
// operations in `Netmap` contract. Is used as identificator for
@ -66,7 +61,13 @@ func ParseUpdatePeerNotary(ne event.NotaryEvent) (event.Event, error) {
return nil, err
}
ev.setStatus(uint32(state))
switch v2netmap.NodeState(state) {
default:
return nil, fmt.Errorf("unsupported node state %d", err)
case v2netmap.Offline:
case v2netmap.Online:
ev.online = true
}
fieldNum++
case fieldNum == expectedItemNumUpdatePeer:

View file

@ -7,7 +7,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"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/netmap"
"github.com/stretchr/testify/require"
)
@ -15,10 +14,7 @@ func TestParseUpdatePeer(t *testing.T) {
priv, err := keys.NewPrivateKey()
require.NoError(t, err)
var (
publicKey = priv.PublicKey()
state = netmap.NodeStateOffline
)
publicKey := priv.PublicKey()
t.Run("wrong number of parameters", func(t *testing.T) {
prms := []stackitem.Item{
@ -48,14 +44,14 @@ func TestParseUpdatePeer(t *testing.T) {
t.Run("correct behavior", func(t *testing.T) {
ev, err := ParseUpdatePeer(createNotifyEventFromItems([]stackitem.Item{
stackitem.NewBigInteger(new(big.Int).SetInt64(int64(state.ToV2()))),
stackitem.NewBigInteger(new(big.Int).SetInt64(1)),
stackitem.NewByteArray(publicKey.Bytes()),
}))
require.NoError(t, err)
require.Equal(t, UpdatePeer{
publicKey: publicKey,
status: state,
online: true,
}, ev)
})
}