Search in sources :

Example 1 with TxsPerAccount

use of co.rsk.net.handler.TxsPerAccount in project rskj by rsksmart.

the class TxFilterAccumCostFilterTest method secondTxInvalidAccumGasPrice.

@Test
public void secondTxInvalidAccumGasPrice() {
    Transaction tx1 = Mockito.mock(Transaction.class);
    Transaction tx2 = Mockito.mock(Transaction.class);
    AccountState as1 = Mockito.mock(AccountState.class);
    AccountState as2 = Mockito.mock(AccountState.class);
    AccountState as3 = Mockito.mock(AccountState.class);
    TxsPerAccount tpa1 = new TxsPerAccount();
    TxsPerAccount tpa2 = new TxsPerAccount();
    Mockito.when(tx1.getGasLimit()).thenReturn(BigInteger.valueOf(1).toByteArray());
    Mockito.when(tx2.getGasLimit()).thenReturn(BigInteger.valueOf(1).toByteArray());
    Mockito.when(tx1.getGasPrice()).thenReturn(Coin.valueOf(1));
    Mockito.when(tx2.getGasPrice()).thenReturn(Coin.valueOf(1));
    Mockito.when(tx1.getValue()).thenReturn(Coin.valueOf(1));
    Mockito.when(tx2.getValue()).thenReturn(Coin.valueOf(1));
    Mockito.when(tx1.getNonce()).thenReturn(BigInteger.valueOf(0).toByteArray());
    Mockito.when(tx2.getNonce()).thenReturn(BigInteger.valueOf(1).toByteArray());
    Mockito.when(as1.getBalance()).thenReturn(Coin.valueOf(0));
    Mockito.when(as2.getBalance()).thenReturn(Coin.valueOf(1));
    Mockito.when(as3.getBalance()).thenReturn(Coin.valueOf(2));
    Mockito.when(as1.getNonce()).thenReturn(BigInteger.valueOf(0));
    Mockito.when(as2.getNonce()).thenReturn(BigInteger.valueOf(0));
    Mockito.when(as3.getNonce()).thenReturn(BigInteger.valueOf(0));
    TxFilterAccumCostFilter tfacf = new TxFilterAccumCostFilter(config);
    tpa1.setTransactions(new LinkedList<>());
    tpa1.getTransactions().add(tx1);
    tpa1.getTransactions().add(tx2);
    Assert.assertEquals(0, tfacf.filter(as1, tpa1, null).size());
    tpa1.setTransactions(new LinkedList<>());
    tpa1.getTransactions().add(tx1);
    tpa1.getTransactions().add(tx2);
    Assert.assertEquals(1, tfacf.filter(as2, tpa1, null).size());
    tpa1.setTransactions(new LinkedList<>());
    tpa1.getTransactions().add(tx1);
    tpa1.getTransactions().add(tx2);
    Assert.assertEquals(1, tfacf.filter(as3, tpa1, null).size());
    tpa2.setTransactions(new LinkedList<>());
    tpa2.getTransactions().add(tx1);
    tpa2.getTransactions().add(tx2);
    Assert.assertEquals(0, tfacf.filter(as1, tpa2, null).size());
    tpa2.setTransactions(new LinkedList<>());
    tpa2.getTransactions().add(tx1);
    tpa2.getTransactions().add(tx2);
    Assert.assertEquals(1, tfacf.filter(as2, tpa2, null).size());
    tpa2.setTransactions(new LinkedList<>());
    tpa2.getTransactions().add(tx1);
    tpa2.getTransactions().add(tx2);
    Assert.assertEquals(1, tfacf.filter(as3, tpa2, null).size());
}
Also used : Transaction(org.ethereum.core.Transaction) TxsPerAccount(co.rsk.net.handler.TxsPerAccount) AccountState(org.ethereum.core.AccountState) Test(org.junit.Test)

Example 2 with TxsPerAccount

use of co.rsk.net.handler.TxsPerAccount in project rskj by rsksmart.

the class TxFilterAccumCostFilterTest method twoTxsValidAccumGasPrice.

@Test
public void twoTxsValidAccumGasPrice() {
    Transaction tx1 = Mockito.mock(Transaction.class);
    Transaction tx2 = Mockito.mock(Transaction.class);
    AccountState as1 = Mockito.mock(AccountState.class);
    AccountState as2 = Mockito.mock(AccountState.class);
    AccountState as3 = Mockito.mock(AccountState.class);
    TxsPerAccount tpa1 = new TxsPerAccount();
    TxsPerAccount tpa2 = new TxsPerAccount();
    Mockito.when(tx1.getGasLimit()).thenReturn(BigInteger.valueOf(1).toByteArray());
    Mockito.when(tx2.getGasLimit()).thenReturn(BigInteger.valueOf(1).toByteArray());
    Mockito.when(tx1.getGasPrice()).thenReturn(Coin.valueOf(1));
    Mockito.when(tx2.getGasPrice()).thenReturn(Coin.valueOf(1));
    Mockito.when(tx1.getValue()).thenReturn(Coin.valueOf(1));
    Mockito.when(tx2.getValue()).thenReturn(Coin.valueOf(1));
    Mockito.when(tx1.getNonce()).thenReturn(BigInteger.valueOf(0).toByteArray());
    Mockito.when(tx2.getNonce()).thenReturn(BigInteger.valueOf(1).toByteArray());
    Mockito.when(as1.getBalance()).thenReturn(Coin.valueOf(1000));
    Mockito.when(as2.getBalance()).thenReturn(Coin.valueOf(4));
    Mockito.when(as3.getBalance()).thenReturn(Coin.valueOf(3));
    Mockito.when(as1.getNonce()).thenReturn(BigInteger.valueOf(0));
    Mockito.when(as2.getNonce()).thenReturn(BigInteger.valueOf(0));
    Mockito.when(as3.getNonce()).thenReturn(BigInteger.valueOf(0));
    TxFilterAccumCostFilter tfacf = new TxFilterAccumCostFilter(config);
    tpa1.setTransactions(new LinkedList<>());
    tpa1.getTransactions().add(tx1);
    tpa1.getTransactions().add(tx2);
    Assert.assertEquals(2, tfacf.filter(as1, tpa1, null).size());
    tpa1.setTransactions(new LinkedList<>());
    tpa1.getTransactions().add(tx1);
    tpa1.getTransactions().add(tx2);
    Assert.assertEquals(2, tfacf.filter(as2, tpa1, null).size());
    tpa1.setTransactions(new LinkedList<>());
    tpa1.getTransactions().add(tx1);
    tpa1.getTransactions().add(tx2);
    Assert.assertEquals(2, tfacf.filter(as3, tpa1, null).size());
    tpa2.setTransactions(new LinkedList<>());
    tpa2.getTransactions().add(tx1);
    tpa2.getTransactions().add(tx2);
    Assert.assertEquals(2, tfacf.filter(as1, tpa2, null).size());
    tpa2.setTransactions(new LinkedList<>());
    tpa2.getTransactions().add(tx1);
    tpa2.getTransactions().add(tx2);
    Assert.assertEquals(2, tfacf.filter(as2, tpa2, null).size());
    tpa2.setTransactions(new LinkedList<>());
    tpa2.getTransactions().add(tx1);
    tpa2.getTransactions().add(tx2);
    Assert.assertEquals(2, tfacf.filter(as3, tpa2, null).size());
}
Also used : Transaction(org.ethereum.core.Transaction) TxsPerAccount(co.rsk.net.handler.TxsPerAccount) AccountState(org.ethereum.core.AccountState) Test(org.junit.Test)

Aggregations

TxsPerAccount (co.rsk.net.handler.TxsPerAccount)2 AccountState (org.ethereum.core.AccountState)2 Transaction (org.ethereum.core.Transaction)2 Test (org.junit.Test)2