From f0af5ce7590463373ecee0e21dbfa2de228692c8 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 18 Nov 2021 18:13:17 +0300 Subject: [PATCH] [#356] refs: Add functions to work with zero subnet Add helper functions which provide ease of use with subnet zero IDs. Signed-off-by: Leonard Lyubich --- refs/types.go | 10 ++++++++++ refs/types_test.go | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 refs/types_test.go diff --git a/refs/types.go b/refs/types.go index f3ce145..d8ff91a 100644 --- a/refs/types.go +++ b/refs/types.go @@ -183,6 +183,16 @@ func (s *SubnetID) GetValue() uint32 { return 0 } +// IsZeroSubnet returns true iff the SubnetID refers to zero subnet. +func IsZeroSubnet(id *SubnetID) bool { + return id.GetValue() == 0 +} + +// MakeZeroSubnet makes the SubnetID to refer to zero subnet. +func MakeZeroSubnet(id *SubnetID) { + id.SetValue(0) +} + func (v *Version) GetMajor() uint32 { if v != nil { return v.major diff --git a/refs/types_test.go b/refs/types_test.go new file mode 100644 index 0000000..a1c68cd --- /dev/null +++ b/refs/types_test.go @@ -0,0 +1,20 @@ +package refs_test + +import ( + "testing" + + "github.com/nspcc-dev/neofs-api-go/v2/refs" + "github.com/stretchr/testify/require" +) + +func TestZeroSubnet(t *testing.T) { + id := new(refs.SubnetID) + + require.True(t, refs.IsZeroSubnet(id)) + + id.SetValue(1) + require.False(t, refs.IsZeroSubnet(id)) + + refs.MakeZeroSubnet(id) + require.True(t, refs.IsZeroSubnet(id)) +}