use of co.rsk.net.TransactionGateway in project rskj by rsksmart.
the class EthModuleTest method sendTransaction_invalidSenderAccount_throwsRskJsonRpcRequestException.
@Test
public void sendTransaction_invalidSenderAccount_throwsRskJsonRpcRequestException() {
// Given
Constants constants = Constants.regtest();
Wallet wallet = new Wallet(new HashMapDB());
TransactionPool transactionPoolMock = mock(TransactionPool.class);
TransactionGateway transactionGatewayMock = mock(TransactionGateway.class);
CallArguments argsMock = mock(CallArguments.class);
RskAddress addressFrom = new RskAddress(new ECKey().getAddress());
// Address not in wallet
doReturn(addressFrom.toJsonString()).when(argsMock).getFrom();
EthModuleTransactionBase ethModuleTransaction = new EthModuleTransactionBase(constants, wallet, transactionPoolMock, transactionGatewayMock);
// Then
try {
ethModuleTransaction.sendTransaction(argsMock);
fail("RskJsonRpcRequestException should be thrown");
} catch (RskJsonRpcRequestException ex) {
verify(argsMock, times(2)).getFrom();
assertEquals("Could not find account for address: " + addressFrom.toJsonString(), ex.getMessage());
}
}
use of co.rsk.net.TransactionGateway in project rskj by rsksmart.
the class Web3ImplTest method createWeb3.
private Web3Impl createWeb3(Ethereum eth, Blockchain blockchain, RepositoryLocator repositoryLocator, TransactionPool transactionPool, BlockStore blockStore, BlockProcessor nodeBlockProcessor, ConfigCapabilities configCapabilities, ReceiptStore receiptStore) {
MiningMainchainView miningMainchainViewMock = mock(MiningMainchainView.class);
ExecutionBlockRetriever executionBlockRetriever = mock(ExecutionBlockRetriever.class);
wallet = WalletFactory.createWallet();
PersonalModuleWalletEnabled personalModule = new PersonalModuleWalletEnabled(config, eth, wallet, transactionPool);
ReversibleTransactionExecutor executor = new ReversibleTransactionExecutor(repositoryLocator, buildTransactionExecutorFactory(blockStore, null));
Web3InformationRetriever retriever = new Web3InformationRetriever(transactionPool, blockchain, repositoryLocator, executionBlockRetriever);
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
EthModule ethModule = new EthModule(config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), blockchain, transactionPool, executor, new ExecutionBlockRetriever(miningMainchainViewMock, blockchain, null, null), repositoryLocator, new EthModuleWalletEnabled(wallet), new EthModuleTransactionBase(config.getNetworkConstants(), wallet, transactionPool, transactionGateway), new BridgeSupportFactory(null, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig()), config.getGasEstimationCap());
TxPoolModule txPoolModule = new TxPoolModuleImpl(transactionPool);
DebugModule debugModule = new DebugModuleImpl(null, null, Web3Mocks.getMockMessageHandler(), null);
RskModule rskModule = new RskModuleImpl(blockchain, blockStore, receiptStore, retriever);
MinerClient minerClient = new SimpleMinerClient();
ChannelManager channelManager = new SimpleChannelManager();
return new Web3RskImpl(eth, blockchain, config, minerClient, Web3Mocks.getMockMinerServer(), personalModule, ethModule, null, txPoolModule, null, debugModule, null, rskModule, channelManager, null, null, blockStore, receiptStore, null, nodeBlockProcessor, null, configCapabilities, new BuildInfo("test", "test"), null, retriever, syncProcessor);
}
use of co.rsk.net.TransactionGateway 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);
}
use of co.rsk.net.TransactionGateway 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);
}
Aggregations