mirror of
https://github.com/arnaucube/arbo.git
synced 2026-01-09 07:21:28 +01:00
Add missing emptyHash in Snapshot Tree
This commit is contained in:
1
tree.go
1
tree.go
@@ -860,6 +860,7 @@ func (t *Tree) Snapshot(fromRoot []byte) (*Tree, error) {
|
|||||||
db: t.db,
|
db: t.db,
|
||||||
maxLevels: t.maxLevels,
|
maxLevels: t.maxLevels,
|
||||||
snapshotRoot: fromRoot,
|
snapshotRoot: fromRoot,
|
||||||
|
emptyHash: t.emptyHash,
|
||||||
hashFunction: t.hashFunction,
|
hashFunction: t.hashFunction,
|
||||||
dbg: t.dbg,
|
dbg: t.dbg,
|
||||||
}, nil
|
}, nil
|
||||||
|
|||||||
21
tree_test.go
21
tree_test.go
@@ -563,6 +563,27 @@ func TestSnapshot(t *testing.T) {
|
|||||||
"1025190963769001718196479367844646783678188389989148142691917685159698888868")
|
"1025190963769001718196479367844646783678188389989148142691917685159698888868")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetFromSnapshotExpectArboErrKeyNotFound(t *testing.T) {
|
||||||
|
c := qt.New(t)
|
||||||
|
|
||||||
|
database, err := badgerdb.New(badgerdb.Options{Path: c.TempDir()})
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
tree, err := NewTree(database, 100, HashFunctionPoseidon)
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
defer tree.db.Close() //nolint:errcheck
|
||||||
|
|
||||||
|
bLen := tree.HashFunction().Len()
|
||||||
|
k := BigIntToBytes(bLen, big.NewInt(int64(3)))
|
||||||
|
|
||||||
|
root, err := tree.Root()
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
tree, err = tree.Snapshot(root)
|
||||||
|
c.Assert(err, qt.IsNil)
|
||||||
|
|
||||||
|
_, _, err = tree.Get(k)
|
||||||
|
c.Assert(err, qt.Equals, ErrKeyNotFound) // and not equal to db.ErrKeyNotFound
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkAdd(b *testing.B) {
|
func BenchmarkAdd(b *testing.B) {
|
||||||
bLen := 32 // for both Poseidon & Sha256
|
bLen := 32 // for both Poseidon & Sha256
|
||||||
// prepare inputs
|
// prepare inputs
|
||||||
|
|||||||
Reference in New Issue
Block a user