-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathops_data_test.go
82 lines (74 loc) · 1.56 KB
/
ops_data_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
78
79
80
81
82
package ics23
import (
"encoding/hex"
"encoding/json"
"os"
"path/filepath"
"testing"
)
type LeafOpTestStruct struct {
Op *LeafOp
Key []byte
Value []byte
IsErr bool
Expected []byte
}
func LeafOpTestData(t *testing.T) map[string]LeafOpTestStruct {
t.Helper()
fname := filepath.Join("..", "testdata", "TestLeafOpData.json")
ffile, err := os.Open(fname)
if err != nil {
t.Fatal(err)
}
var cases map[string]LeafOpTestStruct
jsonDecoder := json.NewDecoder(ffile)
err = jsonDecoder.Decode(&cases)
if err != nil {
t.Fatal(err)
}
return cases
}
type InnerOpTestStruct struct {
Op *InnerOp
Child []byte
IsErr bool
Expected []byte
}
func InnerOpTestData(t *testing.T) map[string]InnerOpTestStruct {
t.Helper()
fname := filepath.Join("..", "testdata", "TestInnerOpData.json")
ffile, err := os.Open(fname)
if err != nil {
t.Fatal(err)
}
var cases map[string]InnerOpTestStruct
jsonDecoder := json.NewDecoder(ffile)
err = jsonDecoder.Decode(&cases)
if err != nil {
t.Fatal(err)
}
return cases
}
type DoHashTestStruct struct {
HashOp HashOp
Preimage string
ExpectedHash string
}
func DoHashTestData(t *testing.T) map[string]DoHashTestStruct {
t.Helper()
fname := filepath.Join("..", "testdata", "TestDoHashData.json")
ffile, err := os.Open(fname)
if err != nil {
t.Fatal(err)
}
var cases map[string]DoHashTestStruct
jsonDecoder := json.NewDecoder(ffile)
err = jsonDecoder.Decode(&cases)
if err != nil {
t.Fatal(err)
}
return cases
}
func toHex(data []byte) string {
return hex.EncodeToString(data)
}