Skip to content

Commit

Permalink
Merge pull request #14 from vocdoni/fix/missing-emptyHash-in-snapshot…
Browse files Browse the repository at this point in the history
…tree

Add missing emptyHash in Snapshot Tree
  • Loading branch information
arnaucube authored Sep 9, 2021
2 parents de5914f + 64c8f8d commit f09b0b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ func (t *Tree) Snapshot(fromRoot []byte) (*Tree, error) {
db: t.db,
maxLevels: t.maxLevels,
snapshotRoot: fromRoot,
emptyHash: t.emptyHash,
hashFunction: t.hashFunction,
dbg: t.dbg,
}, nil
Expand Down
21 changes: 21 additions & 0 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,27 @@ func TestSnapshot(t *testing.T) {
"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) {
bLen := 32 // for both Poseidon & Sha256
// prepare inputs
Expand Down

0 comments on commit f09b0b0

Please sign in to comment.