use of org.ethereum.rpc.CallArguments in project rskj by rsksmart.
the class Web3RskImplTest method web3_CallArguments_toString.
@Test
public void web3_CallArguments_toString() {
CallArguments callArguments = new CallArguments();
callArguments.setFrom("0x1");
callArguments.setTo("0x2");
callArguments.setGas("21000");
callArguments.setGasLimit("21000");
callArguments.setGasPrice("100");
callArguments.setValue("1");
callArguments.setData("data");
callArguments.setNonce("0");
callArguments.setChainId("0x00");
callArguments.setType("0x00");
assertEquals("CallArguments{from='0x1', to='0x2', gas='21000', gasLimit='21000', gasPrice='100', value='1', data='data', nonce='0', chainId='0x00', type='0x00'}", callArguments.toString());
}
use of org.ethereum.rpc.CallArguments 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.rpc.CallArguments in project rskj by rsksmart.
the class EthModuleTest method callWithoutReturn.
@Test
public void callWithoutReturn() {
CallArguments args = new CallArguments();
BlockResult blockResult = mock(BlockResult.class);
Block block = mock(Block.class);
ExecutionBlockRetriever retriever = mock(ExecutionBlockRetriever.class);
when(retriever.retrieveExecutionBlock("latest")).thenReturn(blockResult);
when(blockResult.getBlock()).thenReturn(block);
byte[] hReturn = new byte[0];
ProgramResult executorResult = mock(ProgramResult.class);
when(executorResult.getHReturn()).thenReturn(hReturn);
ReversibleTransactionExecutor executor = mock(ReversibleTransactionExecutor.class);
when(executor.executeTransaction(eq(blockResult.getBlock()), any(), any(), any(), any(), any(), any(), any())).thenReturn(executorResult);
EthModule eth = new EthModule(null, anyByte(), null, null, executor, retriever, null, null, null, new BridgeSupportFactory(null, null, null), config.getGasEstimationCap());
String expectedResult = TypeConverter.toUnformattedJsonHex(hReturn);
String actualResult = eth.call(args, "latest");
assertEquals(expectedResult, actualResult);
}
use of org.ethereum.rpc.CallArguments in project rskj by rsksmart.
the class EthModuleTest method sendTransaction_invalidSenderAccount_throwsRskJsonRpcRequestException.
@Test
public void sendTransaction_invalidSenderAccount_throwsRskJsonRpcRequestException() {
// Given
Constants constants = Constants.regtest();
Wallet wallet = new Wallet(new HashMapDB());
TransactionPool transactionPoolMock = mock(TransactionPool.class);
TransactionGateway transactionGatewayMock = mock(TransactionGateway.class);
CallArguments argsMock = mock(CallArguments.class);
RskAddress addressFrom = new RskAddress(new ECKey().getAddress());
// Address not in wallet
doReturn(addressFrom.toJsonString()).when(argsMock).getFrom();
EthModuleTransactionBase ethModuleTransaction = new EthModuleTransactionBase(constants, wallet, transactionPoolMock, transactionGatewayMock);
// Then
try {
ethModuleTransaction.sendTransaction(argsMock);
fail("RskJsonRpcRequestException should be thrown");
} catch (RskJsonRpcRequestException ex) {
verify(argsMock, times(2)).getFrom();
assertEquals("Could not find account for address: " + addressFrom.toJsonString(), ex.getMessage());
}
}
use of org.ethereum.rpc.CallArguments in project rskj by rsksmart.
the class EthModuleGasEstimationDSLTest method estimateGas_nestedCallsWithValueGasRetainAndStorageRefund.
/**
* Send 1 rBTC accross three contracts, then the last contract frees a storage cell and does a CALL with value
* NOTE: each nested call retains 10000 gas to emit events
*/
@Test
public void estimateGas_nestedCallsWithValueGasRetainAndStorageRefund() throws FileNotFoundException, DslProcessorException {
World world = World.processedWorld("dsl/eth_module/estimateGas/nestedCallsWithValueAndStorageRefund.txt");
TransactionReceipt contractDeployA = world.getTransactionReceiptByName("tx01");
String contractAddressA = "0x" + contractDeployA.getTransaction().getContractAddress().toHexString();
byte[] status = contractDeployA.getStatus();
assertNotNull(status);
assertEquals(1, status.length);
assertEquals(0x01, status[0]);
assertEquals("0x6252703f5ba322ec64d3ac45e56241b7d9e481ad", contractAddressA);
TransactionReceipt contractDeployB = world.getTransactionReceiptByName("tx02");
String contractAddressB = "0x" + contractDeployB.getTransaction().getContractAddress().toHexString();
byte[] status2 = contractDeployB.getStatus();
assertNotNull(status2);
assertEquals(1, status2.length);
assertEquals(0x01, status2[0]);
assertEquals("0x56aa252dd82173789984fa164ee26ce2da9336ff", contractAddressB);
TransactionReceipt contractDeployC = world.getTransactionReceiptByName("tx03");
String contractAddressC = "0x" + contractDeployC.getTransaction().getContractAddress().toHexString();
byte[] status3 = contractDeployC.getStatus();
assertNotNull(status3);
assertEquals(1, status3.length);
assertEquals(0x01, status3[0]);
assertEquals("0x27444fbce96cb2d27b94e116d1506d7739c05862", contractAddressC);
EthModuleTestUtils.EthModuleGasEstimation eth = EthModuleTestUtils.buildBasicEthModuleForGasEstimation(world);
Block block = world.getBlockChain().getBestBlock();
// call callAddressWithValue, it should start the nested calls
final CallArguments args = new CallArguments();
args.setTo(contractAddressA);
args.setValue(TypeConverter.toQuantityJsonHex(1));
args.setNonce(TypeConverter.toQuantityJsonHex(6));
args.setGas(TypeConverter.toQuantityJsonHex(BLOCK_GAS_LIMIT));
// callAddressWithValue()
args.setData("0xfb60f709");
ProgramResult callConstant = eth.callConstant(args, block);
List<InternalTransaction> internalTransactions = callConstant.getInternalTransactions();
assertTrue(internalTransactions.stream().allMatch(i -> i.getValue().equals(Coin.valueOf(1))));
assertEquals(3, internalTransactions.size());
assertEquals(3, callConstant.getLogInfoList().size());
assertEvents(callConstant, "NestedCallWV", 2);
assertEvents(callConstant, "LastCall", 1);
assertTrue(callConstant.getMovedRemainingGasToChild());
long callConstantGasUsed = callConstant.getGasUsed();
long estimatedGas = estimateGas(eth, args);
assertTrue(eth.getEstimationResult().getDeductedRefund() > 0);
assertTrue(callConstant.getDeductedRefund() > 0);
assertEquals(callConstant.getGasUsedBeforeRefunds() / 2, callConstant.getDeductedRefund());
assertEquals(callConstantGasUsed + callConstant.getDeductedRefund(), estimatedGas);
args.setGas(TypeConverter.toQuantityJsonHex(callConstantGasUsed));
assertFalse(runWithArgumentsAndBlock(eth, args, block));
args.setGas(TypeConverter.toQuantityJsonHex(estimatedGas));
assertTrue(runWithArgumentsAndBlock(eth, args, block));
args.setGas(TypeConverter.toQuantityJsonHex(estimatedGas - 1));
assertFalse(runWithArgumentsAndBlock(eth, args, block));
}
Aggregations