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));
}
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));
}
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());
}
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());
}
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());
}
Aggregations