diff --git a/storage.go b/storage.go index b4cf7af..2200f05 100644 --- a/storage.go +++ b/storage.go @@ -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[:]) } diff --git a/storage_test.go b/storage_test.go index bba9461..68bf5df 100644 --- a/storage_test.go +++ b/storage_test.go @@ -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{})