+ Sample for the blog post
This commit is contained in:
romanman 2014-08-30 17:24:36 +03:00
parent 56f415ff39
commit 83d76fbeb9
2 changed files with 34 additions and 1 deletions

View File

@ -510,10 +510,17 @@ public class Trie implements TrieFacade {
public String getTrieDump(){
String root = "";
TraceAllNodes traceAction = new TraceAllNodes();
this.scanTree(this.getRootHash(), traceAction);
String root = "root: " + Hex.toHexString(getRootHash()) + "\n";
if (this.getRoot() instanceof Value){
root = "root: " + Hex.toHexString(getRootHash()) + " => " + this.getRoot() + "\n";
} else{
root = "root: " + Hex.toHexString(getRootHash()) + "\n";
}
return root + traceAction.getOutput();
}

View File

@ -784,4 +784,30 @@ public class TrieTest {
db.close();
}
@Test // update the trie with blog key/val each time dump the entire trie
public void testSample_1(){
Trie trie = new Trie(mockDb);
trie.update("dog", "puppy");
String dmp = trie.getTrieDump();
System.out.println(dmp);
System.out.println();
Assert.assertEquals("ed6e08740e4a267eca9d4740f71f573e9aabbcc739b16a2fa6c1baed5ec21278", Hex.toHexString( trie.getRootHash() ));
trie.update("do", "verb");
dmp = trie.getTrieDump();
System.out.println(dmp);
System.out.println();
Assert.assertEquals("779db3986dd4f38416bfde49750ef7b13c6ecb3e2221620bcad9267e94604d36", Hex.toHexString( trie.getRootHash() ));
trie.update("doggiestan", "aeswome_place");
dmp = trie.getTrieDump();
System.out.println(dmp);
System.out.println();
Assert.assertEquals("8bd5544747b4c44d1274aa99a6293065fe319b3230e800203317e4c75a770099", Hex.toHexString( trie.getRootHash() ));
}
}