forked from TrueCloudLab/frostfs-node
[#280] ir: Add netmap processor unit tests
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
fb5dcc15d2
commit
d00b1c0d29
15 changed files with 690 additions and 41 deletions
|
@ -10,24 +10,24 @@ import (
|
|||
)
|
||||
|
||||
type AddPeer struct {
|
||||
node []byte
|
||||
NodeBytes []byte
|
||||
|
||||
// For notary notifications only.
|
||||
// Contains raw transactions of notary request.
|
||||
notaryRequest *payload.P2PNotaryRequest
|
||||
Request *payload.P2PNotaryRequest
|
||||
}
|
||||
|
||||
// MorphEvent implements Neo:Morph Event interface.
|
||||
func (AddPeer) MorphEvent() {}
|
||||
|
||||
func (s AddPeer) Node() []byte {
|
||||
return s.node
|
||||
return s.NodeBytes
|
||||
}
|
||||
|
||||
// NotaryRequest returns raw notary request if notification
|
||||
// was received via notary service. Otherwise, returns nil.
|
||||
func (s AddPeer) NotaryRequest() *payload.P2PNotaryRequest {
|
||||
return s.notaryRequest
|
||||
return s.Request
|
||||
}
|
||||
|
||||
const expectedItemNumAddPeer = 1
|
||||
|
@ -47,7 +47,7 @@ func ParseAddPeer(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
return nil, event.WrongNumberOfParameters(expectedItemNumAddPeer, ln)
|
||||
}
|
||||
|
||||
ev.node, err = client.BytesFromStackItem(params[0])
|
||||
ev.NodeBytes, err = client.BytesFromStackItem(params[0])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get raw nodeinfo: %w", err)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
func (s *AddPeer) setNode(v []byte) {
|
||||
if v != nil {
|
||||
s.node = v
|
||||
s.NodeBytes = v
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ func ParseAddPeerNotary(ne event.NotaryEvent) (event.Event, error) {
|
|||
}
|
||||
}
|
||||
|
||||
ev.notaryRequest = ne.Raw()
|
||||
ev.Request = ne.Raw()
|
||||
|
||||
return ev, nil
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ func TestParseAddPeer(t *testing.T) {
|
|||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, AddPeer{
|
||||
node: info,
|
||||
NodeBytes: info,
|
||||
}, ev)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -11,12 +11,12 @@ import (
|
|||
|
||||
// NewEpoch is a new epoch Neo:Morph event.
|
||||
type NewEpoch struct {
|
||||
num uint64
|
||||
Num uint64
|
||||
|
||||
// txHash is used in notary environmental
|
||||
// Hash is used in notary environmental
|
||||
// for calculating unique but same for
|
||||
// all notification receivers values.
|
||||
txHash util.Uint256
|
||||
Hash util.Uint256
|
||||
}
|
||||
|
||||
// MorphEvent implements Neo:Morph Event interface.
|
||||
|
@ -24,13 +24,13 @@ func (NewEpoch) MorphEvent() {}
|
|||
|
||||
// EpochNumber returns new epoch number.
|
||||
func (s NewEpoch) EpochNumber() uint64 {
|
||||
return s.num
|
||||
return s.Num
|
||||
}
|
||||
|
||||
// TxHash returns hash of the TX with new epoch
|
||||
// notification.
|
||||
func (s NewEpoch) TxHash() util.Uint256 {
|
||||
return s.txHash
|
||||
return s.Hash
|
||||
}
|
||||
|
||||
// ParseNewEpoch is a parser of new epoch notification event.
|
||||
|
@ -52,7 +52,7 @@ func ParseNewEpoch(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
}
|
||||
|
||||
return NewEpoch{
|
||||
num: uint64(prmEpochNum),
|
||||
txHash: e.Container,
|
||||
Num: uint64(prmEpochNum),
|
||||
Hash: e.Container,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ func TestParseNewEpoch(t *testing.T) {
|
|||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, NewEpoch{
|
||||
num: epochNum,
|
||||
Num: epochNum,
|
||||
}, ev)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -13,13 +13,13 @@ import (
|
|||
)
|
||||
|
||||
type UpdatePeer struct {
|
||||
publicKey *keys.PublicKey
|
||||
PubKey *keys.PublicKey
|
||||
|
||||
state netmap.NodeState
|
||||
State netmap.NodeState
|
||||
|
||||
// For notary notifications only.
|
||||
// Contains raw transactions of notary request.
|
||||
notaryRequest *payload.P2PNotaryRequest
|
||||
Request *payload.P2PNotaryRequest
|
||||
}
|
||||
|
||||
// MorphEvent implements Neo:Morph Event interface.
|
||||
|
@ -28,27 +28,27 @@ func (UpdatePeer) MorphEvent() {}
|
|||
// Online returns true if node's state is requested to be switched
|
||||
// to "online".
|
||||
func (s UpdatePeer) Online() bool {
|
||||
return s.state == netmap.NodeStateOnline
|
||||
return s.State == netmap.NodeStateOnline
|
||||
}
|
||||
|
||||
// Maintenance returns true if node's state is requested to be switched
|
||||
// to "maintenance".
|
||||
func (s UpdatePeer) Maintenance() bool {
|
||||
return s.state == netmap.NodeStateMaintenance
|
||||
return s.State == netmap.NodeStateMaintenance
|
||||
}
|
||||
|
||||
func (s UpdatePeer) PublicKey() *keys.PublicKey {
|
||||
return s.publicKey
|
||||
return s.PubKey
|
||||
}
|
||||
|
||||
// NotaryRequest returns raw notary request if notification
|
||||
// was received via notary service. Otherwise, returns nil.
|
||||
func (s UpdatePeer) NotaryRequest() *payload.P2PNotaryRequest {
|
||||
return s.notaryRequest
|
||||
return s.Request
|
||||
}
|
||||
|
||||
func (s *UpdatePeer) decodeState(state int64) error {
|
||||
switch s.state = netmap.NodeState(state); s.state {
|
||||
switch s.State = netmap.NodeState(state); s.State {
|
||||
default:
|
||||
return fmt.Errorf("unsupported node state %d", state)
|
||||
case
|
||||
|
@ -82,7 +82,7 @@ func ParseUpdatePeer(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
return nil, fmt.Errorf("could not get public key: %w", err)
|
||||
}
|
||||
|
||||
ev.publicKey, err = keys.NewPublicKeyFromBytes(key, elliptic.P256())
|
||||
ev.PubKey, err = keys.NewPublicKeyFromBytes(key, elliptic.P256())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse public key: %w", err)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ func (s *UpdatePeer) setPublicKey(v []byte) (err error) {
|
|||
return errNilPubKey
|
||||
}
|
||||
|
||||
s.publicKey, err = keys.NewPublicKeyFromBytes(v, elliptic.P256())
|
||||
s.PubKey, err = keys.NewPublicKeyFromBytes(v, elliptic.P256())
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not parse public key: %w", err)
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ func ParseUpdatePeerNotary(ne event.NotaryEvent) (event.Event, error) {
|
|||
}
|
||||
}
|
||||
|
||||
ev.notaryRequest = ne.Raw()
|
||||
ev.Request = ne.Raw()
|
||||
|
||||
return ev, nil
|
||||
}
|
||||
|
|
|
@ -52,8 +52,8 @@ func TestParseUpdatePeer(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, UpdatePeer{
|
||||
publicKey: publicKey,
|
||||
state: state,
|
||||
PubKey: publicKey,
|
||||
State: state,
|
||||
}, ev)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue