Search in sources :

Example 96 with Transaction

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

the class TxValidatorMinimumGasPriceValidatorTest method invalidMinimumGasPrice.

@Test
public void invalidMinimumGasPrice() {
    Transaction tx1 = Mockito.mock(Transaction.class);
    Transaction tx2 = Mockito.mock(Transaction.class);
    Transaction tx3 = Mockito.mock(Transaction.class);
    Mockito.when(tx1.getGasPrice()).thenReturn(Coin.valueOf(9));
    Mockito.when(tx2.getGasPrice()).thenReturn(Coin.valueOf(0));
    Mockito.when(tx3.getGasPrice()).thenReturn(null);
    TxValidatorMinimuGasPriceValidator tvmgpv = new TxValidatorMinimuGasPriceValidator();
    Assert.assertFalse(tvmgpv.validate(tx1, null, null, Coin.valueOf(10L), Long.MAX_VALUE, false));
    Assert.assertFalse(tvmgpv.validate(tx2, null, null, Coin.valueOf(10L), Long.MAX_VALUE, false));
    Assert.assertFalse(tvmgpv.validate(tx3, null, null, Coin.valueOf(10L), Long.MAX_VALUE, false));
}
Also used : Transaction(org.ethereum.core.Transaction) Test(org.junit.Test)

Example 97 with Transaction

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

the class TxValidatorMinimumGasPriceValidatorTest method validMinimumGasPrice.

@Test
public void validMinimumGasPrice() {
    Transaction tx1 = Mockito.mock(Transaction.class);
    Transaction tx2 = Mockito.mock(Transaction.class);
    Transaction tx3 = Mockito.mock(Transaction.class);
    Mockito.when(tx1.getGasPrice()).thenReturn(Coin.valueOf(10));
    Mockito.when(tx2.getGasPrice()).thenReturn(Coin.valueOf(11));
    Mockito.when(tx3.getGasPrice()).thenReturn(Coin.valueOf(500000000));
    TxValidatorMinimuGasPriceValidator tvmgpv = new TxValidatorMinimuGasPriceValidator();
    Assert.assertTrue(tvmgpv.validate(tx1, null, null, Coin.valueOf(10L), Long.MAX_VALUE, false));
    Assert.assertTrue(tvmgpv.validate(tx2, null, null, Coin.valueOf(10L), Long.MAX_VALUE, false));
    Assert.assertTrue(tvmgpv.validate(tx3, null, null, Coin.valueOf(10L), Long.MAX_VALUE, false));
}
Also used : Transaction(org.ethereum.core.Transaction) Test(org.junit.Test)

Example 98 with Transaction

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

the class TxValidatorNonceRangeValidatorTest method nonceOutOfRange.

@Test
public void nonceOutOfRange() {
    Transaction tx1 = Mockito.mock(Transaction.class);
    Transaction tx2 = Mockito.mock(Transaction.class);
    AccountState as = Mockito.mock(AccountState.class);
    Mockito.when(tx1.getNonceAsInteger()).thenReturn(BigInteger.valueOf(0));
    Mockito.when(tx2.getNonceAsInteger()).thenReturn(BigInteger.valueOf(6));
    Mockito.when(as.getNonce()).thenReturn(BigInteger.valueOf(1));
    TxValidatorNonceRangeValidator tvnrv = new TxValidatorNonceRangeValidator();
    Assert.assertFalse(tvnrv.validate(tx1, as, null, null, Long.MAX_VALUE, false));
    Assert.assertFalse(tvnrv.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 99 with Transaction

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

the class TxValidatorNonceRangeValidatorTest method nonceInRange.

@Test
public void nonceInRange() {
    Transaction tx1 = Mockito.mock(Transaction.class);
    Transaction tx2 = Mockito.mock(Transaction.class);
    AccountState as = Mockito.mock(AccountState.class);
    Mockito.when(tx1.getNonceAsInteger()).thenReturn(BigInteger.valueOf(0));
    Mockito.when(tx2.getNonceAsInteger()).thenReturn(BigInteger.valueOf(3));
    Mockito.when(as.getNonce()).thenReturn(BigInteger.valueOf(0));
    TxValidatorNonceRangeValidator tvnrv = new TxValidatorNonceRangeValidator();
    Assert.assertTrue(tvnrv.validate(tx1, as, null, null, Long.MAX_VALUE, false));
    Assert.assertTrue(tvnrv.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 100 with Transaction

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

the class TransactionUtils method createTransaction.

public static Transaction createTransaction(byte[] privateKey, String toAddress, BigInteger value, BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit) {
    Transaction tx = Transaction.create(new RskSystemProperties(), toAddress, value, nonce, gasPrice, gasLimit);
    tx.sign(privateKey);
    return tx;
}
Also used : Transaction(org.ethereum.core.Transaction) RskSystemProperties(co.rsk.config.RskSystemProperties)

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