Search in sources :

Example 6 with TransactionGateway

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());
    }
}
Also used : TransactionPool(org.ethereum.core.TransactionPool) RskJsonRpcRequestException(org.ethereum.rpc.exception.RskJsonRpcRequestException) Wallet(co.rsk.core.Wallet) CallArguments(org.ethereum.rpc.CallArguments) RskAddress(co.rsk.core.RskAddress) BridgeConstants(co.rsk.config.BridgeConstants) Constants(org.ethereum.config.Constants) ECKey(org.ethereum.crypto.ECKey) HashMapDB(org.ethereum.datasource.HashMapDB) TransactionGateway(co.rsk.net.TransactionGateway) Test(org.junit.Test)

Example 7 with TransactionGateway

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);
}
Also used : EthModuleTransactionBase(co.rsk.rpc.modules.eth.EthModuleTransactionBase) ChannelManager(org.ethereum.net.server.ChannelManager) RskModule(co.rsk.rpc.modules.rsk.RskModule) Web3RskImpl(co.rsk.rpc.Web3RskImpl) TxPoolModuleImpl(co.rsk.rpc.modules.txpool.TxPoolModuleImpl) DebugModuleImpl(co.rsk.rpc.modules.debug.DebugModuleImpl) PersonalModuleWalletEnabled(co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled) TransactionGateway(co.rsk.net.TransactionGateway) MiningMainchainView(co.rsk.core.bc.MiningMainchainView) EthModuleWalletEnabled(co.rsk.rpc.modules.eth.EthModuleWalletEnabled) MinerClient(co.rsk.mine.MinerClient) Web3InformationRetriever(co.rsk.rpc.Web3InformationRetriever) EthModule(co.rsk.rpc.modules.eth.EthModule) BuildInfo(org.ethereum.util.BuildInfo) DebugModule(co.rsk.rpc.modules.debug.DebugModule) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule) RskModuleImpl(co.rsk.rpc.modules.rsk.RskModuleImpl)

Example 8 with TransactionGateway

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);
}
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 9 with TransactionGateway

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

Aggregations

TransactionGateway (co.rsk.net.TransactionGateway)9 Test (org.junit.Test)8 RepositoryLocator (co.rsk.db.RepositoryLocator)6 World (co.rsk.test.World)6 BlockStore (org.ethereum.db.BlockStore)6 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)6 TrieStore (co.rsk.trie.TrieStore)5 HashMapDB (org.ethereum.datasource.HashMapDB)5 RepositorySnapshot (co.rsk.db.RepositorySnapshot)3 ReceiptStore (org.ethereum.db.ReceiptStore)3 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)3 BridgeConstants (co.rsk.config.BridgeConstants)2 RskAddress (co.rsk.core.RskAddress)2 Wallet (co.rsk.core.Wallet)2 Constants (org.ethereum.config.Constants)2 TransactionPool (org.ethereum.core.TransactionPool)2 CallArguments (org.ethereum.rpc.CallArguments)2 MiningMainchainView (co.rsk.core.bc.MiningMainchainView)1 MinerClient (co.rsk.mine.MinerClient)1 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)1