use of org.ethereum.rpc.CallArguments in project rskj by rsksmart.
the class CallArgumentsToByteArrayTest method getGasLimitWhenValueIsEmpty.
@Test
public void getGasLimitWhenValueIsEmpty() throws Exception {
CallArguments args = new CallArguments();
args.setGas("");
CallArgumentsToByteArray byteArrayArgs = new CallArgumentsToByteArray(args);
String maxGasLimit = "0x5AF3107A4000";
byte[] expectedGasLimit = TypeConverter.stringHexToByteArray(maxGasLimit);
Assert.assertArrayEquals(expectedGasLimit, byteArrayArgs.getGasLimit());
}
use of org.ethereum.rpc.CallArguments 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.rpc.CallArguments in project rskj by rsksmart.
the class EthModuleDSLTest method testCall_getRevertReason.
@Test
public void testCall_getRevertReason() throws FileNotFoundException, DslProcessorException {
DslParser parser = DslParser.fromResource("dsl/eth_module/revert_reason.txt");
World world = new World();
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);
TransactionReceipt transactionReceipt = world.getTransactionReceiptByName("tx02");
byte[] status = transactionReceipt.getStatus();
Assert.assertNotNull(status);
Assert.assertEquals(0, status.length);
EthModule eth = EthModuleTestUtils.buildBasicEthModule(world);
final Transaction tx01 = world.getTransactionByName("tx01");
final CallArguments args = new CallArguments();
// "6252703f5ba322ec64d3ac45e56241b7d9e481ad";
args.setTo("0x" + tx01.getContractAddress().toHexString());
// call to contract with param value = 0
args.setData("0xd96a094a0000000000000000000000000000000000000000000000000000000000000000");
args.setValue("0");
args.setNonce("1");
args.setGas("10000000");
try {
eth.call(args, "0x2");
fail();
} catch (RskJsonRpcRequestException e) {
assertThat(e.getMessage(), Matchers.containsString("Negative value."));
}
// call to contract with param value = 1
args.setData("0xd96a094a0000000000000000000000000000000000000000000000000000000000000001");
final String call = eth.call(args, "0x2");
assertEquals("0x", call);
}
use of org.ethereum.rpc.CallArguments in project rskj by rsksmart.
the class EthModuleTest method callSmokeTest.
@Test
public void callSmokeTest() {
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 = TypeConverter.stringToByteArray("hello");
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 test_revertedTransaction.
@Test
public void test_revertedTransaction() {
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 = Hex.decode("08c379a000000000000000000000000000000000000000000000000000000000" + "0000002000000000000000000000000000000000000000000000000000000000" + "0000000f6465706f73697420746f6f2062696700000000000000000000000000" + "00000000");
ProgramResult executorResult = mock(ProgramResult.class);
when(executorResult.isRevert()).thenReturn(true);
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());
try {
eth.call(args, "latest");
} catch (RskJsonRpcRequestException e) {
assertThat(e.getMessage(), Matchers.containsString("deposit too big"));
}
}
Aggregations