2022-03-28 13:44:53 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
2023-08-09 13:01:44 +00:00
|
|
|
"crypto/rand"
|
2022-03-28 13:44:53 +00:00
|
|
|
"math/big"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
netmapcontract "git.frostfs.info/TrueCloudLab/frostfs-contract/netmap"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
2022-03-28 13:44:53 +00:00
|
|
|
"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)
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
switch i % 3 {
|
2022-09-28 11:34:28 +00:00
|
|
|
default:
|
2024-09-18 09:23:46 +00:00
|
|
|
expected[i].SetStatus(netmap.Offline)
|
2022-09-28 11:34:28 +00:00
|
|
|
case int(netmapcontract.NodeStateOnline):
|
2024-09-18 09:23:46 +00:00
|
|
|
expected[i].SetStatus(netmap.Online)
|
2022-09-28 11:34:28 +00:00
|
|
|
case int(netmapcontract.NodeStateMaintenance):
|
2024-09-18 09:23:46 +00:00
|
|
|
expected[i].SetStatus(netmap.Maintenance)
|
2022-06-08 23:18:26 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 13:44:53 +00:00
|
|
|
expected[i].SetPublicKey(pub)
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
expected[i].SetAttribute("key", strconv.Itoa(i))
|
2022-03-28 13:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
items := make([]stackitem.Item, 4)
|
|
|
|
for i := range items {
|
2022-06-08 23:18:26 +00:00
|
|
|
data := expected[i].Marshal()
|
|
|
|
|
|
|
|
var state int64
|
2022-03-28 13:44:53 +00:00
|
|
|
|
2024-09-18 09:23:46 +00:00
|
|
|
switch expected[i].Status() {
|
|
|
|
case netmap.Online:
|
2022-09-28 11:34:28 +00:00
|
|
|
state = int64(netmapcontract.NodeStateOnline)
|
2024-09-18 09:23:46 +00:00
|
|
|
case netmap.Offline:
|
2022-09-28 11:34:28 +00:00
|
|
|
state = int64(netmapcontract.NodeStateOffline)
|
2024-09-18 09:23:46 +00:00
|
|
|
case netmap.Maintenance:
|
2022-09-28 11:34:28 +00:00
|
|
|
state = int64(netmapcontract.NodeStateMaintenance)
|
2022-03-28 13:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
items[i] = stackitem.NewStruct([]stackitem.Item{
|
2022-09-28 11:34:28 +00:00
|
|
|
stackitem.NewByteArray(data),
|
2022-03-28 13:44:53 +00:00
|
|
|
stackitem.NewBigInteger(big.NewInt(state)),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-28 11:34:28 +00:00
|
|
|
actual, err := decodeNodeList(stackitem.NewArray(items))
|
2022-03-28 13:44:53 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expected, actual)
|
|
|
|
}
|