Skip to content

Commit

Permalink
add test to cover short revert data
Browse files Browse the repository at this point in the history
  • Loading branch information
Vovchyk authored and jurajpiar committed May 17, 2024
1 parent 3eeeb97 commit 58fa81b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
51 changes: 51 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 @@ -204,6 +204,57 @@ void test_revertedTransaction() {
assertArrayEquals(hReturn, exception.getRevertData());
}

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

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

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,
(byte) 0,
null,
null,
executor,
retriever,
null,
null,
null,
new BridgeSupportFactory(
null, null, null, signatureCache),
config.getGasEstimationCap(),
config.getCallGasCap());

BlockIdentifierParam blockIdentifierParam = new BlockIdentifierParam("latest");

CallArgumentsParam callArgumentsParam = TransactionFactoryHelper.toCallArgumentsParam(args);

List<byte[]> hReturns = Arrays.asList(null, new byte[0], Hex.decode("08"), Hex.decode("08c3"), Hex.decode("08c379"));
for (byte[] hReturn : hReturns) {
when(executorResult.getHReturn()).thenReturn(hReturn);

RskJsonRpcRequestException exception = assertThrows(
RskJsonRpcRequestException.class,
() -> eth.call(
callArgumentsParam,
blockIdentifierParam
)
);
assertArrayEquals(hReturn, exception.getRevertData());
}
}

@Test
void sendTransactionWithGasLimitTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ void testHandleJsonNodeRequest_WithResponseLimit() throws Exception {
JsonNode request = objectMapper.readTree(FIRST_METHOD_REQUEST);
Web3Test handler = mock(Web3Test.class);
//expected response would be {"jsonrpc":"2.0","id":1,"result":"test_method_response"} with 56 bytes
ResponseSizeLimitContext limitContext = ResponseSizeLimitContext.createResponseSizeContext(55);
jsonRpcCustomServer = new JsonRpcCustomServer(handler, Web3Test.class, modules, objectMapper);
try (ResponseSizeLimitContext ignored = ResponseSizeLimitContext.createResponseSizeContext(55)) {
jsonRpcCustomServer = new JsonRpcCustomServer(handler, Web3Test.class, modules, objectMapper);

when(handler.test_first(anyString())).thenReturn(response);
when(handler.test_first(anyString())).thenReturn(response);

assertThrows(JsonRpcResponseLimitError.class, () -> jsonRpcCustomServer.handleJsonNodeRequest(request));
limitContext.close();
assertThrows(JsonRpcResponseLimitError.class, () -> jsonRpcCustomServer.handleJsonNodeRequest(request));
}
}

@Test
Expand Down

0 comments on commit 58fa81b

Please sign in to comment.