-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_proof_test.go
53 lines (43 loc) · 1.21 KB
/
validate_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
package main
import (
"fmt"
"os"
"testing"
"github.com/sircoon4/bencodex-go/bencodextype"
"github.com/sircoon4/bencodex-go/util"
)
func TestValidateProof(t *testing.T) {
proofInfos := parseProofInfos()
fmt.Println("Test case count:", len(proofInfos))
for i, proofInfo := range proofInfos {
fmt.Println("Test case", i+1)
proofInfoDict := proofInfo.(*bencodextype.Dictionary)
// stateRootHash, proof, key, value
stateRootHash := proofInfoDict.Get("stateRootHash").([]byte)
proof := anyArrayToBytesArray(proofInfoDict.Get("proof").([]any))
key := proofInfoDict.Get("key").([]byte)
value := proofInfoDict.Get("value").([]byte)
_, err := ValidateProof(stateRootHash, proof, key, value)
if err != nil {
t.Error(err)
}
}
}
func parseProofInfos() []any {
proofInfosJsonData, err := os.ReadFile("./libplanet-block-proofs-11188814.repr.json")
if err != nil {
panic(err)
}
proofInfosBencodex, err := util.UnmarshalJsonRepr(proofInfosJsonData)
if err != nil {
panic(err)
}
return proofInfosBencodex.([]any)
}
func anyArrayToBytesArray(anyArray []any) [][]byte {
bytesArray := make([][]byte, len(anyArray))
for i, any := range anyArray {
bytesArray[i] = any.([]byte)
}
return bytesArray
}