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 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 CallArgumentsToByteArrayTest method getValueWhenValueIsNull.
@Test
public void getValueWhenValueIsNull() throws Exception {
CallArguments args = new CallArguments();
CallArgumentsToByteArray byteArrayArgs = new CallArgumentsToByteArray(args);
Assert.assertArrayEquals(new byte[] { 0 }, byteArrayArgs.getValue());
}
use of org.ethereum.rpc.CallArguments in project rskj by rsksmart.
the class CallArgumentsToByteArrayTest method getDataWhenValueIsEmpty.
@Test
public void getDataWhenValueIsEmpty() throws Exception {
CallArguments args = new CallArguments();
args.setData("");
CallArgumentsToByteArray byteArrayArgs = new CallArgumentsToByteArray(args);
Assert.assertNull(byteArrayArgs.getData());
}
Aggregations