forked from TrueCloudLab/frostfs-node
[#1239] morph/client: Remove intermediate conversion in morph client
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
6936195afa
commit
882236a03b
2 changed files with 68 additions and 59 deletions
50
pkg/morph/client/netmap/netmap_test.go
Normal file
50
pkg/morph/client/netmap/netmap_test.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package netmap
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"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)
|
||||
|
||||
expected[i].SetState(netmap.NodeState(i % 3))
|
||||
expected[i].SetPublicKey(pub)
|
||||
|
||||
var attr netmap.NodeAttribute
|
||||
attr.SetKey("key")
|
||||
attr.SetValue(strconv.Itoa(i))
|
||||
expected[i].SetAttributes(attr)
|
||||
}
|
||||
|
||||
items := make([]stackitem.Item, 4)
|
||||
for i := range items {
|
||||
data, err := expected[i].Marshal()
|
||||
require.NoError(t, err)
|
||||
|
||||
state := int64(expected[i].State())
|
||||
if state != 0 { // In contract online=1, offline=2, in API it is the other way.
|
||||
state = 3 - state
|
||||
}
|
||||
|
||||
items[i] = stackitem.NewStruct([]stackitem.Item{
|
||||
stackitem.NewStruct([]stackitem.Item{
|
||||
stackitem.NewByteArray(data),
|
||||
}),
|
||||
stackitem.NewBigInteger(big.NewInt(state)),
|
||||
})
|
||||
}
|
||||
|
||||
actual, err := nodeInfosFromStackItems([]stackitem.Item{stackitem.NewArray(items)}, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expected, actual)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue