Search in sources :

Example 91 with Transaction

use of org.ethereum.core.Transaction 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)

Example 92 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class TxValidatorAccountBalanceValidatorTest method balanceIsNotValidatedIfFreeTx.

@Test
public void balanceIsNotValidatedIfFreeTx() {
    Transaction tx = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ONE.toByteArray(), BigInteger.valueOf(21071).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), Hex.decode("0001"), new RskSystemProperties().getBlockchainConfig().getCommonConstants().getChainId());
    tx.sign(new ECKey().getPrivKeyBytes());
    TxValidatorAccountBalanceValidator tv = new TxValidatorAccountBalanceValidator();
    Assert.assertTrue(tv.validate(tx, new AccountState(), BigInteger.ONE, Coin.valueOf(1L), Long.MAX_VALUE, true));
}
Also used : Transaction(org.ethereum.core.Transaction) ECKey(org.ethereum.crypto.ECKey) AccountState(org.ethereum.core.AccountState) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Example 93 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class TxValidatorAccountBalanceValidatorTest method invalidAccountBalance.

@Test
public void invalidAccountBalance() {
    Transaction tx1 = Mockito.mock(Transaction.class);
    Transaction tx2 = Mockito.mock(Transaction.class);
    AccountState as = Mockito.mock(AccountState.class);
    Mockito.when(tx1.getGasLimitAsInteger()).thenReturn(BigInteger.valueOf(1));
    Mockito.when(tx2.getGasLimitAsInteger()).thenReturn(BigInteger.valueOf(2));
    Mockito.when(tx1.getGasPrice()).thenReturn(Coin.valueOf(20));
    Mockito.when(tx2.getGasPrice()).thenReturn(Coin.valueOf(10));
    Mockito.when(as.getBalance()).thenReturn(Coin.valueOf(19));
    TxValidatorAccountBalanceValidator tvabv = new TxValidatorAccountBalanceValidator();
    Assert.assertFalse(tvabv.validate(tx1, as, null, null, Long.MAX_VALUE, false));
    Assert.assertFalse(tvabv.validate(tx2, as, null, null, Long.MAX_VALUE, false));
}
Also used : Transaction(org.ethereum.core.Transaction) AccountState(org.ethereum.core.AccountState) Test(org.junit.Test)

Example 94 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class TxValidatorGasLimitValidatorTest method validGasLimit.

@Test
public void validGasLimit() {
    Transaction tx1 = Mockito.mock(Transaction.class);
    Transaction tx2 = Mockito.mock(Transaction.class);
    Mockito.when(tx1.getGasLimitAsInteger()).thenReturn(BigInteger.valueOf(1));
    Mockito.when(tx2.getGasLimitAsInteger()).thenReturn(BigInteger.valueOf(6));
    BigInteger gl = BigInteger.valueOf(6);
    TxValidatorGasLimitValidator tvglv = new TxValidatorGasLimitValidator();
    Assert.assertTrue(tvglv.validate(tx1, null, gl, null, Long.MAX_VALUE, false));
    Assert.assertTrue(tvglv.validate(tx2, null, gl, null, Long.MAX_VALUE, false));
}
Also used : Transaction(org.ethereum.core.Transaction) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 95 with Transaction

use of org.ethereum.core.Transaction in project rskj by rsksmart.

the class TxValidatorIntrinsicGasLimitValidatorTest method validIntrinsicGasPrice.

@Test
public void validIntrinsicGasPrice() {
    Transaction tx1 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.valueOf(21000).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), null, config.getBlockchainConfig().getCommonConstants().getChainId());
    tx1.sign(new ECKey().getPrivKeyBytes());
    Transaction tx2 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.valueOf(30000).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), Hex.decode("0001"), config.getBlockchainConfig().getCommonConstants().getChainId());
    tx2.sign(new ECKey().getPrivKeyBytes());
    Transaction tx3 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.valueOf(21072).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), Hex.decode("0001"), config.getBlockchainConfig().getCommonConstants().getChainId());
    tx3.sign(new ECKey().getPrivKeyBytes());
    Transaction tx4 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), PrecompiledContracts.BRIDGE_ADDR.getBytes(), BigInteger.ZERO.toByteArray(), null, config.getBlockchainConfig().getCommonConstants().getChainId());
    BridgeRegTestConstants bridgeRegTestConstants = BridgeRegTestConstants.getInstance();
    tx4.sign(bridgeRegTestConstants.getFederatorPrivateKeys().get(0).getPrivKeyBytes());
    TxValidatorIntrinsicGasLimitValidator tvigpv = new TxValidatorIntrinsicGasLimitValidator(config);
    Assert.assertTrue(tvigpv.validate(tx1, new AccountState(), null, null, Long.MAX_VALUE, false));
    Assert.assertTrue(tvigpv.validate(tx2, new AccountState(), null, null, Long.MAX_VALUE, false));
    Assert.assertTrue(tvigpv.validate(tx3, new AccountState(), null, null, Long.MAX_VALUE, false));
    Assert.assertTrue(tvigpv.validate(tx4, new AccountState(), null, null, Long.MAX_VALUE, false));
}
Also used : BridgeRegTestConstants(co.rsk.config.BridgeRegTestConstants) Transaction(org.ethereum.core.Transaction) ECKey(org.ethereum.crypto.ECKey) AccountState(org.ethereum.core.AccountState) Test(org.junit.Test)

Aggregations

Transaction (org.ethereum.core.Transaction)131 Test (org.junit.Test)82 BigInteger (java.math.BigInteger)33 Coin (co.rsk.core.Coin)23 Account (org.ethereum.core.Account)20 ArrayList (java.util.ArrayList)17 Block (org.ethereum.core.Block)17 RskAddress (co.rsk.core.RskAddress)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Repository (org.ethereum.core.Repository)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 AccountState (org.ethereum.core.AccountState)10 RemascTransaction (co.rsk.remasc.RemascTransaction)9 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)9 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)8 ECKey (org.ethereum.crypto.ECKey)8 Keccak256 (co.rsk.crypto.Keccak256)7 AccountBuilder (co.rsk.test.builders.AccountBuilder)7 DslParser (co.rsk.test.dsl.DslParser)6 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)6