Search in sources :

Example 6 with Trie

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

the class SecureTrieImplKeyValueTest method oneKeyWhenTwoKeysHasSharedPathAndOneIsPrefixOfTheOther.

@Test
public void oneKeyWhenTwoKeysHasSharedPathAndOneIsPrefixOfTheOther() {
    byte[] zeroKey = "0".getBytes();
    byte[] oneKey = "012345678910".getBytes();
    Trie trie = new TrieImpl(true).put(zeroKey, "So, first of all, let me assert my firm belief that".getBytes()).put(oneKey, "the only thing we have to fear is... fear itself ".getBytes());
    trie = trie.delete(oneKey);
    Assert.assertTrue(Arrays.equals(trie.get(zeroKey), "So, first of all, let me assert my firm belief that".getBytes()));
    Assert.assertNull(trie.get(oneKey));
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 7 with Trie

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

the class SecureTrieImplKeyValueTest method oneKeyWhenTwoKeysHasNoSharedPath.

@Test
public void oneKeyWhenTwoKeysHasNoSharedPath() {
    byte[] zeroKey = "0".getBytes();
    byte[] oneKey = "1".getBytes();
    Trie trie = new TrieImpl(true).put(zeroKey, "So, first of all, let me assert my firm belief that".getBytes()).put(oneKey, "the only thing we have to fear is... fear itself ".getBytes());
    trie = trie.delete(zeroKey);
    Assert.assertTrue(Arrays.equals(trie.get(oneKey), "the only thing we have to fear is... fear itself ".getBytes()));
    Assert.assertNull(trie.get(zeroKey));
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 8 with Trie

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

the class TrieImplHashTest method sonWithNoSiblingsAndTwoSonsShouldBringSameHashRecursionCase.

@Test
public void sonWithNoSiblingsAndTwoSonsShouldBringSameHashRecursionCase() {
    Trie trie1 = new TrieImpl().put("ro", "4".getBytes()).put("roose", "42".getBytes()).put("roosevalt", "4243".getBytes()).put("roosevalt0oosevalt", "424344".getBytes()).put("roosevalt1oosevalt", "42434445".getBytes()).delete("roosevalt");
    Trie trie2 = new TrieImpl().put("ro", "4".getBytes()).put("roose", "42".getBytes()).put("roosevalt0oosevalt", "424344".getBytes()).put("roosevalt1oosevalt", "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("roosevalt0oosevalt"), "424344".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevalt1oosevalt"), "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 9 with Trie

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

the class TrieImplHashTest method removeOrNeverInsertShouldBringSameHash.

@Test
public void removeOrNeverInsertShouldBringSameHash() {
    Trie trie1 = new TrieImpl().put("roosevalt", "So, first of all, let me assert my firm belief that".getBytes()).put("roosevelt", "the only thing we have to fear is... fear itself ".getBytes()).put("roosevilt", "42".getBytes()).delete("roosevelt");
    Trie trie2 = new TrieImpl().put("roosevalt", "So, first of all, let me assert my firm belief that".getBytes()).put("roosevilt", "42".getBytes());
    Assert.assertTrue(Arrays.equals(trie1.get("roosevalt"), "So, first of all, let me assert my firm belief that".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevilt"), "42".getBytes()));
    Assert.assertNull(trie1.get("roosevelt"));
    Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 10 with Trie

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

the class TrieImplHashTest method sonWithNoSiblingsAndTwoSonsShouldBringSameHashBaseCase.

@Test
public void sonWithNoSiblingsAndTwoSonsShouldBringSameHashBaseCase() {
    Trie trie1 = new TrieImpl().put("roose", "42".getBytes()).put("roosevalt", "4243".getBytes()).put("roosevalt0oosevalt", "424344".getBytes()).put("roosevalt1oosevalt", "42434445".getBytes()).delete("roosevalt");
    Trie trie2 = new TrieImpl().put("roose", "42".getBytes()).put("roosevalt0oosevalt", "424344".getBytes()).put("roosevalt1oosevalt", "42434445".getBytes());
    Assert.assertTrue(Arrays.equals(trie1.get("roose"), "42".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevalt0oosevalt"), "424344".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevalt1oosevalt"), "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