You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

55 lines
995 B

package arbotree
import (
"testing"
"go.vocdoni.io/dvote/censustree"
)
func TestInterface(t *testing.T) {
storage := t.TempDir()
tree := &Tree{}
err := tree.Init("test", storage)
if err != nil {
t.Fatal(err)
}
var i interface{} = tree
_, ok := i.(censustree.Tree)
if !ok {
t.Fatal("censustree interface not matched by arbotree wrapper")
}
}
func TestGenProof(t *testing.T) {
storage := t.TempDir()
tr1 := &Tree{}
err := tr1.Init("test1", storage)
if err != nil {
t.Fatal(err)
}
var keys, values [][]byte
for i := 0; i < 10; i++ {
keys = append(keys, []byte{byte(i)})
values = append(values, []byte{byte(i)})
err = tr1.Add([]byte{byte(i)}, []byte{byte(i)})
if err != nil {
t.Fatal(err)
}
}
for i := 0; i < 10; i++ {
p, err := tr1.GenProof(keys[i], values[i])
if err != nil {
t.Fatal(err)
}
v, err := tr1.CheckProof(keys[i], values[i], tr1.Root(), p)
if err != nil {
t.Fatal(err)
}
if !v {
t.Fatal("CheckProof failed")
}
}
}