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));
}
}
}
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++;
}
}
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;
}
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;
}
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;
}
Aggregations