Search in sources :

Example 6 with TrieImpl

use of org.aion.mcf.trie.TrieImpl in project aion by aionnetwork.

the class TrieTestWithRootHashValues method testDeleteShortString1.

@Test
public void testDeleteShortString1() {
    String ROOT_HASH_BEFORE = "a9539c810cc2e8fa20785bdd78ec36cc1dab4b41f0d531e80a5e5fd25c3037ee";
    String ROOT_HASH_AFTER = "fc5120b4a711bca1f5bb54769525b11b3fb9a8d6ac0b8bf08cbb248770521758";
    TrieImpl trie = new TrieImpl(mockDb);
    trie.update(cat, dog);
    assertEquals(dog, new String(trie.get(cat)));
    trie.update(ca, dude);
    assertEquals(dude, new String(trie.get(ca)));
    assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash()));
    trie.delete(ca);
    assertEquals("", new String(trie.get(ca)));
    assertEquals(ROOT_HASH_AFTER, Hex.toHexString(trie.getRootHash()));
}
Also used : TrieImpl(org.aion.mcf.trie.TrieImpl) Test(org.junit.Test)

Example 7 with TrieImpl

use of org.aion.mcf.trie.TrieImpl in project aion by aionnetwork.

the class TrieTestWithRootHashValues method testDogs.

@Test
public void testDogs() {
    TrieImpl trie = new TrieImpl(null);
    trie.update("doe", "reindeer");
    assertEquals("11a0327cfcc5b7689b6b6d727e1f5f8846c1137caaa9fc871ba31b7cce1b703e", Hex.toHexString(trie.getRootHash()));
    trie.update("dog", "puppy");
    assertEquals("05ae693aac2107336a79309e0c60b24a7aac6aa3edecaef593921500d33c63c4", Hex.toHexString(trie.getRootHash()));
    trie.update("dogglesworth", "cat");
    assertEquals("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3", Hex.toHexString(trie.getRootHash()));
}
Also used : TrieImpl(org.aion.mcf.trie.TrieImpl) Test(org.junit.Test)

Example 8 with TrieImpl

use of org.aion.mcf.trie.TrieImpl in project aion by aionnetwork.

the class TrieTestWithRootHashValues method testDeleteShortString2.

@Test
public void testDeleteShortString2() {
    String ROOT_HASH_BEFORE = "a9539c810cc2e8fa20785bdd78ec36cc1dab4b41f0d531e80a5e5fd25c3037ee";
    String ROOT_HASH_AFTER = "b25e1b5be78dbadf6c4e817c6d170bbb47e9916f8f6cc4607c5f3819ce98497b";
    TrieImpl trie = new TrieImpl(mockDb);
    trie.update(ca, dude);
    assertEquals(dude, new String(trie.get(ca)));
    trie.update(cat, dog);
    assertEquals(dog, new String(trie.get(cat)));
    assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash()));
    trie.delete(cat);
    assertEquals("", new String(trie.get(cat)));
    assertEquals(ROOT_HASH_AFTER, Hex.toHexString(trie.getRootHash()));
}
Also used : TrieImpl(org.aion.mcf.trie.TrieImpl) Test(org.junit.Test)

Example 9 with TrieImpl

use of org.aion.mcf.trie.TrieImpl in project aion by aionnetwork.

the class TrieTestWithRootHashValues method testEmptyValues.

@Test
public void testEmptyValues() {
    TrieImpl trie = new TrieImpl(null);
    trie.update("do", "verb");
    trie.update("ether", "wookiedoo");
    trie.update("horse", "stallion");
    trie.update("shaman", "horse");
    trie.update("doge", "coin");
    trie.update("ether", "");
    trie.update("dog", "puppy");
    trie.update("shaman", "");
    assertEquals("5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84", Hex.toHexString(trie.getRootHash()));
}
Also used : TrieImpl(org.aion.mcf.trie.TrieImpl) Test(org.junit.Test)

Example 10 with TrieImpl

use of org.aion.mcf.trie.TrieImpl in project aion by aionnetwork.

the class TrieTestWithRootHashValues method testSmallValues.

@Test
public void testSmallValues() {
    TrieImpl trie = new TrieImpl(null);
    trie.update("be", "e");
    trie.update("dog", "puppy");
    trie.update("bed", "d");
    assertEquals("3f67c7a47520f79faa29255d2d3c084a7a6df0453116ed7232ff10277a8be68b", Hex.toHexString(trie.getRootHash()));
}
Also used : TrieImpl(org.aion.mcf.trie.TrieImpl) Test(org.junit.Test)

Aggregations

TrieImpl (org.aion.mcf.trie.TrieImpl)32 Test (org.junit.Test)31 Parameters (junitparams.Parameters)5 MockDB (org.aion.db.impl.mockdb.MockDB)5 ArrayList (java.util.ArrayList)3 IByteArrayKeyValueDatabase (org.aion.base.db.IByteArrayKeyValueDatabase)3 ImportResult (org.aion.mcf.core.ImportResult)3 AionBlock (org.aion.zero.impl.types.AionBlock)3 RLPElement (org.aion.rlp.RLPElement)1 AionTransaction (org.aion.zero.types.AionTransaction)1