Search in sources :

Example 26 with Trie

use of co.rsk.trie.Trie in project rskj by rsksmart.

the class TrieImplHashTest method sonWithNoSiblingsAndOnlyOneSonShouldBringSameHashBaseCase.

@Test
public void sonWithNoSiblingsAndOnlyOneSonShouldBringSameHashBaseCase() {
    Trie trie1 = new TrieImpl().put("roose", "42".getBytes()).put("roosevalt", "4243".getBytes()).put("roosevaltroosevalt", "424344".getBytes()).delete("roosevalt");
    Trie trie2 = new TrieImpl().put("roose", "42".getBytes()).put("roosevaltroosevalt", "424344".getBytes());
    Assert.assertTrue(Arrays.equals(trie1.get("roose"), "42".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevalt"), "424344".getBytes()));
    Assert.assertNull(trie1.get("roosevalt"));
    Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 27 with Trie

use of co.rsk.trie.Trie in project rskj by rsksmart.

the class TrieImplHashTest method sonWithNoSiblingsAndOnlyOneSonShouldBringSameHashRecursionCase.

@Test
public void sonWithNoSiblingsAndOnlyOneSonShouldBringSameHashRecursionCase() {
    Trie trie1 = new TrieImpl().put("ro", "4".getBytes()).put("roose", "42".getBytes()).put("roosevalt", "4243".getBytes()).put("roosevaltroosevalt", "424344".getBytes()).delete("roosevalt");
    Trie trie2 = new TrieImpl().put("ro", "4".getBytes()).put("roose", "42".getBytes()).put("roosevaltroosevalt", "424344".getBytes());
    Assert.assertTrue(Arrays.equals(trie1.get("ro"), "4".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roose"), "42".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevalt"), "424344".getBytes()));
    Assert.assertNull(trie1.get("roosevalt"));
    Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 28 with Trie

use of co.rsk.trie.Trie in project rskj by rsksmart.

the class TrieImplHashTest method sonWithNoSiblingsAndOnlyOneSonWithSonsShouldBringSameHashBaseCase.

@Test
public void sonWithNoSiblingsAndOnlyOneSonWithSonsShouldBringSameHashBaseCase() {
    Trie trie1 = new TrieImpl().put("roose", "42".getBytes()).put("roosevalt", "4243".getBytes()).put("roosevaltroosevalt", "424344".getBytes()).put("roosevaltroosevaltroosevaltroosevalt", "42434445".getBytes()).delete("roosevalt");
    Trie trie2 = new TrieImpl().put("roose", "42".getBytes()).put("roosevaltroosevalt", "424344".getBytes()).put("roosevaltroosevaltroosevaltroosevalt", "42434445".getBytes());
    Assert.assertTrue(Arrays.equals(trie1.get("roose"), "42".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevalt"), "424344".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevaltroosevaltroosevalt"), "42434445".getBytes()));
    Assert.assertNull(trie1.get("roosevalt"));
    Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 29 with Trie

use of co.rsk.trie.Trie in project rskj by rsksmart.

the class TrieImplHashTest method sonWithNoSiblingsAndOnlyOneSonWithSonsShouldBringSameHashRecursionCase.

@Test
public void sonWithNoSiblingsAndOnlyOneSonWithSonsShouldBringSameHashRecursionCase() {
    Trie trie1 = new TrieImpl().put("ro", "4".getBytes()).put("roose", "42".getBytes()).put("roosevalt", "4243".getBytes()).put("roosevaltroosevalt", "424344".getBytes()).put("roosevaltroosevaltroosevaltroosevalt", "42434445".getBytes()).delete("roosevalt");
    Trie trie2 = new TrieImpl().put("ro", "4".getBytes()).put("roose", "42".getBytes()).put("roosevaltroosevalt", "424344".getBytes()).put("roosevaltroosevaltroosevaltroosevalt", "42434445".getBytes());
    Assert.assertTrue(Arrays.equals(trie1.get("ro"), "4".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roose"), "42".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevalt"), "424344".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevaltroosevaltroosevalt"), "42434445".getBytes()));
    Assert.assertNull(trie1.get("roosevalt"));
    Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Aggregations

Trie (co.rsk.trie.Trie)29 Test (org.junit.Test)24 TrieImpl (co.rsk.trie.TrieImpl)22 DataWord (org.ethereum.vm.DataWord)8 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)7 TrieStore (co.rsk.trie.TrieStore)4 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)4 HashMapDB (org.ethereum.datasource.HashMapDB)4 Coin (co.rsk.core.Coin)2 Keccak256 (co.rsk.crypto.Keccak256)2 BigInteger (java.math.BigInteger)2 Ignore (org.junit.Ignore)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 RskAddress (co.rsk.core.RskAddress)1 RemascTransaction (co.rsk.remasc.RemascTransaction)1 Set (java.util.Set)1 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)1 Transaction (org.ethereum.core.Transaction)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1