Skip to content

Commit

Permalink
Improve tests to compare child map elements
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker committed Sep 26, 2023
1 parent 04f93a2 commit 00a6df8
Show file tree
Hide file tree
Showing 3 changed files with 586 additions and 302 deletions.
66 changes: 34 additions & 32 deletions array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1482,73 +1482,75 @@ func TestArrayWithChildArrayMap(t *testing.T) {

const arraySize = 4096

nestedTypeInfo := testTypeInfo{43}

typeInfo := testTypeInfo{42}
childArayTypeInfo := testTypeInfo{43}
storage := newTestPersistentStorage(t)

address := Address{1, 2, 3, 4, 5, 6, 7, 8}

nestedMaps := make([]Value, arraySize)
array, err := NewArray(storage, address, typeInfo)
require.NoError(t, err)

expectedValues := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
nested, err := NewMap(storage, address, NewDefaultDigesterBuilder(), nestedTypeInfo)
childMap, err := NewMap(storage, address, NewDefaultDigesterBuilder(), childArayTypeInfo)
require.NoError(t, err)

storable, err := nested.Set(compare, hashInputProvider, Uint64Value(i), Uint64Value(i*2))
k := Uint64Value(i)
v := Uint64Value(i * 2)
storable, err := childMap.Set(compare, hashInputProvider, k, v)
require.NoError(t, err)
require.Nil(t, storable)

require.True(t, nested.root.IsData())
require.True(t, childMap.root.IsData())

nestedMaps[i] = nested
}

typeInfo := testTypeInfo{42}

array, err := NewArray(storage, address, typeInfo)
require.NoError(t, err)

for _, a := range nestedMaps {
err := array.Append(a)
err = array.Append(childMap)
require.NoError(t, err)

expectedValues[i] = mapValue{k: v}
}

verifyArray(t, storage, typeInfo, address, array, nestedMaps, false)
verifyArray(t, storage, typeInfo, address, array, expectedValues, false)
})

t.Run("big map", func(t *testing.T) {

const arraySize = 4096

typeInfo := testTypeInfo{42}
nestedTypeInfo := testTypeInfo{43}
storage := newTestPersistentStorage(t)
address := Address{1, 2, 3, 4, 5, 6, 7, 8}

values := make([]Value, arraySize)
array, err := NewArray(storage, address, typeInfo)
require.NoError(t, err)

expectedValues := make([]Value, arraySize)
for i := uint64(0); i < arraySize; i++ {
nested, err := NewMap(storage, address, NewDefaultDigesterBuilder(), nestedTypeInfo)

childMap, err := NewMap(storage, address, NewDefaultDigesterBuilder(), nestedTypeInfo)
require.NoError(t, err)

expectedChildMapValues := mapValue{}
for i := uint64(0); i < 25; i++ {
storable, err := nested.Set(compare, hashInputProvider, Uint64Value(i), Uint64Value(i*2))
k := Uint64Value(i)
v := Uint64Value(i * 2)

storable, err := childMap.Set(compare, hashInputProvider, k, v)
require.NoError(t, err)
require.Nil(t, storable)
}

require.False(t, nested.root.IsData())

values[i] = nested
}
expectedChildMapValues[k] = v
}

typeInfo := testTypeInfo{42}
require.False(t, childMap.root.IsData())

array, err := NewArray(storage, address, typeInfo)
require.NoError(t, err)
for _, a := range values {
err := array.Append(a)
err = array.Append(childMap)
require.NoError(t, err)

expectedValues[i] = expectedChildMapValues
}

verifyArray(t, storage, typeInfo, address, array, values, true)
verifyArray(t, storage, typeInfo, address, array, expectedValues, true)
})
}

Expand Down
Loading

0 comments on commit 00a6df8

Please sign in to comment.