Add Tree.emptyHash & nLeafs methods

This commit is contained in:
2021-04-17 18:51:12 +02:00
parent 02b141d12e
commit 6f43980c0f
2 changed files with 126 additions and 17 deletions

View File

@@ -325,6 +325,54 @@ func TestRWMutex(t *testing.T) {
}
}
func TestSetGetNLeafs(t *testing.T) {
c := qt.New(t)
tree, err := NewTree(memory.NewMemoryStorage(), 100, HashFunctionPoseidon)
c.Assert(err, qt.IsNil)
// 0
tree.tx, err = tree.db.NewTx()
c.Assert(err, qt.IsNil)
err = tree.setNLeafs(0)
c.Assert(err, qt.IsNil)
err = tree.tx.Commit()
c.Assert(err, qt.IsNil)
n, err := tree.GetNLeafs()
c.Assert(err, qt.IsNil)
c.Assert(n, qt.Equals, uint64(0))
// 1024
tree.tx, err = tree.db.NewTx()
c.Assert(err, qt.IsNil)
err = tree.setNLeafs(1024)
c.Assert(err, qt.IsNil)
err = tree.tx.Commit()
c.Assert(err, qt.IsNil)
n, err = tree.GetNLeafs()
c.Assert(err, qt.IsNil)
c.Assert(n, qt.Equals, uint64(1024))
// 2**64 -1
tree.tx, err = tree.db.NewTx()
c.Assert(err, qt.IsNil)
err = tree.setNLeafs(18446744073709551615)
c.Assert(err, qt.IsNil)
err = tree.tx.Commit()
c.Assert(err, qt.IsNil)
n, err = tree.GetNLeafs()
c.Assert(err, qt.IsNil)
c.Assert(n, qt.Equals, uint64(18446744073709551615))
}
func BenchmarkAdd(b *testing.B) {
// prepare inputs
var ks, vs [][]byte