Search in sources :

Example 21 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class LogFilterTest method onlyOneEventAfterTwoBlocksWithEventAndFromLatestBlock.

@Test
public void onlyOneEventAfterTwoBlocksWithEventAndFromLatestBlock() {
    RskTestFactory factory = new RskTestFactory();
    Blockchain blockchain = factory.getBlockchain();
    BlockStore blockStore = factory.getBlockStore();
    RepositoryLocator repositoryLocator = factory.getRepositoryLocator();
    Web3ImplLogsTest.addEmptyBlockToBlockchain(blockchain, blockStore, repositoryLocator, factory.getTrieStore());
    Block block = blockchain.getBestBlock();
    AddressesTopicsFilter atfilter = new AddressesTopicsFilter(new RskAddress[0], null);
    LogFilter filter = new LogFilter(atfilter, blockchain, true, true);
    filter.newBlockReceived(block);
    filter.newBlockReceived(block);
    Object[] result = filter.getEvents();
    Assert.assertNotNull(result);
    Assert.assertEquals(1, result.length);
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) BlockStore(org.ethereum.db.BlockStore) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) RskTestFactory(org.ethereum.util.RskTestFactory) Test(org.junit.Test)

Example 22 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class LogFilterTest method eventAfterBlockWithEvent.

@Test
public void eventAfterBlockWithEvent() {
    RskTestFactory factory = new RskTestFactory();
    Blockchain blockchain = factory.getBlockchain();
    BlockStore blockStore = factory.getBlockStore();
    RepositoryLocator repositoryLocator = factory.getRepositoryLocator();
    Web3ImplLogsTest.addEmptyBlockToBlockchain(blockchain, blockStore, repositoryLocator, factory.getTrieStore());
    Block block = blockchain.getBestBlock();
    AddressesTopicsFilter atfilter = new AddressesTopicsFilter(new RskAddress[0], null);
    LogFilter filter = new LogFilter(atfilter, blockchain, false, true);
    filter.newBlockReceived(block);
    Object[] result = filter.getEvents();
    Assert.assertNotNull(result);
    Assert.assertEquals(1, result.length);
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) BlockStore(org.ethereum.db.BlockStore) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) RskTestFactory(org.ethereum.util.RskTestFactory) Test(org.junit.Test)

Example 23 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class TransactionModuleTest method testGasEstimation.

@Test
public void testGasEstimation() {
    World world = new World();
    Blockchain blockchain = world.getBlockChain();
    TrieStore trieStore = world.getTrieStore();
    RepositoryLocator repositoryLocator = world.getRepositoryLocator();
    RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
    BlockStore blockStore = world.getBlockStore();
    BlockTxSignatureCache blockTxSignatureCache = world.getBlockTxSignatureCache();
    ReceivedTxSignatureCache receivedTxSignatureCache = world.getReceivedTxSignatureCache();
    TransactionExecutorFactory transactionExecutorFactory = buildTransactionExecutionFactoryWithProgramInvokeFactory(blockStore, null, blockTxSignatureCache);
    TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, transactionExecutorFactory, receivedTxSignatureCache, 10, 100);
    TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
    Web3Impl web3 = createEnvironmentGasExactimation(blockchain, trieStore, transactionPool, blockStore, transactionGateway, transactionExecutorFactory);
    RskAddress srcAddr = new RskAddress(ECKey.fromPrivate(Keccak256Helper.keccak256("cow".getBytes())).getAddress());
    // Create the transaction that creates the destination contract
    sendContractCreationTransaction(srcAddr, web3, repository);
    // Compute contract destination address
    BigInteger nonce = repository.getAccountState(srcAddr).getNonce();
    RskAddress contractAddress = new RskAddress(HashUtil.calcNewAddr(srcAddr.getBytes(), nonce.toByteArray()));
    // start with 5M
    int gasLimit = 5000000;
    int consumed = checkEstimateGas(callCallWithValue, 33472, gasLimit, srcAddr, contractAddress, web3, repository);
    // Now that I know the estimation, call again using the estimated value
    // it should not fail. We set the gasLimit to the expected value plus 1 to
    // differentiate between OOG and success.
    int consumed2 = checkEstimateGas(callCallWithValue, 33472, consumed + 1, srcAddr, contractAddress, web3, repository);
    Assert.assertEquals(consumed, consumed2);
    consumed = checkEstimateGas(callUnfill, 46942, gasLimit, srcAddr, contractAddress, web3, repository);
    consumed2 = checkEstimateGas(callUnfill, 46942, consumed + 1, srcAddr, contractAddress, web3, repository);
    Assert.assertEquals(consumed, consumed2);
}
Also used : BlockStore(org.ethereum.db.BlockStore) World(co.rsk.test.World) TransactionGateway(co.rsk.net.TransactionGateway) TrieStore(co.rsk.trie.TrieStore) RepositoryLocator(co.rsk.db.RepositoryLocator) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) RepositorySnapshot(co.rsk.db.RepositorySnapshot) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 24 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class TransactionModuleTest method sendTransactionMustNotBeMined.

@Test
public void sendTransactionMustNotBeMined() {
    World world = new World();
    BlockChainImpl blockchain = world.getBlockChain();
    TrieStore trieStore = world.getTrieStore();
    RepositoryLocator repositoryLocator = world.getRepositoryLocator();
    RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
    BlockStore blockStore = world.getBlockStore();
    TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, buildTransactionExecutorFactory(blockStore, null, world.getBlockTxSignatureCache()), world.getReceivedTxSignatureCache(), 10, 100);
    TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
    Web3Impl web3 = createEnvironment(blockchain, null, trieStore, transactionPool, blockStore, false, world.getBlockTxSignatureCache(), transactionGateway);
    String tx = sendTransaction(web3, repository);
    Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
    Transaction txInBlock = getTransactionFromBlockWhichWasSend(blockchain, tx);
    // Transaction tx must not be in block
    Assert.assertNull(txInBlock);
}
Also used : BlockStore(org.ethereum.db.BlockStore) World(co.rsk.test.World) TransactionGateway(co.rsk.net.TransactionGateway) TrieStore(co.rsk.trie.TrieStore) RepositoryLocator(co.rsk.db.RepositoryLocator) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) RepositorySnapshot(co.rsk.db.RepositorySnapshot) Test(org.junit.Test)

Example 25 with RepositoryLocator

use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.

the class ImportLightTest method createBlockchain.

public static BlockChainImpl createBlockchain(Genesis genesis, TestSystemProperties config, Repository repository, BlockStore blockStore, TrieStore trieStore) {
    BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
    CompositeEthereumListener listener = new TestCompositeEthereumListener();
    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
    ReceivedTxSignatureCache receivedTxSignatureCache = new ReceivedTxSignatureCache();
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(receivedTxSignatureCache);
    TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, blockStore, receiptStore, blockFactory, new ProgramInvokeFactoryImpl(), null, blockTxSignatureCache);
    StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    RepositoryLocator repositoryLocator = new RepositoryLocator(trieStore, stateRootHandler);
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repositoryLocator, null, blockFactory, listener, transactionExecutorFactory, receivedTxSignatureCache, 10, 100);
    BlockChainImpl blockchain = new BlockChainImpl(blockStore, receiptStore, transactionPool, listener, new DummyBlockValidator(), new BlockExecutor(config.getActivationConfig(), repositoryLocator, transactionExecutorFactory), stateRootHandler);
    blockchain.setNoValidation(true);
    Repository track = repository.startTracking();
    for (Map.Entry<RskAddress, AccountState> accountsEntry : genesis.getAccounts().entrySet()) {
        RskAddress accountAddress = accountsEntry.getKey();
        track.createAccount(accountAddress);
        track.addBalance(accountAddress, accountsEntry.getValue().getBalance());
    }
    track.commit();
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    blockchain.setStatus(genesis, genesis.getCumulativeDifficulty());
    return blockchain;
}
Also used : StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryLocator(co.rsk.db.RepositoryLocator) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) TestCompositeEthereumListener(org.ethereum.listener.TestCompositeEthereumListener) TestCompositeEthereumListener(org.ethereum.listener.TestCompositeEthereumListener) RskAddress(co.rsk.core.RskAddress) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) Map(java.util.Map) ReceiptStore(org.ethereum.db.ReceiptStore)

Aggregations

RepositoryLocator (co.rsk.db.RepositoryLocator)38 Test (org.junit.Test)25 BlockStore (org.ethereum.db.BlockStore)21 RepositorySnapshot (co.rsk.db.RepositorySnapshot)18 BlockExecutor (co.rsk.core.bc.BlockExecutor)15 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)14 HashMapDB (org.ethereum.datasource.HashMapDB)10 TestSystemProperties (co.rsk.config.TestSystemProperties)9 Coin (co.rsk.core.Coin)7 World (co.rsk.test.World)7 RskAddress (co.rsk.core.RskAddress)6 StateRootHandler (co.rsk.db.StateRootHandler)6 TransactionGateway (co.rsk.net.TransactionGateway)6 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)6 TrieStore (co.rsk.trie.TrieStore)6 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)6 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)6 RskSystemProperties (co.rsk.config.RskSystemProperties)5 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)5 StateRootsStoreImpl (co.rsk.db.StateRootsStoreImpl)5