Skip to content

Commit

Permalink
[nspcc-dev#356] refs: Add functions to work with zero subnet
Browse files Browse the repository at this point in the history
Add helper functions which provide ease of use with subnet zero IDs.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
  • Loading branch information
Leonard Lyubich committed Nov 18, 2021
1 parent 580f6c5 commit 31c6451
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions refs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions refs/types_test.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 31c6451

Please sign in to comment.