Skip to content

Commit

Permalink
add testcase for in-memory merkletree
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed Oct 25, 2021
1 parent c167eb2 commit 331436b
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions test/db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MerkleTree } from "../src/merkle-tree-large";

var assert = require('assert');

async function main() {
async function testDBMerkleTree() {
const merkle_tree = new MerkleTree();

await merkle_tree.loadSnapshot("0");
Expand Down Expand Up @@ -55,4 +55,32 @@ async function main() {
await merkle_tree.closeDb();
}

main().then(() => console.log("done"))
async function testInMemoryMerkleTree() {
const merkle_tree = new MerkleTree(true);

await merkle_tree.getNode("0001").then((node) => {
assert.ok(node === undefined)
});

await merkle_tree.setNode("0001", new Field(1));
await merkle_tree.getNode("0001").then((node) => {
assert.ok(node!.v.eq(new Field(1).v))
});

// lastestSnapshot should always return string "0"
await merkle_tree.lastestSnapshot().then((node) => {
assert.equal(node, "0");
});

// should do nothing
await merkle_tree.loadSnapshot("0");
await merkle_tree.endSnapshot();
await merkle_tree.closeDb();
}

async function main() {
await testDBMerkleTree();
await testInMemoryMerkleTree();
}

main().then(() => console.log("done"))

0 comments on commit 331436b

Please sign in to comment.