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

  1. package arbotree
  2. import (
  3. "testing"
  4. "go.vocdoni.io/dvote/censustree"
  5. )
  6. func TestInterface(t *testing.T) {
  7. storage := t.TempDir()
  8. tree := &Tree{}
  9. err := tree.Init("test", storage)
  10. if err != nil {
  11. t.Fatal(err)
  12. }
  13. var i interface{} = tree
  14. _, ok := i.(censustree.Tree)
  15. if !ok {
  16. t.Fatal("censustree interface not matched by arbotree wrapper")
  17. }
  18. }
  19. func TestGenProof(t *testing.T) {
  20. storage := t.TempDir()
  21. tr1 := &Tree{}
  22. err := tr1.Init("test1", storage)
  23. if err != nil {
  24. t.Fatal(err)
  25. }
  26. var keys, values [][]byte
  27. for i := 0; i < 10; i++ {
  28. keys = append(keys, []byte{byte(i)})
  29. values = append(values, []byte{byte(i)})
  30. err = tr1.Add([]byte{byte(i)}, []byte{byte(i)})
  31. if err != nil {
  32. t.Fatal(err)
  33. }
  34. }
  35. for i := 0; i < 10; i++ {
  36. p, err := tr1.GenProof(keys[i], values[i])
  37. if err != nil {
  38. t.Fatal(err)
  39. }
  40. v, err := tr1.CheckProof(keys[i], values[i], tr1.Root(), p)
  41. if err != nil {
  42. t.Fatal(err)
  43. }
  44. if !v {
  45. t.Fatal("CheckProof failed")
  46. }
  47. }
  48. }