forked from celestiaorg/smt
-
Notifications
You must be signed in to change notification settings - Fork 3
/
proofs_test.go
42 lines (37 loc) · 1.17 KB
/
proofs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package smt
import (
"bytes"
"math/rand"
"testing"
)
func randomiseProof(proof SparseMerkleProof) SparseMerkleProof {
sideNodes := make([][]byte, len(proof.SideNodes))
for i := range sideNodes {
sideNodes[i] = make([]byte, len(proof.SideNodes[i]))
rand.Read(sideNodes[i])
}
return SparseMerkleProof{
SideNodes: sideNodes,
NonMembershipLeafData: proof.NonMembershipLeafData,
}
}
// Check that a non-compact proof is equivalent to the proof returned when it is compacted and de-compacted.
func checkCompactEquivalence(t *testing.T, proof SparseMerkleProof, base *BaseSMT) {
t.Helper()
compactedProof, err := CompactProof(proof, base)
if err != nil {
t.Fatalf("failed to compact proof: %v", err)
}
decompactedProof, err := DecompactProof(compactedProof, base)
if err != nil {
t.Fatalf("failed to decompact proof: %v", err)
}
for i, sideNode := range proof.SideNodes {
if !bytes.Equal(decompactedProof.SideNodes[i], sideNode) {
t.Fatalf("de-compacted proof does not match original proof")
}
}
if !bytes.Equal(proof.NonMembershipLeafData, decompactedProof.NonMembershipLeafData) {
t.Fatalf("de-compacted proof does not match original proof")
}
}