use of org.ethereum.core.TransactionPoolAddResult in project rskj by rsksmart.
the class EthModuleTest method sendTransactionWithGasLimitTest.
@Test
public void sendTransactionWithGasLimitTest() {
Constants constants = Constants.regtest();
Wallet wallet = new Wallet(new HashMapDB());
RskAddress sender = wallet.addAccount();
RskAddress receiver = wallet.addAccount();
// Hash of the expected transaction
CallArguments args = TransactionFactoryHelper.createArguments(sender, receiver);
Transaction tx = TransactionFactoryHelper.createTransaction(args, constants.getChainId(), wallet.getAccount(sender));
String txExpectedResult = tx.getHash().toJsonString();
TransactionPoolAddResult transactionPoolAddResult = mock(TransactionPoolAddResult.class);
when(transactionPoolAddResult.transactionsWereAdded()).thenReturn(true);
TransactionGateway transactionGateway = mock(TransactionGateway.class);
when(transactionGateway.receiveTransaction(any(Transaction.class))).thenReturn(transactionPoolAddResult);
TransactionPool transactionPool = mock(TransactionPool.class);
EthModuleTransactionBase ethModuleTransaction = new EthModuleTransactionBase(constants, wallet, transactionPool, transactionGateway);
// Hash of the actual transaction builded inside the sendTransaction
String txResult = ethModuleTransaction.sendTransaction(args);
assertEquals(txExpectedResult, txResult);
}
use of org.ethereum.core.TransactionPoolAddResult in project rskj by rsksmart.
the class PersonalModuleTest method sendTransactionWithGasLimitTest.
@Test
public void sendTransactionWithGasLimitTest() throws Exception {
TestSystemProperties props = new TestSystemProperties();
Wallet wallet = new Wallet(new HashMapDB());
RskAddress sender = wallet.addAccount(PASS_FRASE);
RskAddress receiver = wallet.addAccount();
// Hash of the expected transaction
CallArguments args = TransactionFactoryHelper.createArguments(sender, receiver);
Transaction tx = TransactionFactoryHelper.createTransaction(args, props.getNetworkConstants().getChainId(), wallet.getAccount(sender, PASS_FRASE));
String txExpectedResult = tx.getHash().toJsonString();
TransactionPoolAddResult transactionPoolAddResult = mock(TransactionPoolAddResult.class);
when(transactionPoolAddResult.transactionsWereAdded()).thenReturn(true);
Ethereum ethereum = mock(Ethereum.class);
PersonalModuleWalletEnabled personalModuleWalletEnabled = new PersonalModuleWalletEnabled(props, ethereum, wallet, null);
// Hash of the actual transaction builded inside the sendTransaction
String txResult = personalModuleWalletEnabled.sendTransaction(args, PASS_FRASE);
assertEquals(txExpectedResult, txResult);
}
use of org.ethereum.core.TransactionPoolAddResult in project rskj by rsksmart.
the class EthModuleTransactionBase method sendTransaction.
@Override
public synchronized String sendTransaction(CallArguments args) {
Account senderAccount = this.wallet.getAccount(new RskAddress(args.getFrom()));
if (senderAccount == null) {
throw RskJsonRpcRequestException.invalidParamError(TransactionArgumentsUtil.ERR_COULD_NOT_FIND_ACCOUNT + args.getFrom());
}
String txHash = null;
try {
synchronized (transactionPool) {
TransactionArguments txArgs = TransactionArgumentsUtil.processArguments(args, transactionPool, senderAccount, constants.getChainId());
Transaction tx = Transaction.builder().withTransactionArguments(txArgs).build();
tx.sign(senderAccount.getEcKey().getPrivKeyBytes());
if (!tx.acceptTransactionSignature(constants.getChainId())) {
throw RskJsonRpcRequestException.invalidParamError(TransactionArgumentsUtil.ERR_INVALID_CHAIN_ID + args.getChainId());
}
TransactionPoolAddResult result = transactionGateway.receiveTransaction(tx.toImmutableTransaction());
if (!result.transactionsWereAdded()) {
throw RskJsonRpcRequestException.transactionError(result.getErrorMessage());
}
txHash = tx.getHash().toJsonString();
}
return txHash;
} finally {
LOGGER.debug("eth_sendTransaction({}): {}", args, txHash);
}
}
use of org.ethereum.core.TransactionPoolAddResult in project rskj by rsksmart.
the class EthModuleTransactionBase method sendRawTransaction.
@Override
public String sendRawTransaction(String rawData) {
String s = null;
try {
Transaction tx = new ImmutableTransaction(stringHexToByteArray(rawData));
if (null == tx.getGasLimit() || null == tx.getGasPrice() || null == tx.getValue()) {
throw invalidParamError("Missing parameter, gasPrice, gas or value");
}
TransactionPoolAddResult result = transactionGateway.receiveTransaction(tx);
if (!result.transactionsWereAdded()) {
throw RskJsonRpcRequestException.transactionError(result.getErrorMessage());
}
return s = tx.getHash().toJsonString();
} finally {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("eth_sendRawTransaction({}): {}", rawData, s);
}
}
}
use of org.ethereum.core.TransactionPoolAddResult in project rskj by rsksmart.
the class TransactionGatewayTest method receiveTransaction_alreadyAddedTransaction_shouldntAddAndShouldntBroadcast.
@Test
public void receiveTransaction_alreadyAddedTransaction_shouldntAddAndShouldntBroadcast() {
TransactionPoolAddResult transactionPoolAddResult = TransactionPoolAddResult.withError("Not added");
receiveTransactionAndVerifyCalls(transactionPoolAddResult, 0);
}
Aggregations