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.

51 lines
1.1 KiB

  1. package arbo
  2. import (
  3. "fmt"
  4. "math/big"
  5. "testing"
  6. "time"
  7. qt "github.com/frankban/quicktest"
  8. "github.com/iden3/go-merkletree/db/memory"
  9. )
  10. func TestAddBatchCaseA(t *testing.T) {
  11. c := qt.New(t)
  12. nLeafs := 1024
  13. tree, err := NewTree(memory.NewMemoryStorage(), 100, HashFunctionPoseidon)
  14. c.Assert(err, qt.IsNil)
  15. defer tree.db.Close()
  16. start := time.Now()
  17. for i := 0; i < nLeafs; i++ {
  18. k := BigIntToBytes(big.NewInt(int64(i)))
  19. v := BigIntToBytes(big.NewInt(int64(i * 2)))
  20. if err := tree.Add(k, v); err != nil {
  21. t.Fatal(err)
  22. }
  23. }
  24. fmt.Println(time.Since(start))
  25. tree2, err := NewTree(memory.NewMemoryStorage(), 100, HashFunctionPoseidon)
  26. c.Assert(err, qt.IsNil)
  27. defer tree2.db.Close()
  28. var keys, values [][]byte
  29. for i := 0; i < nLeafs; i++ {
  30. k := BigIntToBytes(big.NewInt(int64(i)))
  31. v := BigIntToBytes(big.NewInt(int64(i * 2)))
  32. keys = append(keys, k)
  33. values = append(values, v)
  34. }
  35. start = time.Now()
  36. indexes, err := tree2.AddBatchOpt(keys, values)
  37. c.Assert(err, qt.IsNil)
  38. fmt.Println(time.Since(start))
  39. c.Check(len(indexes), qt.Equals, 0)
  40. // check that both trees roots are equal
  41. c.Check(tree2.Root(), qt.DeepEquals, tree.Root())
  42. }