frostfs-node/pkg/morph/client/netmap/netmap_test.go
Leonard Lyubich eb1fba5182 [#1680] morph/netmap: Adopt to recent contract changes
After recent Netmap contract changes all read methods which return
network map (either candidates or snapshots) encode node descriptors
into same structure.

Decode `netmap.Node` contract-side structure from the call results.
Replace node state with the value from the `netmap.Node.State` field.

Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
2022-10-05 11:41:49 +03:00

59 lines
1.3 KiB
Go

package netmap
import (
"math/big"
"math/rand"
"strconv"
"testing"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
netmapcontract "github.com/nspcc-dev/neofs-contract/netmap"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/stretchr/testify/require"
)
func Test_stackItemsToNodeInfos(t *testing.T) {
expected := make([]netmap.NodeInfo, 4)
for i := range expected {
pub := make([]byte, 33)
rand.Read(pub)
switch i % 3 {
default:
expected[i].SetOffline()
case int(netmapcontract.NodeStateOnline):
expected[i].SetOnline()
case int(netmapcontract.NodeStateMaintenance):
expected[i].SetMaintenance()
}
expected[i].SetPublicKey(pub)
expected[i].SetAttribute("key", strconv.Itoa(i))
}
items := make([]stackitem.Item, 4)
for i := range items {
data := expected[i].Marshal()
var state int64
switch {
case expected[i].IsOnline():
state = int64(netmapcontract.NodeStateOnline)
case expected[i].IsOffline():
state = int64(netmapcontract.NodeStateOffline)
case expected[i].IsMaintenance():
state = int64(netmapcontract.NodeStateMaintenance)
}
items[i] = stackitem.NewStruct([]stackitem.Item{
stackitem.NewByteArray(data),
stackitem.NewBigInteger(big.NewInt(state)),
})
}
actual, err := decodeNodeList(stackitem.NewArray(items))
require.NoError(t, err)
require.Equal(t, expected, actual)
}