Search in sources :

Example 1 with HashMapDB

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

the class ReceiptStoreImplTest method getUnknownKey.

@Test
public void getUnknownKey() {
    ReceiptStore store = new ReceiptStoreImpl(new HashMapDB());
    byte[] key = new byte[] { 0x01, 0x02 };
    TransactionInfo result = store.get(key);
    Assert.assertNull(result);
}
Also used : HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 2 with HashMapDB

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

the class ReceiptStoreImplTest method addTwoTransactionsAndGetTransactionByDescendantBlocks.

@Test
public void addTwoTransactionsAndGetTransactionByDescendantBlocks() {
    World world = new World();
    Block genesis = world.getBlockChain().getBestBlock();
    Block block1a = new BlockBuilder().difficulty(10).parent(genesis).build();
    Block block1b = new BlockBuilder().difficulty(block1a.getDifficulty().asBigInteger().longValue() - 1).parent(genesis).build();
    Block block2a = new BlockBuilder().parent(block1a).build();
    Block block2b = new BlockBuilder().parent(block1b).build();
    Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1a));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, world.getBlockChain().tryToConnect(block1b));
    Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block2a));
    Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, world.getBlockChain().tryToConnect(block2b));
    ReceiptStore store = new ReceiptStoreImpl(new HashMapDB());
    TransactionReceipt receipt0 = createReceipt();
    byte[] blockHash0 = Hex.decode("010203040506070809");
    store.add(block1a.getHash().getBytes(), 3, receipt0);
    TransactionReceipt receipt = createReceipt();
    byte[] blockHash = Hex.decode("0102030405060708");
    store.add(block1b.getHash().getBytes(), 42, receipt);
    TransactionInfo result = store.get(receipt.getTransaction().getHash().getBytes(), block2a.getHash().getBytes(), world.getBlockChain().getBlockStore());
    Assert.assertNotNull(result.getBlockHash());
    Assert.assertArrayEquals(block1a.getHash().getBytes(), result.getBlockHash());
    Assert.assertEquals(3, result.getIndex());
    Assert.assertArrayEquals(receipt.getEncoded(), result.getReceipt().getEncoded());
    result = store.get(receipt.getTransaction().getHash().getBytes(), block2b.getHash().getBytes(), world.getBlockChain().getBlockStore());
    Assert.assertNotNull(result.getBlockHash());
    Assert.assertArrayEquals(block1b.getHash().getBytes(), result.getBlockHash());
    Assert.assertEquals(42, result.getIndex());
    Assert.assertArrayEquals(receipt.getEncoded(), result.getReceipt().getEncoded());
    result = store.get(receipt.getTransaction().getHash().getBytes(), genesis.getHash().getBytes(), world.getBlockChain().getBlockStore());
    Assert.assertNull(result);
}
Also used : World(co.rsk.test.World) HashMapDB(org.ethereum.datasource.HashMapDB) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 3 with HashMapDB

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

the class Web3ImplLogsTest method getWeb3WithContractInvoke.

private Web3Impl getWeb3WithContractInvoke() {
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
    Block genesis = world.getBlockByName("g00");
    Transaction tx;
    tx = getContractTransaction(acc1);
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    BlockChainImpl blockChain = world.getBlockChain();
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block1));
    byte[] contractAddress = tx.getContractAddress().getBytes();
    Transaction tx2 = getContractTransactionWithInvoke(acc1, contractAddress);
    List<Transaction> tx2s = new ArrayList<>();
    tx2s.add(tx2);
    Block block2 = new BlockBuilder(world).parent(block1).transactions(tx2s).build();
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block2));
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), receiptStore, null, null, 10, 100);
    Web3Impl web3 = createWeb3(world.getBlockChain(), transactionPool, receiptStore);
    web3.personal_newAccountWithSeed("default");
    web3.personal_newAccountWithSeed("notDefault");
    return web3;
}
Also used : ArrayList(java.util.ArrayList) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) AccountBuilder(co.rsk.test.builders.AccountBuilder) ReceiptStore(org.ethereum.db.ReceiptStore) BlockBuilder(co.rsk.test.builders.BlockBuilder)

Example 4 with HashMapDB

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

the class ImportLightTest method createBlockchain.

public static BlockChainImpl createBlockchain(Genesis genesis) {
    RskSystemProperties config = new RskSystemProperties();
    config.setBlockchainConfig(new GenesisConfig(new GenesisConfig.GenesisConstants() {

        @Override
        public BlockDifficulty getMinimumDifficulty() {
            return new BlockDifficulty(BigInteger.ONE);
        }
    }));
    IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    Repository repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB()));
    EthereumListenerAdapter listener = new EthereumListenerAdapter();
    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
    BlockChainImpl blockchain = new BlockChainImpl(config, repository, blockStore, receiptStore, null, listener, new AdminInfo(), new DummyBlockValidator());
    blockchain.setNoValidation(true);
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repository, null, receiptStore, null, listener, 10, 100);
    blockchain.setTransactionPool(transactionPool);
    Repository track = repository.startTracking();
    for (RskAddress addr : genesis.getPremine().keySet()) {
        track.createAccount(addr);
        track.addBalance(addr, genesis.getPremine().get(addr).getAccountState().getBalance());
    }
    track.commit();
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    blockchain.setBestBlock(genesis);
    blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty());
    return blockchain;
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) AdminInfo(org.ethereum.manager.AdminInfo) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) EthereumListenerAdapter(org.ethereum.listener.EthereumListenerAdapter) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) BlockDifficulty(co.rsk.core.BlockDifficulty) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) RepositoryImpl(co.rsk.db.RepositoryImpl) RskAddress(co.rsk.core.RskAddress) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) RskSystemProperties(co.rsk.config.RskSystemProperties) ReceiptStore(org.ethereum.db.ReceiptStore) GenesisConfig(org.ethereum.config.blockchain.GenesisConfig)

Example 5 with HashMapDB

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

the class DetailsDataStoreTest method test4.

@Test
public void test4() {
    DatabaseImpl db = new DatabaseImpl(new HashMapDB());
    DetailsDataStore dds = new DetailsDataStore(config, db);
    RskAddress c_key = new RskAddress("0000000000000000000000000000000000001a2b");
    ContractDetails contractDetails = dds.get(c_key);
    assertNull(contractDetails);
}
Also used : RskAddress(co.rsk.core.RskAddress) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Aggregations

HashMapDB (org.ethereum.datasource.HashMapDB)208 Test (org.junit.Test)181 World (co.rsk.test.World)45 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)34 ReceiptStore (org.ethereum.db.ReceiptStore)34 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)34 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)29 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)27 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)27 TrieStore (co.rsk.trie.TrieStore)26 HashMapBlocksIndex (co.rsk.db.HashMapBlocksIndex)23 Trie (co.rsk.trie.Trie)21 Blockchain (org.ethereum.core.Blockchain)17 RskAddress (co.rsk.core.RskAddress)16 Transaction (org.ethereum.core.Transaction)16 DslParser (co.rsk.test.dsl.DslParser)15 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12