-
Notifications
You must be signed in to change notification settings - Fork 46
/
hasher_test.go
executable file
·74 lines (65 loc) · 1.04 KB
/
hasher_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
package ssz
import (
"fmt"
"testing"
"github.com/prysmaticlabs/gohashtree"
)
func TestDepth(t *testing.T) {
cases := []struct {
Num uint64
Res uint8
}{
{0, 0},
{1, 0},
{2, 1},
{3, 2},
{4, 2},
{5, 3},
{6, 3},
{7, 3},
{8, 3},
{9, 4},
{16, 4},
{1024, 10},
}
for _, c := range cases {
if depth := getDepth(c.Num); depth != c.Res {
t.Fatalf("num %d, expected %d but found %d", c.Num, c.Res, depth)
}
}
}
func TestNextPowerOfTwo(t *testing.T) {
cases := []struct {
Num, Res uint64
}{
{0, 0},
{1, 1},
{2, 2},
{3, 4},
{4, 4},
{5, 8},
{6, 8},
{7, 8},
{8, 8},
{9, 16},
{10, 16},
{11, 16},
{13, 16},
}
for _, c := range cases {
if next := nextPowerOfTwo(c.Num); uint64(next) != c.Res {
t.Fatalf("num %d, expected %d but found %d", c.Num, c.Res, next)
}
}
}
func TestHashGoHashTree(t *testing.T) {
a := make([]byte, 32)
b := make([]byte, 32)
a[0] = 1
b[0] = 2
buf := []byte{}
buf = append(buf, a...)
buf = append(buf, b...)
gohashtree.HashByteSlice(buf, buf)
fmt.Println(buf)
}