String testSrc = new String(testData);
JSONParser parser = new JSONParser();
JSONArray dbDumpJSONArray = (JSONArray)parser.parse(testSrc);
DatabaseImpl db = new DatabaseImpl("testState");
for (int i = 0; i < dbDumpJSONArray.size(); ++i){
JSONObject obj = (JSONObject)dbDumpJSONArray.get(i);
byte[] key = Hex.decode(obj.get("key").toString());
byte[] val = Hex.decode(obj.get("val").toString());
db.put(key, val);
}
// TEST: load trie out of this run up to block#33
byte[] rootNode = Hex.decode("bb690805d24882bc7ccae6fc0f80ac146274d5b81c6a6e9c882cd9b0a649c9c7");
TrieImpl trie = new TrieImpl(db.getDb(), rootNode);
// first key added in genesis
byte[] val1 = trie.get(Hex.decode("51ba59315b3a95761d0863b05ccc7a7f54703d99"));
AccountState accountState1 = new AccountState(val1);
assertEquals(BigInteger.valueOf(2).pow(200), accountState1.getBalance());
assertEquals("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", Hex.toHexString(accountState1.getCodeHash()));
assertEquals(BigInteger.ZERO, accountState1.getNonce());
assertEquals(null, accountState1.getStateRoot());
// last key added up to block#33
byte[] val2 = trie.get(Hex.decode("a39c2067eb45bc878818946d0f05a836b3da44fa"));
AccountState accountState2 = new AccountState(val2);
assertEquals(new BigInteger("1500000000000000000"), accountState2.getBalance());
assertEquals("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", Hex.toHexString(accountState2.getCodeHash()));
assertEquals(BigInteger.ZERO, accountState2.getNonce());
assertEquals(null, accountState2.getStateRoot());
db.close();
}