Skip to content

Commit

Permalink
Addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoreliovlabs committed Nov 18, 2024
1 parent d08229f commit f79732d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public String call(CallArgumentsParam argsParam, BlockIdentifierParam bnOrId) {
} else {
res = callConstant(args, block);
}
handleTransactionRevert(res);
handleTransactionRevertIfHappens(res);
hReturn = HexUtils.toUnformattedJsonHex(res.getHReturn());

return hReturn;
Expand Down Expand Up @@ -181,7 +181,7 @@ public String estimateGas(CallArgumentsParam args, @Nonnull BlockIdentifierParam
);

ProgramResult res = executor.getResult();
handleTransactionRevert(res);
handleTransactionRevertIfHappens(res);

estimation = internalEstimateGas(executor.getResult());

Expand Down Expand Up @@ -348,7 +348,7 @@ private ProgramResult callConstantWithState(CallArguments args, Block executionB
);
}

private void handleTransactionRevert(ProgramResult res) {
private void handleTransactionRevertIfHappens(ProgramResult res) {
if (res.isRevert()) {
Pair<String, byte[]> programRevert = decodeProgramRevert(res);
String revertReason = programRevert.getLeft();
Expand Down
43 changes: 43 additions & 0 deletions rskj-core/src/test/java/co/rsk/rpc/modules/eth/EthModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,49 @@ void whenExecuteEstimateGasWithDataParameter_callExecutorWithData() {
assertArrayEquals(HexUtils.strHexOrStrNumberToByteArray(args.getData()), dataCaptor.getValue());
}

@Test
void testwhenExecuteEstimateGasWithDataParameter_callExecutorWithData() {
CallArguments args = new CallArguments();
Block block = mock(Block.class);
ExecutionBlockRetriever.Result blockResult = mock(ExecutionBlockRetriever.Result.class);
when(blockResult.getBlock()).thenReturn(block);
ExecutionBlockRetriever retriever = mock(ExecutionBlockRetriever.class);
when(retriever.retrieveExecutionBlock("latest")).thenReturn(blockResult);
Blockchain blockchain = mock(Blockchain.class);

ProgramResult executorResult = mock(ProgramResult.class);
when(executorResult.isRevert()).thenReturn(true);
TransactionExecutor transactionExecutor = mock(TransactionExecutor.class);
when(transactionExecutor.getResult())
.thenReturn(executorResult);

ReversibleTransactionExecutor reversibleTransactionExecutor = mock(ReversibleTransactionExecutor.class);
when(reversibleTransactionExecutor.estimateGas(eq(block), any(), any(), any(), any(), any(), any(), any(), any()))
.thenReturn(transactionExecutor);

EthModule eth = new EthModule(
null,
Constants.REGTEST_CHAIN_ID,
blockchain,
null,
reversibleTransactionExecutor,
retriever,
mock(RepositoryLocator.class),
null,
null,
new BridgeSupportFactory(
null, null, null, signatureCache),
config.getGasEstimationCap(),
config.getCallGasCap());

CallArgumentsParam callArgumentsParam = TransactionFactoryHelper.toCallArgumentsParam(args);

RskJsonRpcRequestException exception = assertThrows(RskJsonRpcRequestException.class, () -> {
eth.estimateGas(callArgumentsParam, new BlockIdentifierParam("latest"));
});
assertThat(exception.getMessage(), Matchers.containsString("transaction reverted"));
}

@Test
void whenExecuteEstimateGasWithInputParameter_callExecutorWithInput() {
CallArguments args = new CallArguments();
Expand Down

0 comments on commit f79732d

Please sign in to comment.