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