-
Notifications
You must be signed in to change notification settings - Fork 0
/
merkle_test.go
48 lines (40 loc) · 1004 Bytes
/
merkle_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
package merkle
import (
"crypto/sha256"
"encoding/json"
"fmt"
"testing"
)
// cert implements the Content interface provided by merkle and represents the content to bestored in the tree.
type cert struct {
ID string `json:"id"`
Name string `json:"name"`
Test string `json:"test"`
}
func (c cert) Data() []byte {
b, _ := json.Marshal(c)
return b
}
//CalculateHash hashes the value of a cert
func (c cert) CalculateHash() []byte {
hashable := c.Data()
h := sha256.New()
h.Write(hashable)
return h.Sum(nil)
}
var certs = []Content{
cert{ID: "A", Name: "Reece", Test: "1"},
cert{ID: "B", Name: "Kara", Test: "2"},
cert{ID: "C", Name: "Maxx", Test: "3"},
cert{ID: "D", Name: "Conor", Test: "4"},
}
func TestNewTree(t *testing.T) {
tree, err := NewTree(certs)
if err != nil {
t.Error("error: unexpected error: ", err)
}
tree.GenerateProofs()
fmt.Println("--------------------------")
fmt.Println(VerifyProof(tree.Leafs[1].proof))
fmt.Println("--------------------------")
}