Skip to content

Commit 141ec5c

Browse files
authored
Merge pull request #435 from onflow/fxamacker/add-SlabID.Address-func
Add SlabID.Address()
2 parents 5be1546 + d61caa8 commit 141ec5c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

storage.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ func (id SlabID) AddressAsUint64() uint64 {
136136
return binary.BigEndian.Uint64(id.address[:])
137137
}
138138

139+
// Address returns the address of SlabID.
140+
func (id SlabID) Address() Address {
141+
return id.address
142+
}
143+
139144
func (id SlabID) IndexAsUint64() uint64 {
140145
return binary.BigEndian.Uint64(id.index[:])
141146
}

storage_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ func TestSlabIDAddressAsUint64(t *testing.T) {
170170
})
171171
}
172172

173+
func TestSlabIDAddress(t *testing.T) {
174+
t.Run("temp", func(t *testing.T) {
175+
id := NewSlabID(Address{}, SlabIndex{1})
176+
require.Equal(t, Address{}, id.Address())
177+
})
178+
t.Run("perm", func(t *testing.T) {
179+
id := NewSlabID(Address{0, 0, 0, 0, 0, 0, 0, 1}, SlabIndex{1})
180+
require.Equal(t, Address{0, 0, 0, 0, 0, 0, 0, 1}, id.Address())
181+
})
182+
}
183+
173184
func TestSlabIDIndexAsUint64(t *testing.T) {
174185
t.Run("temp", func(t *testing.T) {
175186
id := NewSlabID(Address{}, SlabIndex{})

0 commit comments

Comments
 (0)