aboutsummaryrefslogtreecommitdiffstats
path: root/merkle_test.go
blob: c486dc1a59c1588859a0ec4233752210f251b63a (plain)
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
package main

import (
	"bytes"
	"testing"
)

func testMerkle(mtype string) bool {
	m := NewMerkle(mtype, 4, "test.db")
	root := m.Build()
	id := m.Size() / 2
	proof := m.Proof(id)
	v := verify(id, proof)
	if !bytes.Equal(v, root) {
		return false
	}

	id = m.Size()/2 + 1
	proof = m.Proof(id)
	v = verify(id, proof)
	if !bytes.Equal(v, root) {
		return false
	}
	return true
}

func TestMerkle(t *testing.T) {
	tests := []string{"bfs", "post"}
	for _, test := range tests {
		if !testMerkle(test) {
			t.Error(test)
		}
	}
}