Search in sources :

Example 6 with TrieImpl

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());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 7 with TrieImpl

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());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 8 with TrieImpl

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());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 9 with TrieImpl

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;
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) Trie(co.rsk.trie.Trie)

Example 10 with TrieImpl

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;
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) RemascTransaction(co.rsk.remasc.RemascTransaction) Trie(co.rsk.trie.Trie)

Aggregations

TrieImpl (co.rsk.trie.TrieImpl)25 Trie (co.rsk.trie.Trie)22 Test (org.junit.Test)20 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)7 DataWord (org.ethereum.vm.DataWord)7 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)6 HashMapDB (org.ethereum.datasource.HashMapDB)6 TrieStore (co.rsk.trie.TrieStore)5 RskAddress (co.rsk.core.RskAddress)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 Coin (co.rsk.core.Coin)1 RemascTransaction (co.rsk.remasc.RemascTransaction)1 BigInteger (java.math.BigInteger)1 Set (java.util.Set)1 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)1 Transaction (org.ethereum.core.Transaction)1 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)1 ContractDetails (org.ethereum.db.ContractDetails)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1