Skip to content

Commit 5cdc2df

Browse files
authored
trie: fix TestBadRangeProof unit test (#21034)
1 parent c2147ee commit 5cdc2df

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎trie/proof_test.go‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,23 @@ func TestBadRangeProof(t *testing.T) {
177177
vals[index] = randBytes(20) // In theory it can't be same
178178
case 2:
179179
// Gapped entry slice
180+
181+
// There are only two elements, skip it. Dropped any element
182+
// will lead to single edge proof which is always correct.
183+
if end-start <= 2 {
184+
continue
185+
}
186+
// If the dropped element is the first or last one and it's a
187+
// batch of small size elements. In this special case, it can
188+
// happen that the proof for the edge element is exactly same
189+
// with the first/last second element(since small values are
190+
// embedded in the parent). Avoid this case.
180191
index = mrand.Intn(end - start)
181-
keys = append(keys[:index], keys[index+1:]...)
182-
vals = append(vals[:index], vals[index+1:]...)
183-
if len(keys) <= 1 {
192+
if (index == end-start-1 || index == 0) && end <= 100 {
184193
continue
185194
}
195+
keys = append(keys[:index], keys[index+1:]...)
196+
vals = append(vals[:index], vals[index+1:]...)
186197
case 3:
187198
// Switched entry slice, same effect with gapped
188199
index = mrand.Intn(end - start)

0 commit comments

Comments
 (0)