Search in sources :

Example 16 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class TransactionPoolImplTest method getAllPendingTransactions.

@Test
public void getAllPendingTransactions() {
    BlockChainImpl blockchain = createBlockchain();
    Coin balance = Coin.valueOf(1000000);
    TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(2, balance, blockchain);
    transactionPool.processBest(blockchain.getBestBlock());
    Transaction tx1 = createSampleTransaction(1, 2, 1000, 0);
    Transaction tx2 = createSampleTransaction(1, 2, 3000, 1);
    transactionPool.addTransaction(tx1);
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx1);
    txs.add(tx2);
    transactionPool.addTransactions(txs);
    List<Transaction> alltxs = transactionPool.getPendingTransactions();
    Assert.assertNotNull(alltxs);
    Assert.assertFalse(alltxs.isEmpty());
    Assert.assertEquals(2, alltxs.size());
    Assert.assertTrue(alltxs.contains(tx1));
    Assert.assertTrue(alltxs.contains(tx2));
}
Also used : Coin(co.rsk.core.Coin) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 17 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class TransactionPoolImplTest method rejectTransactionPoolTransaction.

@Test
public void rejectTransactionPoolTransaction() {
    BlockChainImpl blockchain = createBlockchain();
    Coin balance = Coin.valueOf(1000000);
    TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(2, balance, blockchain);
    transactionPool.processBest(blockchain.getBestBlock());
    Transaction tx = createSampleTransaction(1, 2, 1000, 0);
    tx.setGasLimit(BigInteger.valueOf(3000001).toByteArray());
    Account receiver = createAccount(2);
    transactionPool.addTransaction(tx);
    Repository repository = transactionPool.getRepository();
    Assert.assertEquals(BigInteger.valueOf(1000000), repository.getBalance(receiver.getAddress()).asBigInteger());
}
Also used : Coin(co.rsk.core.Coin) Account(org.ethereum.core.Account) Repository(org.ethereum.core.Repository) Transaction(org.ethereum.core.Transaction) Test(org.junit.Test)

Example 18 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class TransactionPoolImplTest method removeObsoleteQueuedTransactionsByBlock.

@Test
public void removeObsoleteQueuedTransactionsByBlock() {
    BlockChainImpl blockchain = createBlockchain();
    Coin balance = Coin.valueOf(1000000);
    TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(2, balance, blockchain);
    transactionPool.processBest(blockchain.getBestBlock());
    Transaction tx1 = createSampleTransaction(1, 2, 1000, 1);
    Transaction tx2 = createSampleTransaction(1, 2, 3000, 2);
    transactionPool.addTransaction(tx1);
    transactionPool.addTransaction(tx2);
    Assert.assertEquals(10, transactionPool.getOutdatedThreshold());
    List<Transaction> list = transactionPool.getQueuedTransactions();
    Assert.assertNotNull(list);
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(2, list.size());
    transactionPool.removeObsoleteTransactions(1, 1, 100);
    list = transactionPool.getQueuedTransactions();
    Assert.assertNotNull(list);
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(2, list.size());
    transactionPool.removeObsoleteTransactions(20, transactionPool.getOutdatedThreshold(), 100);
    list = transactionPool.getQueuedTransactions();
    Assert.assertNotNull(list);
    Assert.assertTrue(list.isEmpty());
}
Also used : Coin(co.rsk.core.Coin) Transaction(org.ethereum.core.Transaction) Test(org.junit.Test)

Example 19 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class TransactionPoolImplTest method removeObsoleteQueuedTransactionsByTimeout.

@Test
public void removeObsoleteQueuedTransactionsByTimeout() throws InterruptedException {
    BlockChainImpl blockchain = createBlockchain();
    Coin balance = Coin.valueOf(1000000);
    TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(2, balance, blockchain);
    transactionPool.processBest(blockchain.getBestBlock());
    Transaction tx1 = createSampleTransaction(1, 2, 1000, 1);
    Transaction tx2 = createSampleTransaction(1, 2, 3000, 2);
    transactionPool.addTransaction(tx1);
    transactionPool.addTransaction(tx2);
    Assert.assertEquals(10, transactionPool.getOutdatedThreshold());
    List<Transaction> list = transactionPool.getQueuedTransactions();
    Assert.assertNotNull(list);
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(2, list.size());
    Thread.sleep(3000);
    transactionPool.removeObsoleteTransactions(1, 1, 1);
    list = transactionPool.getQueuedTransactions();
    Assert.assertNotNull(list);
    Assert.assertTrue(list.isEmpty());
}
Also used : Coin(co.rsk.core.Coin) Transaction(org.ethereum.core.Transaction) Test(org.junit.Test)

Example 20 with Coin

use of co.rsk.core.Coin in project rskj by rsksmart.

the class TransactionPoolImplTest method removeObsoletePendingTransactionsByTimeout.

@Test
public void removeObsoletePendingTransactionsByTimeout() throws InterruptedException {
    BlockChainImpl blockchain = createBlockchain();
    Coin balance = Coin.valueOf(1000000);
    TransactionPoolImpl transactionPool = createSampleNewTransactionPoolWithAccounts(2, balance, blockchain);
    transactionPool.processBest(blockchain.getBestBlock());
    Transaction tx1 = createSampleTransaction(1, 2, 1000, 0);
    Transaction tx2 = createSampleTransaction(1, 2, 3000, 1);
    transactionPool.addTransaction(tx1);
    transactionPool.addTransaction(tx2);
    Assert.assertEquals(10, transactionPool.getOutdatedThreshold());
    List<Transaction> list = transactionPool.getPendingTransactions();
    Assert.assertNotNull(list);
    Assert.assertFalse(list.isEmpty());
    Assert.assertEquals(2, list.size());
    Thread.sleep(3000);
    transactionPool.removeObsoleteTransactions(1, 1, 1);
    list = transactionPool.getPendingTransactions();
    Assert.assertNotNull(list);
    Assert.assertTrue(list.isEmpty());
}
Also used : Coin(co.rsk.core.Coin) Transaction(org.ethereum.core.Transaction) Test(org.junit.Test)

Aggregations

Coin (co.rsk.core.Coin)95 Test (org.junit.Test)46 RskAddress (co.rsk.core.RskAddress)37 BigInteger (java.math.BigInteger)32 Repository (org.ethereum.core.Repository)23 Transaction (org.ethereum.core.Transaction)23 Program (org.ethereum.vm.program.Program)12 AccountState (org.ethereum.core.AccountState)10 ArrayList (java.util.ArrayList)9 Ignore (org.junit.Ignore)9 ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)8 Account (org.ethereum.core.Account)7 BlockExecutor (co.rsk.core.bc.BlockExecutor)6 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)6 Keccak256 (co.rsk.crypto.Keccak256)5 Block (org.ethereum.core.Block)5 DataWord (org.ethereum.vm.DataWord)5 ProgramInvoke (org.ethereum.vm.program.invoke.ProgramInvoke)5 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)4 RskSystemProperties (co.rsk.config.RskSystemProperties)4