2021-10-27 10:00:35 +00:00
|
|
|
package netmap_test
|
|
|
|
|
|
|
|
import (
|
2022-06-07 08:25:34 +00:00
|
|
|
"encoding/binary"
|
|
|
|
"math"
|
2021-10-27 10:00:35 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
2021-10-27 10:00:35 +00:00
|
|
|
. "github.com/nspcc-dev/neofs-sdk-go/netmap"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
func TestNetworkInfo_CurrentEpoch(t *testing.T) {
|
|
|
|
var x NetworkInfo
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
require.Zero(t, x.CurrentEpoch())
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
const e = 13
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
x.SetCurrentEpoch(e)
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
require.EqualValues(t, e, x.CurrentEpoch())
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
var m netmap.NetworkInfo
|
|
|
|
x.WriteToV2(&m)
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
require.EqualValues(t, e, m.GetCurrentEpoch())
|
2021-10-27 10:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_MagicNumber(t *testing.T) {
|
2022-06-07 08:25:34 +00:00
|
|
|
var x NetworkInfo
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
require.Zero(t, x.MagicNumber())
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
const magic = 321
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
x.SetMagicNumber(magic)
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
require.EqualValues(t, magic, x.MagicNumber())
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
var m netmap.NetworkInfo
|
|
|
|
x.WriteToV2(&m)
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
require.EqualValues(t, magic, m.GetMagicNumber())
|
2021-10-27 10:00:35 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
func TestNetworkInfo_MsPerBlock(t *testing.T) {
|
|
|
|
var x NetworkInfo
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
require.Zero(t, x.MsPerBlock())
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
const ms = 789
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
x.SetMsPerBlock(ms)
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
require.EqualValues(t, ms, x.MsPerBlock())
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
var m netmap.NetworkInfo
|
|
|
|
x.WriteToV2(&m)
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
require.EqualValues(t, ms, m.GetMsPerBlock())
|
2021-10-27 10:00:35 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
func testConfigValue(t *testing.T,
|
|
|
|
getter func(x NetworkInfo) interface{},
|
|
|
|
setter func(x *NetworkInfo, val interface{}),
|
|
|
|
val1, val2 interface{},
|
|
|
|
v2Key string, v2Val func(val interface{}) []byte,
|
|
|
|
) {
|
|
|
|
var x NetworkInfo
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
require.Zero(t, getter(x))
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
checkVal := func(exp interface{}) {
|
|
|
|
require.EqualValues(t, exp, getter(x))
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
var m netmap.NetworkInfo
|
|
|
|
x.WriteToV2(&m)
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
require.EqualValues(t, 1, m.GetNetworkConfig().NumberOfParameters())
|
|
|
|
found := false
|
|
|
|
m.GetNetworkConfig().IterateParameters(func(prm *netmap.NetworkParameter) bool {
|
|
|
|
require.False(t, found)
|
|
|
|
require.Equal(t, []byte(v2Key), prm.GetKey())
|
|
|
|
require.Equal(t, v2Val(exp), prm.GetValue())
|
|
|
|
found = true
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
require.True(t, found)
|
|
|
|
}
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2022-06-07 08:25:34 +00:00
|
|
|
setter(&x, val1)
|
|
|
|
checkVal(val1)
|
|
|
|
|
|
|
|
setter(&x, val2)
|
|
|
|
checkVal(val2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_AuditFee(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
|
|
|
func(x NetworkInfo) interface{} { return x.AuditFee() },
|
|
|
|
func(info *NetworkInfo, val interface{}) { info.SetAuditFee(val.(uint64)) },
|
|
|
|
uint64(1), uint64(2),
|
|
|
|
"AuditFee", func(val interface{}) []byte {
|
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_StoragePrice(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
|
|
|
func(x NetworkInfo) interface{} { return x.StoragePrice() },
|
|
|
|
func(info *NetworkInfo, val interface{}) { info.SetStoragePrice(val.(uint64)) },
|
|
|
|
uint64(1), uint64(2),
|
|
|
|
"BasicIncomeRate", func(val interface{}) []byte {
|
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_ContainerFee(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
|
|
|
func(x NetworkInfo) interface{} { return x.ContainerFee() },
|
|
|
|
func(info *NetworkInfo, val interface{}) { info.SetContainerFee(val.(uint64)) },
|
|
|
|
uint64(1), uint64(2),
|
|
|
|
"ContainerFee", func(val interface{}) []byte {
|
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_NamedContainerFee(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
|
|
|
func(x NetworkInfo) interface{} { return x.NamedContainerFee() },
|
|
|
|
func(info *NetworkInfo, val interface{}) { info.SetNamedContainerFee(val.(uint64)) },
|
|
|
|
uint64(1), uint64(2),
|
|
|
|
"ContainerAliasFee", func(val interface{}) []byte {
|
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_EigenTrustAlpha(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
|
|
|
func(x NetworkInfo) interface{} { return x.EigenTrustAlpha() },
|
|
|
|
func(info *NetworkInfo, val interface{}) { info.SetEigenTrustAlpha(val.(float64)) },
|
|
|
|
0.1, 0.2,
|
|
|
|
"EigenTrustAlpha", func(val interface{}) []byte {
|
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, math.Float64bits(val.(float64)))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_EigenTrustIterationAmount(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
|
|
|
func(x NetworkInfo) interface{} { return x.EigenTrustIterationAmount() },
|
|
|
|
func(info *NetworkInfo, val interface{}) { info.SetEigenTrustIterationAmount(val.(uint64)) },
|
|
|
|
uint64(1), uint64(2),
|
|
|
|
"EigenTrustIterations", func(val interface{}) []byte {
|
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_IRCandidateFee(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
|
|
|
func(x NetworkInfo) interface{} { return x.IRCandidateFee() },
|
|
|
|
func(info *NetworkInfo, val interface{}) { info.SetIRCandidateFee(val.(uint64)) },
|
|
|
|
uint64(1), uint64(2),
|
|
|
|
"InnerRingCandidateFee", func(val interface{}) []byte {
|
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_MaxObjectSize(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
|
|
|
func(x NetworkInfo) interface{} { return x.MaxObjectSize() },
|
|
|
|
func(info *NetworkInfo, val interface{}) { info.SetMaxObjectSize(val.(uint64)) },
|
|
|
|
uint64(1), uint64(2),
|
|
|
|
"MaxObjectSize", func(val interface{}) []byte {
|
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_WithdrawalFee(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
|
|
|
func(x NetworkInfo) interface{} { return x.WithdrawalFee() },
|
|
|
|
func(info *NetworkInfo, val interface{}) { info.SetWithdrawalFee(val.(uint64)) },
|
|
|
|
uint64(1), uint64(2),
|
|
|
|
"WithdrawFee", func(val interface{}) []byte {
|
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
2021-10-27 10:00:35 +00:00
|
|
|
}
|