use of co.rsk.trie.TrieImpl 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.TrieImpl 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());
}
use of co.rsk.trie.TrieImpl in project rskj by rsksmart.
the class TrieImplHashTest method sonWithSiblingAndOnlyOneGrandsonShouldBringSameHashBaseCase.
@Test
public void sonWithSiblingAndOnlyOneGrandsonShouldBringSameHashBaseCase() {
Trie trie1 = new TrieImpl().put("roosevalt", "4243".getBytes()).put("rooseval_", "424344".getBytes()).put("roosevaltroosevalt", "42434445".getBytes()).delete("roosevalt");
Trie trie2 = new TrieImpl().put("rooseval_", "424344".getBytes()).put("roosevaltroosevalt", "42434445".getBytes());
Assert.assertTrue(Arrays.equals(trie1.get("rooseval_"), "424344".getBytes()));
Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevalt"), "42434445".getBytes()));
Assert.assertNull(trie1.get("roosevalt"));
Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
use of co.rsk.trie.TrieImpl in project rskj by rsksmart.
the class FreeBlock method getTxTrie.
public static Trie getTxTrie(List<Transaction> transactions) {
if (transactions == null) {
return new TrieImpl();
}
Trie txsState = new TrieImpl();
for (int i = 0; i < transactions.size(); i++) {
Transaction transaction = transactions.get(i);
txsState = txsState.put(RLP.encodeInt(i), transaction.getEncoded());
}
return txsState;
}
use of co.rsk.trie.TrieImpl in project rskj by rsksmart.
the class Block method getTxTrie.
public static Trie getTxTrie(List<Transaction> transactions) {
if (transactions == null) {
return new TrieImpl();
}
Trie txsState = new TrieImpl();
for (int i = 0; i < transactions.size(); i++) {
Transaction transaction = transactions.get(i);
txsState = txsState.put(RLP.encodeInt(i), transaction.getEncoded());
}
return txsState;
}
Aggregations