Skip to content

Commit

Permalink
Fuzz ConsistencyProof function against reference implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
hickford committed Jul 22, 2022
1 parent ca422cf commit e900f6f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions testonly/tree_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//go:build go1.18

package testonly

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)

func FuzzConsistencyProofAgainstReferenceImplementation(f *testing.F) {
for size := 0; size <= 8; size++ {
for size2 := 0; size2 <= size; size2++ {
for size1 := 0; size1 <= size2; size1++ {
f.Add(uint64(size), uint64(size1), uint64(size2))
}
}
}
f.Fuzz(func(t *testing.T, size, size1, size2 uint64) {
t.Logf("size=%d, size1=%d, size2=%d", size, size1, size2)
if size1 > size2 || size2 > size {
return
}
entries := genEntries(size)
tree := newTree(entries)
got, err := tree.ConsistencyProof(size1, size2)
if err != nil {
t.Fatalf("ConsistencyProof: %v", err)
}
want := refConsistencyProof(entries[:size2], size2, size1, tree.hasher, true)
if diff := cmp.Diff(got, want, cmpopts.EquateEmpty()); diff != "" {
t.Errorf("ConsistencyProof: diff (-got +want)\n%s", diff)
}
})
}

0 comments on commit e900f6f

Please sign in to comment.