Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Namespace method to blob #1030

Merged
merged 4 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
}