use of co.rsk.net.TransactionGateway in project rskj by rsksmart.
the class TransactionModuleTest method sendSeveralTransactionsWithAutoMining.
/**
* This test send a several transactions, and should be mine 1 transaction in each block.
*/
@Test
public void sendSeveralTransactionsWithAutoMining() {
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
BlockChainImpl blockchain = world.getBlockChain();
MiningMainchainView mainchainView = new MiningMainchainViewImpl(world.getBlockStore(), 1);
RepositoryLocator repositoryLocator = world.getRepositoryLocator();
BlockStore blockStore = world.getBlockStore();
TransactionPool transactionPool = world.getTransactionPool();
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
Web3Impl web3 = createEnvironment(blockchain, mainchainView, receiptStore, transactionPool, blockStore, true, createStateRootHandler(), repositoryLocator, world.getBlockTxSignatureCache(), transactionGateway);
for (int i = 1; i < 100; i++) {
String tx = sendTransaction(web3, repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader()));
// The goal of this test is transaction testing and not block mining testing
// Hence, there is no setup for listeners and best blocks must be added manually
// to mainchain view object that is used by miner server to build new blocks.
mainchainView.addBest(blockchain.getBestBlock().getHeader());
Transaction txInBlock = getTransactionFromBlockWhichWasSend(blockchain, tx);
Assert.assertEquals(i, blockchain.getBestBlock().getNumber());
Assert.assertEquals(2, blockchain.getBestBlock().getTransactionsList().size());
Assert.assertEquals(tx, txInBlock.getHash().toJsonString());
}
}
use of co.rsk.net.TransactionGateway in project rskj by rsksmart.
the class TransactionModuleTest method sendRawTransactionWithAutoMining.
@Test
public void sendRawTransactionWithAutoMining() throws Exception {
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
BlockChainImpl blockchain = world.getBlockChain();
TrieStore trieStore = world.getTrieStore();
RepositoryLocator repositoryLocator = world.getRepositoryLocator();
BlockStore blockStore = world.getBlockStore();
TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, buildTransactionExecutorFactory(blockStore, receiptStore, world.getBlockTxSignatureCache()), world.getReceivedTxSignatureCache(), 10, 100);
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
Web3Impl web3 = createEnvironment(blockchain, receiptStore, trieStore, transactionPool, blockStore, true, world.getBlockTxSignatureCache(), transactionGateway);
String txHash = sendRawTransaction(web3);
Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
Assert.assertEquals(2, blockchain.getBestBlock().getTransactionsList().size());
Transaction txInBlock = getTransactionFromBlockWhichWasSend(blockchain, txHash);
// Transaction tx must be in the block mined.
Assert.assertEquals(txHash, txInBlock.getHash().toJsonString());
}
use of co.rsk.net.TransactionGateway in project rskj by rsksmart.
the class TransactionModuleTest method sendTransactionMustBeMined.
@Test
public void sendTransactionMustBeMined() {
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, true, world.getBlockTxSignatureCache(), transactionGateway);
String tx = sendTransaction(web3, repository);
Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
Assert.assertEquals(2, blockchain.getBestBlock().getTransactionsList().size());
Transaction txInBlock = getTransactionFromBlockWhichWasSend(blockchain, tx);
// Transaction tx must be in the block mined.
Assert.assertEquals(tx, txInBlock.getHash().toJsonString());
}
use of co.rsk.net.TransactionGateway in project rskj by rsksmart.
the class TransactionModuleTest method sendRawTransactionWithoutAutoMining.
@Test
public void sendRawTransactionWithoutAutoMining() {
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
BlockChainImpl blockchain = world.getBlockChain();
TrieStore trieStore = world.getTrieStore();
RepositoryLocator repositoryLocator = world.getRepositoryLocator();
BlockStore blockStore = world.getBlockStore();
TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, buildTransactionExecutorFactory(blockStore, receiptStore, world.getBlockTxSignatureCache()), world.getReceivedTxSignatureCache(), 10, 100);
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
Web3Impl web3 = createEnvironment(blockchain, receiptStore, trieStore, transactionPool, blockStore, false, world.getBlockTxSignatureCache(), transactionGateway);
String txHash = sendRawTransaction(web3);
Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
Assert.assertEquals(1, transactionPool.getPendingTransactions().size());
Assert.assertEquals(txHash, transactionPool.getPendingTransactions().get(0).getHash().toJsonString());
}
use of co.rsk.net.TransactionGateway in project rskj by rsksmart.
the class EthModuleTest method sendTransactionWithGasLimitTest.
@Test
public void sendTransactionWithGasLimitTest() {
Constants constants = Constants.regtest();
Wallet wallet = new Wallet(new HashMapDB());
RskAddress sender = wallet.addAccount();
RskAddress receiver = wallet.addAccount();
// Hash of the expected transaction
CallArguments args = TransactionFactoryHelper.createArguments(sender, receiver);
Transaction tx = TransactionFactoryHelper.createTransaction(args, constants.getChainId(), wallet.getAccount(sender));
String txExpectedResult = tx.getHash().toJsonString();
TransactionPoolAddResult transactionPoolAddResult = mock(TransactionPoolAddResult.class);
when(transactionPoolAddResult.transactionsWereAdded()).thenReturn(true);
TransactionGateway transactionGateway = mock(TransactionGateway.class);
when(transactionGateway.receiveTransaction(any(Transaction.class))).thenReturn(transactionPoolAddResult);
TransactionPool transactionPool = mock(TransactionPool.class);
EthModuleTransactionBase ethModuleTransaction = new EthModuleTransactionBase(constants, wallet, transactionPool, transactionGateway);
// Hash of the actual transaction builded inside the sendTransaction
String txResult = ethModuleTransaction.sendTransaction(args);
assertEquals(txExpectedResult, txResult);
}
Aggregations