Skip to content

Commit

Permalink
Add SlabID.Address()
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker committed Aug 14, 2024
1 parent bb0f1aa commit d61caa8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func (id SlabID) AddressAsUint64() uint64 {
return binary.BigEndian.Uint64(id.address[:])
}

// Address returns the address of SlabID.
func (id SlabID) Address() Address {
return id.address
}

func (id SlabID) IndexAsUint64() uint64 {
return binary.BigEndian.Uint64(id.index[:])
}
Expand Down
11 changes: 11 additions & 0 deletions storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ func TestSlabIDAddressAsUint64(t *testing.T) {
})
}

func TestSlabIDAddress(t *testing.T) {
t.Run("temp", func(t *testing.T) {
id := NewSlabID(Address{}, SlabIndex{1})
require.Equal(t, Address{}, id.Address())
})
t.Run("perm", func(t *testing.T) {
id := NewSlabID(Address{0, 0, 0, 0, 0, 0, 0, 1}, SlabIndex{1})
require.Equal(t, Address{0, 0, 0, 0, 0, 0, 0, 1}, id.Address())
})
}

func TestSlabIDIndexAsUint64(t *testing.T) {
t.Run("temp", func(t *testing.T) {
id := NewSlabID(Address{}, SlabIndex{})
Expand Down

0 comments on commit d61caa8

Please sign in to comment.