Skip to content

Commit c1c8012

Browse files
committed
tree_test
1 parent ededf79 commit c1c8012

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

testonly/tree_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package testonly
1717
import (
1818
"bytes"
1919
"fmt"
20+
"math/bits"
2021
"math/rand/v2"
2122
"strconv"
2223
"testing"
@@ -111,6 +112,36 @@ func TestTreeInclusionProof(t *testing.T) {
111112
}
112113
}
113114

115+
func TestTreeSubtreeInclusionProof(t *testing.T) {
116+
test := func(desc string, entries [][]byte) {
117+
t.Run(desc, func(t *testing.T) {
118+
mt := newTree(entries)
119+
end := uint64(len(entries))
120+
for start := range end + 1 {
121+
for index := start; index < end; index++ {
122+
if bc := uint64(1) << bits.Len64(end-start-1); start%bc != 0 {
123+
continue
124+
}
125+
got, err := mt.SubtreeInclusionProof(index, start, end)
126+
if err != nil {
127+
t.Fatalf("SubtreeInclusionProof(%d, %d, %d): %v", index, start, end, err)
128+
}
129+
want := refInclusionProof(entries[start:end], index-start, mt.hasher)
130+
if diff := cmp.Diff(got, want, cmpopts.EquateEmpty()); diff != "" {
131+
t.Fatalf("SubtreeInclusionProof(%d, %d, %d): diff (-got +want)\n%s", index, start, end, diff)
132+
}
133+
}
134+
}
135+
})
136+
}
137+
138+
test("generated", genEntries(256))
139+
entries := LeafInputs()
140+
for end := range len(entries) {
141+
test(fmt.Sprintf("golden:%d", end), entries[:end])
142+
}
143+
}
144+
114145
func TestTreeConsistencyProof(t *testing.T) {
115146
entries := LeafInputs()
116147
mt := newTree(entries)

0 commit comments

Comments
 (0)