Search in sources :

Example 16 with ProgramInvokeFactoryImpl

use of org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl in project rskj by rsksmart.

the class RemascStorageProviderTest method paysOnlyBlocksWithEnoughBalanceAccumulatedAfterRFS.

@Test
public void paysOnlyBlocksWithEnoughBalanceAccumulatedAfterRFS() throws IOException {
    Constants constants = spy(Constants.testnet(null));
    // we need to pass chain id check, and make believe that testnet config has same chain id as cow account
    when(constants.getChainId()).thenReturn(Constants.REGTEST_CHAIN_ID);
    when(constants.getMinimumPayableGas()).thenReturn(BigInteger.valueOf(21000L));
    RskSystemProperties config = spy(new TestSystemProperties());
    when(config.getNetworkConstants()).thenReturn(constants);
    long txValue = 10000;
    long gasLimit = 100000L;
    long gasPrice = 10L;
    long lowGasPrice = 1L;
    long minerFee = 21000;
    RskAddress coinbase = randomAddress();
    BlockChainBuilder builder = new BlockChainBuilder().setTesting(true).setGenesis(genesisBlock).setConfig(config);
    RemascTestRunner testRunner = new RemascTestRunner(builder, this.genesisBlock).txValue(txValue).minerFee(minerFee).initialHeight(13).siblingElements(new ArrayList<>()).txSigningKey(this.cowKey).gasPrice(gasPrice);
    testRunner.setFixedCoinbase(coinbase);
    testRunner.start();
    Blockchain blockchain = testRunner.getBlockChain();
    RepositoryLocator repositoryLocator = builder.getRepositoryLocator();
    List<Block> blocks = new ArrayList<>();
    blocks.add(RemascTestRunner.createBlock(genesisBlock, blockchain.getBestBlock(), PegTestUtils.createHash3(), coinbase, Collections.emptyList(), gasLimit, gasPrice, 14, txValue, cowKey, null));
    blocks.add(RemascTestRunner.createBlock(genesisBlock, blocks.get(blocks.size() - 1), PegTestUtils.createHash3(), coinbase, Collections.emptyList(), gasLimit, lowGasPrice, 15, txValue, cowKey, null));
    blocks.add(RemascTestRunner.createBlock(genesisBlock, blocks.get(blocks.size() - 1), PegTestUtils.createHash3(), coinbase, Collections.emptyList(), gasLimit, gasPrice, 16, txValue, cowKey, null));
    blocks.add(RemascTestRunner.createBlock(genesisBlock, blocks.get(blocks.size() - 1), PegTestUtils.createHash3(), coinbase, Collections.emptyList(), gasLimit, lowGasPrice, 17, txValue, cowKey, null));
    blocks.addAll(createSimpleBlocks(blocks.get(blocks.size() - 1), 10, coinbase));
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    BlockExecutor blockExecutor = new BlockExecutor(config.getActivationConfig(), repositoryLocator, new TransactionExecutorFactory(config, builder.getBlockStore(), null, new BlockFactory(config.getActivationConfig()), new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache())));
    for (Block b : blocks) {
        blockExecutor.executeAndFillAll(b, blockchain.getBestBlock().getHeader());
        Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(b));
        RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
        long blockNumber = blockchain.getBestBlock().getNumber();
        if (blockNumber == 24) {
            // before first special block
            assertEquals(Coin.valueOf(1663200L), RemascTestRunner.getAccountBalance(repository, coinbase));
        } else if (blockNumber == 25 || blockNumber == 26) {
            // after first and second special block
            assertEquals(Coin.valueOf(1829520L), RemascTestRunner.getAccountBalance(repository, coinbase));
        } else if (blockNumber == 27 || blockNumber == 28) {
            // after third and fourth special block
            assertEquals(Coin.valueOf(1999167L), RemascTestRunner.getAccountBalance(repository, coinbase));
        }
    }
}
Also used : BlockExecutor(co.rsk.core.bc.BlockExecutor) Constants(org.ethereum.config.Constants) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) RskAddress(co.rsk.core.RskAddress) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) RskSystemProperties(co.rsk.config.RskSystemProperties) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 17 with ProgramInvokeFactoryImpl

use of org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl in project rskj by rsksmart.

the class WorldDslProcessor method processBlockChainCommand.

private void processBlockChainCommand(DslCommand cmd) {
    Block parent = world.getBlockByName(cmd.getArgument(0));
    int k = 1;
    while (cmd.getArgument(k) != null) {
        String name = cmd.getArgument(k);
        int difficulty = k;
        if (name != null) {
            StringTokenizer difficultyTokenizer = new StringTokenizer(name, ":");
            name = difficultyTokenizer.nextToken();
            difficulty = difficultyTokenizer.hasMoreTokens() ? parseDifficulty(difficultyTokenizer.nextToken(), k) : k;
        }
        Block block = blockBuilder.difficulty(difficulty).parent(parent).build();
        final ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
        final TestSystemProperties config = new TestSystemProperties();
        StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
        BlockExecutor executor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(world.getTrieStore(), stateRootHandler), new TransactionExecutorFactory(config, world.getBlockStore(), null, new BlockFactory(config.getActivationConfig()), programInvokeFactory, null, world.getBlockTxSignatureCache()));
        executor.executeAndFill(block, parent.getHeader());
        world.saveBlock(name, block);
        parent = block;
        k++;
    }
}
Also used : StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) HashMapDB(org.ethereum.datasource.HashMapDB) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryLocator(co.rsk.db.RepositoryLocator) StringTokenizer(java.util.StringTokenizer) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 18 with ProgramInvokeFactoryImpl

use of org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl in project rskj by rsksmart.

the class TransactionPoolImplTest method createSampleNewTransactionPool.

private static TransactionPoolImpl createSampleNewTransactionPool(BlockChainImpl blockChain) {
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, blockChain.getRepository(), blockChain.getBlockStore(), null, new ProgramInvokeFactoryImpl(), new BlockExecutorTest.SimpleEthereumListener(), 10, 100);
    transactionPool.processBest(blockChain.getBestBlock());
    return transactionPool;
}
Also used : ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)

Example 19 with ProgramInvokeFactoryImpl

use of org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl in project rskj by rsksmart.

the class TransactionPoolImplTest method createSampleNewTransactionPoolWithAccounts.

private static TransactionPoolImpl createSampleNewTransactionPoolWithAccounts(int naccounts, Coin balance, BlockChainImpl blockChain) {
    Block best = blockChain.getStatus().getBestBlock();
    Repository repository = blockChain.getRepository();
    Repository track = repository.startTracking();
    for (int k = 1; k <= naccounts; k++) {
        Account account = createAccount(k);
        track.createAccount(account.getAddress());
        track.addBalance(account.getAddress(), balance);
    }
    track.commit();
    best.setStateRoot(repository.getRoot());
    best.flushRLP();
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, blockChain.getRepository(), blockChain.getBlockStore(), null, new ProgramInvokeFactoryImpl(), new BlockExecutorTest.SimpleEthereumListener(), 10, 100);
    blockChain.setTransactionPool(transactionPool);
    return transactionPool;
}
Also used : Account(org.ethereum.core.Account) Repository(org.ethereum.core.Repository) Block(org.ethereum.core.Block) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)

Example 20 with ProgramInvokeFactoryImpl

use of org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl in project rskj by rsksmart.

the class TransactionTest method executeTransaction.

private TransactionExecutor executeTransaction(Blockchain blockchain, Transaction tx) {
    Repository track = blockchain.getRepository().startTracking();
    TransactionExecutor executor = new TransactionExecutor(config, tx, 0, RskAddress.nullAddress(), blockchain.getRepository(), blockchain.getBlockStore(), null, new ProgramInvokeFactoryImpl(), blockchain.getBestBlock());
    executor.init();
    executor.execute();
    executor.go();
    executor.finalization();
    track.commit();
    return executor;
}
Also used : ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)

Aggregations

ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)21 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)13 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)11 BlockExecutor (co.rsk.core.bc.BlockExecutor)9 HashMapDB (org.ethereum.datasource.HashMapDB)9 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)8 TestSystemProperties (co.rsk.config.TestSystemProperties)7 RepositoryLocator (co.rsk.db.RepositoryLocator)6 StateRootHandler (co.rsk.db.StateRootHandler)5 StateRootsStoreImpl (co.rsk.db.StateRootsStoreImpl)5 RepositoryBtcBlockStoreWithCache (co.rsk.peg.RepositoryBtcBlockStoreWithCache)5 RskAddress (co.rsk.core.RskAddress)4 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)4 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)4 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)4 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)4 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)3 TestCompositeEthereumListener (org.ethereum.listener.TestCompositeEthereumListener)3 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)2 RskSystemProperties (co.rsk.config.RskSystemProperties)2