Search in sources :

Example 1 with TransactionGateway

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());
    }
}
Also used : BlockStore(org.ethereum.db.BlockStore) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) TransactionGateway(co.rsk.net.TransactionGateway) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) RepositoryLocator(co.rsk.db.RepositoryLocator) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 2 with TransactionGateway

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());
}
Also used : BlockStore(org.ethereum.db.BlockStore) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) TransactionGateway(co.rsk.net.TransactionGateway) TrieStore(co.rsk.trie.TrieStore) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) RepositoryLocator(co.rsk.db.RepositoryLocator) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 3 with TransactionGateway

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

Example 4 with TransactionGateway

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());
}
Also used : BlockStore(org.ethereum.db.BlockStore) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) TransactionGateway(co.rsk.net.TransactionGateway) TrieStore(co.rsk.trie.TrieStore) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) RepositoryLocator(co.rsk.db.RepositoryLocator) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 5 with TransactionGateway

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