diff --git a/array_test.go b/array_test.go index 60670e9..a0f5abc 100644 --- a/array_test.go +++ b/array_test.go @@ -2891,10 +2891,10 @@ func TestArrayDecodeV0(t *testing.T) { typeInfo := testTypeInfo{42} address := Address{1, 2, 3, 4, 5, 6, 7, 8} - arraySlabID := SlabID{ - address: address, - index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}, - } + arraySlabID := NewSlabID( + address, + SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}, + ) slabData := map[SlabID][]byte{ arraySlabID: { @@ -2931,10 +2931,10 @@ func TestArrayDecodeV0(t *testing.T) { typeInfo := testTypeInfo{42} address := Address{1, 2, 3, 4, 5, 6, 7, 8} - arraySlabID := SlabID{ - address: address, - index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}, - } + arraySlabID := NewSlabID( + address, + SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}, + ) values := []Value{ Uint64Value(0), @@ -2980,10 +2980,10 @@ func TestArrayDecodeV0(t *testing.T) { address := Address{1, 2, 3, 4, 5, 6, 7, 8} - arraySlabID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - arrayDataSlabID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - arrayDataSlabID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} - childArraySlabID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}} + arraySlabID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + arrayDataSlabID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + arrayDataSlabID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) + childArraySlabID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}) const arraySize = 20 values := make([]Value, arraySize) @@ -3218,9 +3218,9 @@ func TestArrayEncodeDecode(t *testing.T) { require.NoError(t, err) } - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -3339,7 +3339,7 @@ func TestArrayEncodeDecode(t *testing.T) { expectedValues[i] = arrayValue{v} } - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -3425,7 +3425,7 @@ func TestArrayEncodeDecode(t *testing.T) { expectedValues[i] = arrayValue{v} } - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -3518,7 +3518,7 @@ func TestArrayEncodeDecode(t *testing.T) { } } - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -3622,7 +3622,7 @@ func TestArrayEncodeDecode(t *testing.T) { } } - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -3722,9 +3722,9 @@ func TestArrayEncodeDecode(t *testing.T) { require.Equal(t, uint64(arraySize), array.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -3874,9 +3874,9 @@ func TestArrayEncodeDecode(t *testing.T) { require.Equal(t, uint64(arraySize), array.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -4024,10 +4024,10 @@ func TestArrayEncodeDecode(t *testing.T) { require.Equal(t, uint64(arraySize), array.Count()) require.Equal(t, uint64(5), childArray.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} - id4 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) + id4 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -4198,10 +4198,10 @@ func TestArrayEncodeDecode(t *testing.T) { require.Equal(t, uint64(1), childArray.Count()) require.Equal(t, uint64(5), gchildArray.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} - id4 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 5}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) + id4 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 5}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ diff --git a/map_test.go b/map_test.go index bdff27e..204d74c 100644 --- a/map_test.go +++ b/map_test.go @@ -7282,7 +7282,7 @@ func TestMapDecodeV0(t *testing.T) { t.Run("empty", func(t *testing.T) { - mapSlabID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + mapSlabID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) slabData := map[SlabID][]byte{ mapSlabID: { @@ -7349,7 +7349,7 @@ func TestMapDecodeV0(t *testing.T) { digesterBuilder.On("Digest", k).Return(mockDigester{d: digests}) } - mapSlabID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + mapSlabID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id slabData := map[SlabID][]byte{ @@ -7431,10 +7431,10 @@ func TestMapDecodeV0(t *testing.T) { // Create nested array typeInfo2 := testTypeInfo{43} - mapSlabID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} - nestedSlabID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}} + mapSlabID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) + nestedSlabID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}) childArray, err := NewArray(storage, address, typeInfo2) childArray.root.SetSlabID(nestedSlabID) @@ -7637,7 +7637,7 @@ func TestMapDecodeV0(t *testing.T) { keyValues[k] = v } - mapSlabID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + mapSlabID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) slabData := map[SlabID][]byte{ @@ -7811,7 +7811,7 @@ func TestMapDecodeV0(t *testing.T) { keyValues[k] = v } - mapSlabID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + mapSlabID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) slabData := map[SlabID][]byte{ @@ -8035,9 +8035,9 @@ func TestMapDecodeV0(t *testing.T) { keyValues[k] = v } - mapSlabID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + mapSlabID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) slabData := map[SlabID][]byte{ @@ -8250,7 +8250,7 @@ func TestMapEncodeDecode(t *testing.T) { require.NoError(t, err) require.Equal(t, uint64(0), m.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) expected := map[SlabID][]byte{ id1: { @@ -8332,7 +8332,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), m.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -8447,9 +8447,9 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), m.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -8669,7 +8669,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), parentMap.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -8864,7 +8864,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), parentMap.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -9057,7 +9057,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), parentMap.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -9336,7 +9336,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), parentMap.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -9581,9 +9581,9 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), parentMap.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 10}} // inlined maps index 2-9 - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 11}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 10}) // inlined maps index 2-9 + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 11}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -10080,9 +10080,9 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), parentMap.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 10}} // inlined maps index 2-9 - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 11}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 10}) // inlined maps index 2-9 + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 11}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -10531,7 +10531,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), m.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -10718,7 +10718,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), m.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -10955,9 +10955,9 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), m.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -11217,9 +11217,9 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), m.Count()) // root slab (data slab) ID - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // child map slab ID - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -11407,9 +11407,9 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), m.Count()) // root slab (data slab) ID - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // grand child map slab ID - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -11625,10 +11625,10 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), m.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} - id4 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) + id4 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -11885,9 +11885,9 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), m.Count()) // parent map root slab ID - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // grand child array root slab ID - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -12027,8 +12027,8 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(1), m.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) expectedNoPointer := []byte{ @@ -12187,7 +12187,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), parentMap.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -12359,7 +12359,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), parentMap.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -12538,7 +12538,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), parentMap.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -12732,7 +12732,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), parentMap.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -12976,7 +12976,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), parentMap.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ @@ -13181,7 +13181,7 @@ func TestMapEncodeDecode(t *testing.T) { require.Equal(t, uint64(mapSize), parentMap.Count()) - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) // Expected serialized slab data with slab id expected := map[SlabID][]byte{ diff --git a/storage_bench_test.go b/storage_bench_test.go index 0736b75..6aad5cc 100644 --- a/storage_bench_test.go +++ b/storage_bench_test.go @@ -45,7 +45,7 @@ func benchmarkFastCommit(b *testing.B, seed int64, numberOfSlabs int) { var index SlabIndex binary.BigEndian.PutUint64(index[:], uint64(i)) - id := SlabID{addr, index} + id := NewSlabID(addr, index) slabs[i] = generateLargeSlab(id) } @@ -86,7 +86,7 @@ func benchmarkNondeterministicFastCommit(b *testing.B, seed int64, numberOfSlabs var index SlabIndex binary.BigEndian.PutUint64(index[:], uint64(i)) - id := SlabID{addr, index} + id := NewSlabID(addr, index) slabs[i] = generateLargeSlab(id) } @@ -151,7 +151,7 @@ func benchmarkRetrieve(b *testing.B, seed int64, numberOfSlabs int) { var index SlabIndex binary.BigEndian.PutUint64(index[:], uint64(i)) - id := SlabID{addr, index} + id := NewSlabID(addr, index) slab := generateLargeSlab(id) @@ -198,7 +198,7 @@ func benchmarkBatchPreload(b *testing.B, seed int64, numberOfSlabs int) { var index SlabIndex binary.BigEndian.PutUint64(index[:], uint64(i)) - id := SlabID{addr, index} + id := NewSlabID(addr, index) slab := generateLargeSlab(id) diff --git a/storage_test.go b/storage_test.go index 95096b2..f7c6a67 100644 --- a/storage_test.go +++ b/storage_test.go @@ -38,12 +38,10 @@ func TestStorageIndexNext(t *testing.T) { func TestNewSlabID(t *testing.T) { t.Run("temp address", func(t *testing.T) { - want := SlabID{address: Address{}, index: SlabIndex{1}} - require.Equal(t, want, NewSlabID(Address{}, SlabIndex{1})) + require.True(t, NewSlabID(Address{}, SlabIndex{1}).HasTempAddress()) }) t.Run("perm address", func(t *testing.T) { - want := SlabID{address: Address{1}, index: SlabIndex{1}} - require.Equal(t, want, NewSlabID(Address{1}, SlabIndex{1})) + require.False(t, NewSlabID(Address{1}, SlabIndex{1}).HasTempAddress()) }) } @@ -70,20 +68,20 @@ func TestNewSlabIDFromRawBytes(t *testing.T) { t.Run("data length == slab id size", func(t *testing.T) { id, err := NewSlabIDFromRawBytes([]byte{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2}) - want := SlabID{ - address: Address{0, 0, 0, 0, 0, 0, 0, 1}, - index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}, - } + want := NewSlabID( + Address{0, 0, 0, 0, 0, 0, 0, 1}, + SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}, + ) require.Equal(t, want, id) require.NoError(t, err) }) t.Run("data length > slab id size", func(t *testing.T) { id, err := NewSlabIDFromRawBytes([]byte{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 1, 2, 3, 4, 5, 6, 7, 8}) - want := SlabID{ - address: Address{0, 0, 0, 0, 0, 0, 0, 1}, - index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}, - } + want := NewSlabID( + Address{0, 0, 0, 0, 0, 0, 0, 1}, + SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}, + ) require.Equal(t, want, id) require.NoError(t, err) }) @@ -206,7 +204,7 @@ func TestSlabIDValid(t *testing.T) { }) t.Run("temp index", func(t *testing.T) { - id := SlabID{address: Address{1}, index: SlabIndexUndefined} + id := NewSlabID(Address{1}, SlabIndexUndefined) err := id.Valid() var fatalError *FatalError @@ -218,12 +216,12 @@ func TestSlabIDValid(t *testing.T) { }) t.Run("temp address", func(t *testing.T) { - id := SlabID{address: AddressUndefined, index: SlabIndex{1}} + id := NewSlabID(AddressUndefined, SlabIndex{1}) require.NoError(t, id.Valid()) }) t.Run("valid", func(t *testing.T) { - id := SlabID{address: Address{1}, index: SlabIndex{2}} + id := NewSlabID(Address{1}, SlabIndex{2}) require.NoError(t, id.Valid()) }) } @@ -310,7 +308,7 @@ func TestLedgerBaseStorageRetrieve(t *testing.T) { ledger := newTestLedger() baseStorage := NewLedgerBaseStorage(ledger) - id := SlabID{address: Address{1}, index: SlabIndex{1}} + id := NewSlabID(Address{1}, SlabIndex{1}) value := []byte{1, 2, 3} bytesStored := 0 bytesRetrieved := 0 @@ -333,7 +331,7 @@ func TestLedgerBaseStorageRetrieve(t *testing.T) { require.Equal(t, value, b) // Retrieve non-existent value - id = SlabID{address: Address{1}, index: SlabIndex{2}} + id = NewSlabID(Address{1}, SlabIndex{2}) b, found, err = baseStorage.Retrieve(id) require.NoError(t, err) require.False(t, found) @@ -347,7 +345,7 @@ func TestLedgerBaseStorageRemove(t *testing.T) { ledger := newTestLedger() baseStorage := NewLedgerBaseStorage(ledger) - id := SlabID{address: Address{1}, index: SlabIndex{1}} + id := NewSlabID(Address{1}, SlabIndex{1}) value := []byte{1, 2, 3} // Remove value from empty storage @@ -366,7 +364,7 @@ func TestLedgerBaseStorageRemove(t *testing.T) { require.NoError(t, err) // Remove non-existent value - err = baseStorage.Remove(SlabID{address: id.address, index: id.index.Next()}) + err = baseStorage.Remove(NewSlabID(id.address, id.index.Next())) require.NoError(t, err) // Retrieve removed value @@ -424,8 +422,8 @@ func TestBasicSlabStorageStore(t *testing.T) { r := newRand(t) address := Address{1} slabs := map[SlabID]Slab{ - {address, SlabIndex{1}}: generateRandomSlab(SlabID{address, SlabIndex{1}}, r), - {address, SlabIndex{2}}: generateRandomSlab(SlabID{address, SlabIndex{2}}, r), + NewSlabID(address, SlabIndex{1}): generateRandomSlab(NewSlabID(address, SlabIndex{1}), r), + NewSlabID(address, SlabIndex{2}): generateRandomSlab(NewSlabID(address, SlabIndex{2}), r), } // Store values @@ -457,7 +455,7 @@ func TestBasicSlabStorageRetrieve(t *testing.T) { storage := NewBasicSlabStorage(nil, nil, nil, nil) r := newRand(t) - id := SlabID{Address{1}, SlabIndex{1}} + id := NewSlabID(Address{1}, SlabIndex{1}) slab := generateRandomSlab(id, r) // Retrieve value from empty storage @@ -476,7 +474,7 @@ func TestBasicSlabStorageRetrieve(t *testing.T) { require.Equal(t, slab, retrievedSlab) // Retrieve non-existent value - id = SlabID{address: Address{1}, index: SlabIndex{2}} + id = NewSlabID(Address{1}, SlabIndex{2}) retrievedSlab, found, err = storage.Retrieve(id) require.NoError(t, err) require.False(t, found) @@ -487,7 +485,7 @@ func TestBasicSlabStorageRemove(t *testing.T) { storage := NewBasicSlabStorage(nil, nil, nil, nil) r := newRand(t) - id := SlabID{Address{1}, SlabIndex{1}} + id := NewSlabID(Address{1}, SlabIndex{1}) slab := generateRandomSlab(id, r) // Remove value from empty storage @@ -506,7 +504,7 @@ func TestBasicSlabStorageRemove(t *testing.T) { require.NoError(t, err) // Remove non-existent value - err = storage.Remove(SlabID{address: id.address, index: id.index.Next()}) + err = storage.Remove(NewSlabID(id.address, id.index.Next())) require.NoError(t, err) // Retrieve removed value @@ -576,9 +574,9 @@ func TestBasicSlabStorageSlabIterat(t *testing.T) { address := Address{1} index := SlabIndex{0, 0, 0, 0, 0, 0, 0, 0} - id1 := SlabID{address: address, index: index.Next()} - id2 := SlabID{address: address, index: index.Next()} - id3 := SlabID{address: address, index: index.Next()} + id1 := NewSlabID(address, index.Next()) + id2 := NewSlabID(address, index.Next()) + id3 := NewSlabID(address, index.Next()) want := map[SlabID]Slab{ id1: generateRandomSlab(id1, r), @@ -929,10 +927,10 @@ func TestPersistentStorageSlabIterator(t *testing.T) { t.Run("not-empty storage", func(t *testing.T) { address := Address{1, 2, 3, 4, 5, 6, 7, 8} - id1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - id2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - id3 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} - id4 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}} + id1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + id2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + id3 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) + id4 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}) data := map[SlabID][]byte{ // (metadata slab) headers: [{id:2 size:228 count:9} {id:3 size:270 count:11} ] @@ -1306,23 +1304,23 @@ func TestFixLoadedBrokenReferences(t *testing.T) { t.Run("healthy", func(t *testing.T) { // Create a health storage with arrays and maps - mapMetaDataRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - mapDataNonRootID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - mapDataNonRootID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} - nestedArrayID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}} + mapMetaDataRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + mapDataNonRootID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + mapDataNonRootID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) + nestedArrayID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}) - emptyMapDataRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 5}} + emptyMapDataRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 5}) - mapDataRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 6}} + mapDataRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 6}) - emptyArrayDataRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 7}} + emptyArrayDataRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 7}) - arrayDataRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 8}} + arrayDataRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 8}) - arrayMetaDataRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 9}} - arrayDataNonRootID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 10}} - arrayDataNonRootID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 11}} - nestedArrayID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 12}} + arrayMetaDataRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 9}) + arrayDataNonRootID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 10}) + arrayDataNonRootID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 11}) + nestedArrayID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 12}) rootIDs := []SlabID{ mapMetaDataRootID, @@ -1758,7 +1756,7 @@ func TestFixLoadedBrokenReferences(t *testing.T) { t.Run("broken root map data slab", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) brokenRefs := map[SlabID][]SlabID{ rootID: {rootID}, @@ -1912,7 +1910,7 @@ func TestFixLoadedBrokenReferences(t *testing.T) { t.Run("broken nested storable in root map data slab", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) brokenRefs := map[SlabID][]SlabID{ rootID: {rootID}, @@ -2065,9 +2063,9 @@ func TestFixLoadedBrokenReferences(t *testing.T) { }) t.Run("broken non-root map data slab", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - nonRootDataID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - nonRootDataID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + nonRootDataID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + nonRootDataID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) brokenRefs := map[SlabID][]SlabID{ rootID: {nonRootDataID2}, @@ -2310,9 +2308,9 @@ func TestFixLoadedBrokenReferences(t *testing.T) { }) t.Run("multiple data slabs with broken reference in the same map", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - nonRootDataID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - nonRootDataID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + nonRootDataID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + nonRootDataID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) brokenRefs := map[SlabID][]SlabID{ rootID: {nonRootDataID1, nonRootDataID2}, @@ -2554,10 +2552,10 @@ func TestFixLoadedBrokenReferences(t *testing.T) { }) t.Run("broken reference in nested container", func(t *testing.T) { - parentContainerRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - nonRootDataID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - nonRootDataID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} - nestedContainerRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}} + parentContainerRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + nonRootDataID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + nonRootDataID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) + nestedContainerRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}) brokenRefs := map[SlabID][]SlabID{ nestedContainerRootID: {nestedContainerRootID}, @@ -2843,11 +2841,11 @@ func TestFixLoadedBrokenReferences(t *testing.T) { }) t.Run("selectively fix maps", func(t *testing.T) { - rootID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - nonRootDataID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - nonRootDataID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} // containing broken ref + rootID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + nonRootDataID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + nonRootDataID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) // containing broken ref - rootID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}} // containing broken ref + rootID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}) // containing broken ref rootIDs := []SlabID{rootID1, rootID2} @@ -3190,7 +3188,7 @@ func TestGetAllChildReferencesFromArray(t *testing.T) { address := Address{1, 2, 3, 4, 5, 6, 7, 8} t.Run("empty", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) expectedRefIDs := []SlabID{} expectedBrokenRefIDs := []SlabID{} @@ -3220,7 +3218,7 @@ func TestGetAllChildReferencesFromArray(t *testing.T) { }) t.Run("root data slab without refs", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) expectedRefIDs := []SlabID{} expectedBrokenRefIDs := []SlabID{} @@ -3252,8 +3250,8 @@ func TestGetAllChildReferencesFromArray(t *testing.T) { }) t.Run("root data slab with ref to nested element", func(t *testing.T) { - parentRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - childRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} + parentRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + childRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) expectedRefIDs := []SlabID{childRootID} expectedBrokenRefIDs := []SlabID{} @@ -3306,8 +3304,8 @@ func TestGetAllChildReferencesFromArray(t *testing.T) { }) t.Run("root data slab with ref in nested storable", func(t *testing.T) { - parentRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - childRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} + parentRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + childRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) expectedRefIDs := []SlabID{childRootID} expectedBrokenRefIDs := []SlabID{} @@ -3360,8 +3358,8 @@ func TestGetAllChildReferencesFromArray(t *testing.T) { }) t.Run("root data slab with broken ref", func(t *testing.T) { - parentRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - childRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} + parentRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + childRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) expectedRefIDs := []SlabID{} expectedBrokenRefIDs := []SlabID{childRootID} @@ -3393,9 +3391,9 @@ func TestGetAllChildReferencesFromArray(t *testing.T) { }) t.Run("root metadata slab", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - nonRootID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - nonRootID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + nonRootID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + nonRootID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) expectedRefIDs := []SlabID{nonRootID1, nonRootID2} expectedBrokenRefIDs := []SlabID{} @@ -3479,9 +3477,9 @@ func TestGetAllChildReferencesFromArray(t *testing.T) { }) t.Run("root metadata slab with broken ref to first data slab", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - nonRootID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - nonRootID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + nonRootID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + nonRootID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) expectedRefIDs := []SlabID{nonRootID2} expectedBrokenRefIDs := []SlabID{nonRootID1} @@ -3543,11 +3541,11 @@ func TestGetAllChildReferencesFromArray(t *testing.T) { }) t.Run("root metadata slab with ref", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - nonRootID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - nonRootID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + nonRootID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + nonRootID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) - childRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}} + childRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}) expectedRefIDs := []SlabID{nonRootID1, nonRootID2, childRootID} expectedBrokenRefIDs := []SlabID{} @@ -3652,11 +3650,11 @@ func TestGetAllChildReferencesFromArray(t *testing.T) { }) t.Run("root metadata slab with broken ref to nested element", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - nonRootID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - nonRootID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + nonRootID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + nonRootID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) - childRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}} + childRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}) expectedRefIDs := []SlabID{nonRootID1, nonRootID2} expectedBrokenRefIDs := []SlabID{childRootID} @@ -3740,9 +3738,9 @@ func TestGetAllChildReferencesFromArray(t *testing.T) { }) t.Run("3-level of nested containers", func(t *testing.T) { - parentRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - childRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - gchildRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + parentRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + childRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + gchildRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) expectedRefIDs := []SlabID{childRootID, gchildRootID} expectedBrokenRefIDs := []SlabID{} @@ -3820,7 +3818,7 @@ func TestGetAllChildReferencesFromMap(t *testing.T) { address := Address{1, 2, 3, 4, 5, 6, 7, 8} t.Run("empty", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) expectedRefIDs := []SlabID{} expectedBrokenRefIDs := []SlabID{} @@ -3867,7 +3865,7 @@ func TestGetAllChildReferencesFromMap(t *testing.T) { }) t.Run("root data slab without refs", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) expectedRefIDs := []SlabID{} expectedBrokenRefIDs := []SlabID{} @@ -3918,8 +3916,8 @@ func TestGetAllChildReferencesFromMap(t *testing.T) { }) t.Run("root data slab with ref", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - childRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + childRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) expectedRefIDs := []SlabID{childRootID} expectedBrokenRefIDs := []SlabID{} @@ -3993,8 +3991,8 @@ func TestGetAllChildReferencesFromMap(t *testing.T) { }) t.Run("root data slab with ref in nested storable", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - childRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + childRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) expectedRefIDs := []SlabID{childRootID} expectedBrokenRefIDs := []SlabID{} @@ -4068,8 +4066,8 @@ func TestGetAllChildReferencesFromMap(t *testing.T) { }) t.Run("root data slab with broken ref", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - childRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + childRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) expectedRefIDs := []SlabID{} expectedBrokenRefIDs := []SlabID{childRootID} @@ -4122,9 +4120,9 @@ func TestGetAllChildReferencesFromMap(t *testing.T) { }) t.Run("root metadata slab", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - nonRootID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - nonRootID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + nonRootID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + nonRootID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) expectedRefIDs := []SlabID{nonRootID1, nonRootID2} expectedBrokenRefIDs := []SlabID{} @@ -4266,9 +4264,9 @@ func TestGetAllChildReferencesFromMap(t *testing.T) { }) t.Run("root metadata slab with broken ref to first data slab", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - nonRootID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - nonRootID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + nonRootID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + nonRootID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) expectedRefIDs := []SlabID{nonRootID2} expectedBrokenRefIDs := []SlabID{nonRootID1} @@ -4361,11 +4359,11 @@ func TestGetAllChildReferencesFromMap(t *testing.T) { }) t.Run("root metadata slab with ref", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - nonRootID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - nonRootID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + nonRootID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + nonRootID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) - childRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}} + childRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}) expectedRefIDs := []SlabID{nonRootID1, nonRootID2, childRootID} expectedBrokenRefIDs := []SlabID{} @@ -4542,11 +4540,11 @@ func TestGetAllChildReferencesFromMap(t *testing.T) { }) t.Run("root metadata slab with broken ref to nested element", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - nonRootID1 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - nonRootID2 := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + nonRootID1 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + nonRootID2 := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) - childRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}} + childRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 4}) expectedRefIDs := []SlabID{nonRootID1, nonRootID2} expectedBrokenRefIDs := []SlabID{childRootID} @@ -4687,9 +4685,9 @@ func TestGetAllChildReferencesFromMap(t *testing.T) { }) t.Run("3-level containers", func(t *testing.T) { - rootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}} - childRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}} - gchildRootID := SlabID{address: address, index: SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}} + rootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 1}) + childRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 2}) + gchildRootID := NewSlabID(address, SlabIndex{0, 0, 0, 0, 0, 0, 0, 3}) expectedRefIDs := []SlabID{childRootID, gchildRootID} expectedBrokenRefIDs := []SlabID{}