frostfs-node/pkg/morph/client/netmap/netmap_test.go
Evgenii Stratonikov d641cba2fc
Some checks failed
Build / Build Components (1.20) (pull_request) Failing after 3s
Build / Build Components (1.21) (pull_request) Failing after 3s
Tests and linters / Lint (pull_request) Failing after 3s
Tests and linters / Tests (1.20) (pull_request) Failing after 3s
Tests and linters / Tests (1.21) (pull_request) Failing after 3s
Tests and linters / Tests with -race (pull_request) Failing after 5s
Tests and linters / Staticcheck (pull_request) Failing after 8s
Vulncheck / Vulncheck (pull_request) Failing after 2s
[#587] Do not use math/rand.Read
Fix staticcheck warnings after go1.20 update.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-08-09 16:02:44 +03:00

59 lines
1.4 KiB
Go

package netmap
import (
"crypto/rand"
"math/big"
"strconv"
"testing"
netmapcontract "git.frostfs.info/TrueCloudLab/frostfs-contract/netmap"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"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)
}