Search in sources :

Example 6 with Transaction

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

the class TxPendingValidatorTest method validGas.

@Test
public void validGas() {
    TxPendingValidator validator = new TxPendingValidator();
    Transaction tx = createTransaction(0, 1000, 0, 0, 0, 0);
    BigInteger gasLimit = BigInteger.valueOf(1000);
    Assert.assertTrue(validator.isValid(tx, gasLimit));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) Transaction(org.ethereum.core.Transaction) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 7 with Transaction

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

the class TxPendingValidatorTest method invalidGas.

@Test
public void invalidGas() {
    TxPendingValidator validator = new TxPendingValidator();
    Transaction tx = createTransaction(0, 1000, 0, 0, 0, 0);
    BigInteger gasLimit = BigInteger.valueOf(999);
    Assert.assertFalse(validator.isValid(tx, gasLimit));
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) Transaction(org.ethereum.core.Transaction) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 8 with Transaction

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

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

the class EthModuleWalletEnabled method sendTransaction.

@Override
public synchronized String sendTransaction(Web3.CallArguments args) {
    Account account = this.getAccount(args.from);
    String s = null;
    try {
        if (account == null) {
            throw new JsonRpcInvalidParamException("From address private key could not be found in this node");
        }
        String toAddress = args.to != null ? Hex.toHexString(stringHexToByteArray(args.to)) : null;
        BigInteger value = args.value != null ? TypeConverter.stringNumberAsBigInt(args.value) : BigInteger.ZERO;
        BigInteger gasPrice = args.gasPrice != null ? TypeConverter.stringNumberAsBigInt(args.gasPrice) : BigInteger.ZERO;
        BigInteger gasLimit = args.gas != null ? TypeConverter.stringNumberAsBigInt(args.gas) : BigInteger.valueOf(GasCost.TRANSACTION_DEFAULT);
        if (args.data != null && args.data.startsWith("0x")) {
            args.data = args.data.substring(2);
        }
        synchronized (transactionPool) {
            BigInteger accountNonce = args.nonce != null ? TypeConverter.stringNumberAsBigInt(args.nonce) : transactionPool.getRepository().getNonce(account.getAddress());
            Transaction tx = Transaction.create(config, toAddress, value, accountNonce, gasPrice, gasLimit, args.data);
            tx.sign(account.getEcKey().getPrivKeyBytes());
            eth.submitTransaction(tx.toImmutableTransaction());
            s = tx.getHash().toJsonString();
        }
        return s;
    } finally {
        LOGGER.debug("eth_sendTransaction({}): {}", args, s);
    }
}
Also used : Account(org.ethereum.core.Account) Transaction(org.ethereum.core.Transaction) BigInteger(java.math.BigInteger) JsonRpcInvalidParamException(org.ethereum.rpc.exception.JsonRpcInvalidParamException)

Example 10 with Transaction

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

the class TransactionsMessage method parse.

private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
    transactions = new ArrayList<>();
    for (int i = 0; i < paramsList.size(); ++i) {
        RLPList rlpTxData = (RLPList) paramsList.get(i);
        Transaction tx = new ImmutableTransaction(rlpTxData.getRLPData());
        transactions.add(tx);
    }
    parsed = true;
}
Also used : ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) RLPList(org.ethereum.util.RLPList)

Aggregations

Transaction (org.ethereum.core.Transaction)257 Test (org.junit.Test)166 Block (org.ethereum.core.Block)73 RskAddress (co.rsk.core.RskAddress)69 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)57 InternalTransaction (org.ethereum.vm.program.InternalTransaction)57 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)39 ActivationConfig (org.ethereum.config.blockchain.upgrades.ActivationConfig)39 BigInteger (java.math.BigInteger)38 ArrayList (java.util.ArrayList)38 Repository (org.ethereum.core.Repository)35 JsonNode (com.fasterxml.jackson.databind.JsonNode)32 ECKey (org.ethereum.crypto.ECKey)30 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)29 Keccak256 (co.rsk.crypto.Keccak256)28 Account (org.ethereum.core.Account)26 World (co.rsk.test.World)23 DslParser (co.rsk.test.dsl.DslParser)23 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)23 MutableRepository (org.ethereum.db.MutableRepository)22