Skip to content

Commit

Permalink
fix nits
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Oct 14, 2024
1 parent fa5e214 commit ff76792
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 38 deletions.
4 changes: 2 additions & 2 deletions share/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ func SortBlobs(blobs []*Blob) {
})
}

// IsBlobNamespace returns a true if this namespace is a valid user-specifiable
// IsValidBlobNamespace returns a true if this namespace is a valid user-specifiable
// blob namespace.
func IsBlobNamespace(ns Namespace) bool {
func IsValidBlobNamespace(ns Namespace) bool {
if ns.IsReserved() {
return false
}
Expand Down
25 changes: 0 additions & 25 deletions share/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,31 +241,6 @@ func (n Namespace) Compare(n2 Namespace) int {
return bytes.Compare(n.data, n2.data)
}

// IsOutsideRange checks if the namespace is outside the min-max range of the given hashes.
func (n Namespace) IsOutsideRange(leftHash, rightHash []byte) bool {
if len(leftHash) < NamespaceSize || len(rightHash) < 2*NamespaceSize {
return false
}
return n.IsLessThan(Namespace{data: leftHash[:NamespaceSize]}) ||
!n.IsLessOrEqualThan(Namespace{data: rightHash[NamespaceSize : NamespaceSize*2]})
}

// IsAboveMax checks if the namespace is above the maximum namespace of the given hash.
func (n Namespace) IsAboveMax(hash []byte) bool {
if len(hash) < 2*NamespaceSize {
return false
}
return !n.IsLessOrEqualThan(Namespace{data: hash[NamespaceSize : NamespaceSize*2]})
}

// IsBelowMin checks if the target namespace is below the minimum namespace of the given hash.
func (n Namespace) IsBelowMin(hash []byte) bool {
if len(hash) < NamespaceSize {
return false
}
return n.IsLessThan(Namespace{data: hash[:NamespaceSize]})
}

// leftPad returns a new byte slice with the provided byte slice left-padded to the provided size.
// If the provided byte slice is already larger than the provided size, the original byte slice is returned.
func leftPad(b []byte, size int) []byte {
Expand Down
17 changes: 8 additions & 9 deletions share/random_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package share
import (
"crypto/rand"
"encoding/binary"
"errors"
"github.com/stretchr/testify/assert"
"testing"
)

func RandomNamespace() Namespace {
Expand Down Expand Up @@ -39,18 +40,16 @@ func RandomBlobNamespace() Namespace {
for {
id := RandomBlobNamespaceID()
namespace := MustNewV0Namespace(id)
if IsBlobNamespace(namespace) {
if IsValidBlobNamespace(namespace) {
return namespace
}
}
}

// AddInt adds arbitrary int value to namespace, treating namespace as big-endian
// implementation of int
func AddInt(n Namespace, val int) (Namespace, error) {
if val == 0 {
return n, nil
}
// implementation of int. Note: should only be used for tests.
func AddInt(t *testing.T, n Namespace, val int) Namespace {
assert.Greater(t, val, 0)
// Convert the input integer to a byte slice and add it to result slice
result := make([]byte, NamespaceSize)
if val > 0 {
Expand Down Expand Up @@ -86,8 +85,8 @@ func AddInt(n Namespace, val int) (Namespace, error) {

// Handle any remaining carry
if carry != 0 {
return Namespace{}, errors.New("namespace overflow")
t.Fatal("namespace overflow")
}

return Namespace{data: result}, nil
return Namespace{data: result}
}
4 changes: 2 additions & 2 deletions share/share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ func TestShareToBytesAndFromBytes(t *testing.T) {

func TestMarshalShare(t *testing.T) {
sh := RandShares(1)[0]
b, err := sh[0].MarshalJSON()
b, err := sh.MarshalJSON()
require.NoError(t, err)

newShare := Share{}
err = newShare.UnmarshalJSON(b)
require.NoError(t, err)

require.Equal(t, sh[0], newShare)
require.Equal(t, sh, newShare)
}

0 comments on commit ff76792

Please sign in to comment.