-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathproof_test.go
77 lines (68 loc) · 1.83 KB
/
proof_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package ics23
import (
"bytes"
"testing"
)
func TestExistenceProof(t *testing.T) {
cases := ExistenceProofTestData(t)
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
res, err := tc.Proof.Calculate()
// short-circuit with error case
if tc.IsErr {
if err == nil {
t.Fatal("Expected error, but got none")
}
} else {
if err != nil {
t.Fatal(err)
}
}
if !bytes.Equal(res, tc.Expected) {
t.Errorf("Bad result: %s vs %s", toHex(res), toHex(tc.Expected))
}
})
}
}
func TestCheckLeaf(t *testing.T) {
cases := CheckLeafTestData(t)
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
err := tc.Leaf.CheckAgainstSpec(&ProofSpec{LeafSpec: tc.Spec})
if tc.IsErr && err == nil {
t.Fatal("Expected error, but got nil")
} else if !tc.IsErr && err != nil {
t.Fatalf("Unexpected error: %v", err)
}
})
}
}
func TestCheckAgainstSpec(t *testing.T) {
cases := CheckAgainstSpecTestData(t)
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
err := tc.Proof.CheckAgainstSpec(tc.Spec)
if tc.Err == "" && err != nil {
t.Fatalf("Unexpected error: %v", err)
} else if tc.Err != "" && tc.Err != err.Error() {
t.Fatalf("Expected error: %s, got: %s", tc.Err, err.Error())
}
})
}
}
func TestEmptyBranch(t *testing.T) {
cases := EmptyBranchTestData(t)
for _, tc := range cases {
t.Run("case", func(t *testing.T) {
if err := tc.Op.CheckAgainstSpec(tc.Spec, 1); err != nil {
t.Errorf("Invalid InnerOp: %v", err)
}
if leftBranchesAreEmpty(tc.Spec.InnerSpec, tc.Op) != tc.IsLeft {
t.Errorf("Expected leftBranchesAreEmpty to be %t but it wasn't", tc.IsLeft)
}
if rightBranchesAreEmpty(tc.Spec.InnerSpec, tc.Op) != tc.IsRight {
t.Errorf("Expected rightBranchesAreEmpty to be %t but it wasn't", tc.IsRight)
}
})
}
}