Skip to content

Commit

Permalink
* ✅ getFromCache sometimes incorrect (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
no2chem authored Apr 1, 2019
1 parent 560bab3 commit 0903369
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rainblock/merkle-patricia-tree",
"version": "4.3.0",
"version": "4.3.1",
"description": "An implementation of the modified merkle patricia tree used in Ethereum, optimized for in-memory usage",
"main": "build/src/index.js",
"types": "build/src/index.d.js",
Expand Down
30 changes: 30 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,36 @@ describe('Try batchCOW operations', () => {
});
});

describe('test cached merkle tree', async () => {
it('should be able to deal with ethereum accounts', async () => {
const tree = new CachedMerklePatriciaTree();
const data = require('../test/initial_accounts.json') as string[];
const errorAccount =
Buffer.from('2910543af39aba0cd09dbb2d50200b3e800a63d2', 'hex');
const value = Buffer.from('value');

// Create a tree with a reasonable depth
data.forEach(s => {
if (s.length !== 64) {
s = s.padStart(64, '0');
}
tree.put(Buffer.from(s, 'hex'), value);
});

// This account should be inserted and re-read using getFromCache
tree.put(errorAccount, value);

// This should return the correct witness
const witness = tree.get(errorAccount);
should.not.equal(null, witness.value);

// And getting from cache should as well
const result = tree.getFromCache(errorAccount, new Map());
should.not.equal(null, result);
result!.should.deep.equal(value);
});
});

describe('Test getFromCache and rlpToMerkleNode', async () => {
const cache =
new CachedMerklePatriciaTree<Buffer, Buffer>({putCanDelete: false}, 1);
Expand Down
1 change: 1 addition & 0 deletions test/initial_accounts.json

Large diffs are not rendered by default.

0 comments on commit 0903369

Please sign in to comment.