Skip to content

Commit

Permalink
Fix eth_getBlockByNumber with empty params returns (hyperledger#8134)
Browse files Browse the repository at this point in the history
* fix testcase

Signed-off-by: Iryoung Jeong <[email protected]>

* fix EthGetBlockByNumber logic to pass testcase

Signed-off-by: Iryoung Jeong <[email protected]>

* fix missed testcase - JsonRpcHttpServiceTest

Signed-off-by: Iryoung Jeong <[email protected]>

---------

Signed-off-by: Iryoung Jeong <[email protected]>
Co-authored-by: Matilda-Clerke <[email protected]>
  • Loading branch information
iryoung and Matilda-Clerke authored Jan 21, 2025
1 parent e930c2d commit 519323f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected BlockParameter blockParameter(final JsonRpcRequestContext request) {
return request.getRequiredParameter(0, BlockParameter.class);
} catch (JsonRpcParameterException e) {
throw new InvalidJsonRpcParameters(
"Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
"Invalid block parameter (index 0)", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ public void getBlockByNumberForInvalidBlockParameter() throws Exception {
// Check general format of result
final String respBody = resp.body().string();
final JsonObject json = new JsonObject(respBody);
final RpcErrorType expectedError = RpcErrorType.INVALID_BLOCK_PARAMS;
final RpcErrorType expectedError = RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS;
testHelper.assertValidJsonRpcError(
json, id, expectedError.getCode(), expectedError.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,17 @@ public void returnsCorrectMethodName() {
@Test
public void exceptionWhenNoParamsSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams()))
.isInstanceOf(InvalidJsonRpcParameters.class);
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasFieldOrPropertyWithValue("rpcErrorType", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS);
verifyNoMoreInteractions(blockchainQueries);
}

@Test
public void exceptionWhenNoNumberSupplied() {
assertThatThrownBy(() -> method.response(requestWithParams("false")))
.isInstanceOf(InvalidJsonRpcParameters.class);
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasFieldOrPropertyWithValue("rpcErrorType", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS);

verifyNoMoreInteractions(blockchainQueries);
}

Expand All @@ -129,7 +132,8 @@ public void exceptionWhenNoBoolSupplied() {
public void exceptionWhenNumberParamInvalid() {
assertThatThrownBy(() -> method.response(requestWithParams("invalid", "true")))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessage("Invalid block parameter (index 0)");
.hasMessage("Invalid block parameter (index 0)")
.hasFieldOrPropertyWithValue("rpcErrorType", RpcErrorType.INVALID_BLOCK_NUMBER_PARAMS);
verifyNoMoreInteractions(blockchainQueries);
}

Expand Down

0 comments on commit 519323f

Please sign in to comment.