2021-10-27 10:00:35 +00:00
|
|
|
package netmap_test
|
|
|
|
|
|
|
|
import (
|
2022-06-07 08:25:34 +00:00
|
|
|
"encoding/binary"
|
2021-10-27 10:00:35 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 11:20:03 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
|
|
|
|
. "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
2021-10-27 10:00:35 +00:00
|
|
|
"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,
|
2023-05-15 14:21:49 +00:00
|
|
|
getter func(x NetworkInfo) any,
|
|
|
|
setter func(x *NetworkInfo, val any),
|
|
|
|
val1, val2 any,
|
|
|
|
v2Key string, v2Val func(val any) []byte,
|
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, getter(x))
|
2021-10-27 10:00:35 +00:00
|
|
|
|
2023-05-15 14:21:49 +00:00
|
|
|
checkVal := func(exp any) {
|
2022-06-07 08:25:34 +00:00
|
|
|
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,
|
2023-05-15 14:21:49 +00:00
|
|
|
func(x NetworkInfo) any { return x.AuditFee() },
|
|
|
|
func(info *NetworkInfo, val any) { info.SetAuditFee(val.(uint64)) },
|
2022-06-07 08:25:34 +00:00
|
|
|
uint64(1), uint64(2),
|
2023-05-15 14:21:49 +00:00
|
|
|
"AuditFee", func(val any) []byte {
|
2022-06-07 08:25:34 +00:00
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_StoragePrice(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
2023-05-15 14:21:49 +00:00
|
|
|
func(x NetworkInfo) any { return x.StoragePrice() },
|
|
|
|
func(info *NetworkInfo, val any) { info.SetStoragePrice(val.(uint64)) },
|
2022-06-07 08:25:34 +00:00
|
|
|
uint64(1), uint64(2),
|
2023-05-15 14:21:49 +00:00
|
|
|
"BasicIncomeRate", func(val any) []byte {
|
2022-06-07 08:25:34 +00:00
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_ContainerFee(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
2023-05-15 14:21:49 +00:00
|
|
|
func(x NetworkInfo) any { return x.ContainerFee() },
|
|
|
|
func(info *NetworkInfo, val any) { info.SetContainerFee(val.(uint64)) },
|
2022-06-07 08:25:34 +00:00
|
|
|
uint64(1), uint64(2),
|
2023-05-15 14:21:49 +00:00
|
|
|
"ContainerFee", func(val any) []byte {
|
2022-06-07 08:25:34 +00:00
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_NamedContainerFee(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
2023-05-15 14:21:49 +00:00
|
|
|
func(x NetworkInfo) any { return x.NamedContainerFee() },
|
|
|
|
func(info *NetworkInfo, val any) { info.SetNamedContainerFee(val.(uint64)) },
|
2022-06-07 08:25:34 +00:00
|
|
|
uint64(1), uint64(2),
|
2023-05-15 14:21:49 +00:00
|
|
|
"ContainerAliasFee", func(val any) []byte {
|
2022-06-07 08:25:34 +00:00
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_IRCandidateFee(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
2023-05-15 14:21:49 +00:00
|
|
|
func(x NetworkInfo) any { return x.IRCandidateFee() },
|
|
|
|
func(info *NetworkInfo, val any) { info.SetIRCandidateFee(val.(uint64)) },
|
2022-06-07 08:25:34 +00:00
|
|
|
uint64(1), uint64(2),
|
2023-05-15 14:21:49 +00:00
|
|
|
"InnerRingCandidateFee", func(val any) []byte {
|
2022-06-07 08:25:34 +00:00
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_MaxObjectSize(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
2023-05-15 14:21:49 +00:00
|
|
|
func(x NetworkInfo) any { return x.MaxObjectSize() },
|
|
|
|
func(info *NetworkInfo, val any) { info.SetMaxObjectSize(val.(uint64)) },
|
2022-06-07 08:25:34 +00:00
|
|
|
uint64(1), uint64(2),
|
2023-05-15 14:21:49 +00:00
|
|
|
"MaxObjectSize", func(val any) []byte {
|
2022-06-07 08:25:34 +00:00
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNetworkInfo_WithdrawalFee(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
2023-05-15 14:21:49 +00:00
|
|
|
func(x NetworkInfo) any { return x.WithdrawalFee() },
|
|
|
|
func(info *NetworkInfo, val any) { info.SetWithdrawalFee(val.(uint64)) },
|
2022-06-07 08:25:34 +00:00
|
|
|
uint64(1), uint64(2),
|
2023-05-15 14:21:49 +00:00
|
|
|
"WithdrawFee", func(val any) []byte {
|
2022-06-07 08:25:34 +00:00
|
|
|
data := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
2021-10-27 10:00:35 +00:00
|
|
|
}
|
2022-06-30 15:44:40 +00:00
|
|
|
|
|
|
|
func TestNetworkInfo_HomomorphicHashingDisabled(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
2023-05-15 14:21:49 +00:00
|
|
|
func(x NetworkInfo) any { return x.HomomorphicHashingDisabled() },
|
|
|
|
func(info *NetworkInfo, val any) {
|
2022-06-30 15:44:40 +00:00
|
|
|
if val.(bool) {
|
|
|
|
info.DisableHomomorphicHashing()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true, true, // it is impossible to enable hashing
|
2023-05-15 14:21:49 +00:00
|
|
|
"HomomorphicHashingDisabled", func(val any) []byte {
|
2022-06-30 15:44:40 +00:00
|
|
|
data := make([]byte, 1)
|
|
|
|
|
|
|
|
if val.(bool) {
|
|
|
|
data[0] = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
return data
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2022-09-15 05:45:51 +00:00
|
|
|
|
|
|
|
func TestNetworkInfo_MaintenanceModeAllowed(t *testing.T) {
|
|
|
|
testConfigValue(t,
|
2023-05-15 14:21:49 +00:00
|
|
|
func(x NetworkInfo) any { return x.MaintenanceModeAllowed() },
|
|
|
|
func(info *NetworkInfo, val any) {
|
2022-09-15 05:45:51 +00:00
|
|
|
if val.(bool) {
|
|
|
|
info.AllowMaintenanceMode()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true, true,
|
2023-05-15 14:21:49 +00:00
|
|
|
"MaintenanceModeAllowed", func(val any) []byte {
|
2022-09-15 05:45:51 +00:00
|
|
|
if val.(bool) {
|
|
|
|
return []byte{1}
|
|
|
|
}
|
|
|
|
return []byte{0}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|