Skip to content

merkledb -- remove unneeded codec test helper #1943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions x/merkledb/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"bytes"
"io"
"math/rand"
"reflect"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -61,54 +60,6 @@ func newRandomProofNode(r *rand.Rand) ProofNode {
}
}

func nilEmptySlices(dest interface{}) {
if dest == nil {
return
}

destPtr := reflect.ValueOf(dest)
if destPtr.Kind() != reflect.Ptr {
return
}
nilEmptySlicesRec(destPtr.Elem())
}

func nilEmptySlicesRec(value reflect.Value) {
switch value.Kind() {
case reflect.Slice:
if value.Len() == 0 {
newValue := reflect.Zero(value.Type())
value.Set(newValue)
return
}

for i := 0; i < value.Len(); i++ {
f := value.Index(i)
nilEmptySlicesRec(f)
}
case reflect.Array:
for i := 0; i < value.Len(); i++ {
f := value.Index(i)
nilEmptySlicesRec(f)
}
case reflect.Interface, reflect.Ptr:
if value.IsNil() {
return
}
nilEmptySlicesRec(value.Elem())
case reflect.Struct:
t := value.Type()
numFields := value.NumField()
for i := 0; i < numFields; i++ {
tField := t.Field(i)
if tField.IsExported() {
field := value.Field(i)
nilEmptySlicesRec(field)
}
}
}
}

func FuzzCodecBool(f *testing.F) {
f.Fuzz(
func(
Expand Down Expand Up @@ -236,8 +187,6 @@ func FuzzCodecDBNodeDeterministic(f *testing.F) {
// we will later decode it as nil.
// Doing this prevents inconsistency when comparing the
// encoded and decoded values below.
// Calling nilEmptySlices doesn't set this because it is a
// private variable on the struct
valueBytes = nil
}
value = maybe.Some(valueBytes)
Expand Down Expand Up @@ -267,9 +216,6 @@ func FuzzCodecDBNodeDeterministic(f *testing.F) {

var gotNode dbNode
require.NoError(codec.decodeDBNode(nodeBytes, &gotNode))

nilEmptySlices(&node)
nilEmptySlices(&gotNode)
require.Equal(node, gotNode)

nodeBytes2 := codec.encodeDBNode(&gotNode)
Expand Down