@Test
public void testRollbackTrie() throws URISyntaxException, IOException {
TrieImpl trieSingle = new TrieImpl(mockDb);
URL massiveUpload_1 = ClassLoader
.getSystemResource("trie/massive-upload.dmp");
File file = new File(massiveUpload_1.toURI());
List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
List<byte[]> roots = new ArrayList<>();
Map<String, String> trieDumps = new HashMap<>();
for (int i = 0; i < 100; ++i){
String[] keyVal= strData.get(i).split("=");
if (keyVal[0].equals("*"))
trieSingle.delete(keyVal[1].trim());
else
trieSingle.update(keyVal[0].trim(), keyVal[1].trim());
byte[] hash = trieSingle.getRootHash();
roots.add(hash);
String key = Hex.toHexString(hash);
String dump = trieSingle.getTrieDump();
trieDumps.put(key, dump);
}
// compare all 100 rollback dumps and
// the originaly saved dumps
for (int i = 1; i < roots.size(); ++i){
byte[] root = roots.get(i);
logger.info("rollback over root : {}", Hex.toHexString(root) );
trieSingle.setRoot(root);
String currDump = trieSingle.getTrieDump();
String originDump = trieDumps.get(Hex.toHexString(root));
// System.out.println(currDump);
Assert.assertEquals(currDump, originDump);
}