arnaucube
arnaucube/arboPublic Self-hosted repository
Add missing emptyHash in Snapshot Tree
arnaucube root@arnaucube.com
Thu, 09 Sep 2021 11:42:41 +0200
commit

64c8f8d0bc3e145fd2f89d0a74a49c0bb9c6cff0

parent

de5914f453cf28e35c707f7b093bbb46fda0eab5

2 files changed, 22 insertions(+), 0 deletions(-)

jump to
M tree.go → tree.go

@@ -860,6 +860,7 @@ return &Tree{

db: t.db, maxLevels: t.maxLevels, snapshotRoot: fromRoot, + emptyHash: t.emptyHash, hashFunction: t.hashFunction, dbg: t.dbg, }, nil
M tree_test.go → tree_test.go

@@ -563,6 +563,27 @@ checkRootBIString(c, tree,

"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