Skip to content

Commit

Permalink
Merge pull request #435 from onflow/fxamacker/add-SlabID.Address-func
Browse files Browse the repository at this point in the history
Add SlabID.Address()
  • Loading branch information
fxamacker authored Aug 15, 2024
2 parents 5be1546 + d61caa8 commit 141ec5c
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 141ec5c

Please sign in to comment.