Skip to content

Commit

Permalink
feat: add Namespace method to blob (#1030)
Browse files Browse the repository at this point in the history
* feat: add Namespace method to blob

* lint

---------

Co-authored-by: Callum Waters <cmwaters19@gmail.com>
  • Loading branch information
rootulp and cmwaters committed Jul 13, 2023
1 parent 82c5411 commit 3e636bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,11 @@ type Blob struct {
ShareVersion uint8
}

// Namespace returns the namespace of this blob encoded as a byte slice.
func (b Blob) Namespace() []byte {
return append([]byte{b.NamespaceVersion}, b.NamespaceID...)
}

// StringIndented returns an indented string representation of the transactions.
func (data *Data) StringIndented(indent string) string {
if data == nil {
Expand Down
24 changes: 24 additions & 0 deletions types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,3 +856,27 @@ func TestBlockIDEquals(t *testing.T) {
assert.True(t, blockIDEmpty.Equals(blockIDEmpty))
assert.False(t, blockIDEmpty.Equals(blockIDDifferent))
}

func TestBlob(t *testing.T) {
namespaceVersion := uint8(0)
namespaceID := stdbytes.Repeat([]byte{0x01}, 28)
data := []byte("data")
shareVersion := uint8(0)

blob := Blob{
NamespaceVersion: namespaceVersion,
NamespaceID: namespaceID,
Data: data,
ShareVersion: shareVersion,
}

t.Run("blob.Namespace() returns encoded namespace", func(t *testing.T) {
got := blob.Namespace()
want := []byte{
0, // namespace version
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // namespace ID
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // namespace ID
}
assert.Equal(t, want, got)
})
}

0 comments on commit 3e636bb

Please sign in to comment.