[#302] pkg/netmap: Document default values set in `NewNetworkInfo`

Document field values of instance constructed via `NewNetworkInfo`.
Assert the values in corresponding unit test.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
remotes/KirillovDenis/feature/refactor-sig-rpc
Pavel Karpy 2021-06-08 17:11:11 +03:00 committed by Alex Vanin
parent 6142a352da
commit 19cf3c2d0b
2 changed files with 18 additions and 0 deletions

View File

@ -16,6 +16,10 @@ func NewNetworkInfoFromV2(iV2 *netmap.NetworkInfo) *NetworkInfo {
}
// NewNetworkInfo creates and initializes blank NetworkInfo.
//
// Defaults:
// - curEpoch: 0;
// - magicNum: 0.
func NewNetworkInfo() *NetworkInfo {
return NewNetworkInfoFromV2(new(netmap.NetworkInfo))
}

View File

@ -65,3 +65,17 @@ func TestNetworkInfo_ToV2(t *testing.T) {
require.Nil(t, x.ToV2())
})
}
func TestNewNetworkInfo(t *testing.T) {
ni := NewNetworkInfo()
// check initial values
require.Zero(t, ni.CurrentEpoch())
require.Zero(t, ni.MagicNumber())
// convert to v2 message
niV2 := ni.ToV2()
require.Zero(t, niV2.GetCurrentEpoch())
require.Zero(t, niV2.GetMagicNumber())
}