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