Search in sources :

Example 31 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class Web3ImplTest method getUnknownTransactionReceipt.

@Test
public void getUnknownTransactionReceipt() throws Exception {
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    Web3Impl web3 = createWeb3(world, receiptStore);
    Account acc1 = new AccountBuilder().name("acc1").build();
    Account acc2 = new AccountBuilder().name("acc2").build();
    Transaction tx = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
    String hashString = tx.getHash().toHexString();
    Assert.assertNull(web3.eth_getTransactionReceipt(hashString));
}
Also used : ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) TransactionBuilder(co.rsk.test.builders.TransactionBuilder) AccountBuilder(co.rsk.test.builders.AccountBuilder) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 32 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class SecureTrieImplSaveRetrieveTest method updateSaveRetrieveAndGetOneThousandKeyValuesUsingBinaryTree.

@Test
public void updateSaveRetrieveAndGetOneThousandKeyValuesUsingBinaryTree() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new TrieImpl(store, true);
    for (int k = 0; k < 1000; k++) trie = trie.put(k + "", (k + "").getBytes());
    trie.save();
    Trie trie2 = store.retrieve(trie.getHash().getBytes());
    Assert.assertNotNull(trie2);
    Assert.assertEquals(trie.getHash(), trie2.getHash());
    for (int k = 0; k < 1000; k++) {
        String key = k + "";
        byte[] expected = trie.get(key);
        byte[] value = trie2.get(key);
        Assert.assertArrayEquals(expected, value);
    }
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 33 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class SecureTrieImplSaveRetrieveTest method updateSaveRetrieveAndGetOneThousandKeyValuesInverseOrder.

@Test
public void updateSaveRetrieveAndGetOneThousandKeyValuesInverseOrder() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new TrieImpl(store, true);
    for (int k = 1000; k > 0; k--) trie = trie.put(k + "", (k + "").getBytes());
    trie.save();
    Trie trie2 = store.retrieve(trie.getHash().getBytes());
    Assert.assertNotNull(trie2);
    Assert.assertEquals(trie.getHash(), trie2.getHash());
    for (int k = 1000; k > 0; k--) {
        String key = k + "";
        byte[] expected = trie.get(key);
        byte[] value = trie2.get(key);
        Assert.assertArrayEquals(expected, value);
    }
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 34 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class SecureTrieImplSaveRetrieveTest method updateSaveRetrieveAndGetOneThousandKeyValues.

@Test
public void updateSaveRetrieveAndGetOneThousandKeyValues() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new TrieImpl(store, true);
    for (int k = 0; k < 1000; k++) trie = trie.put(k + "", (k + "").getBytes());
    trie.save();
    Trie trie2 = store.retrieve(trie.getHash().getBytes());
    Assert.assertNotNull(trie2);
    Assert.assertEquals(trie.getHash(), trie2.getHash());
    for (int k = 0; k < 1000; k++) {
        String key = k + "";
        byte[] expected = trie.get(key);
        byte[] value = trie2.get(key);
        Assert.assertArrayEquals(expected, value);
    }
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 35 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class SecureTrieImplStoreTest method saveFullTrieTwice.

@Test
public void saveFullTrieTwice() {
    HashMapDB map = new HashMapDB();
    TrieStoreImpl store = new TrieStoreImpl(map);
    Trie trie = new TrieImpl(store, true).put("foo", "bar".getBytes());
    trie.save();
    Assert.assertEquals(trie.trieSize(), store.getSaveCount());
    trie.save();
    Assert.assertEquals(trie.trieSize(), store.getSaveCount());
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Aggregations

HashMapDB (org.ethereum.datasource.HashMapDB)141 Test (org.junit.Test)130 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)28 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)23 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)22 SimpleBlock (co.rsk.peg.simples.SimpleBlock)18 ArrayList (java.util.ArrayList)18 RepositoryImpl (co.rsk.db.RepositoryImpl)15 DataWord (org.ethereum.vm.DataWord)14 Repository (org.ethereum.core.Repository)12 RskAddress (co.rsk.core.RskAddress)11 TrieStore (co.rsk.trie.TrieStore)10 BlockBuilder (co.rsk.test.builders.BlockBuilder)9 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)8 ReceiptStore (org.ethereum.db.ReceiptStore)8 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)8 Keccak256 (co.rsk.crypto.Keccak256)7 World (co.rsk.test.World)7 TrieImpl (co.rsk.trie.TrieImpl)6 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)6