From 519323f77e95cfefe71586a0a736b935c26e61ba Mon Sep 17 00:00:00 2001 From: Iryoung Jeong Date: Wed, 22 Jan 2025 07:04:42 +0900 Subject: [PATCH] Fix eth_getBlockByNumber with empty params returns (#8134) * fix testcase Signed-off-by: Iryoung Jeong * fix EthGetBlockByNumber logic to pass testcase Signed-off-by: Iryoung Jeong * fix missed testcase - JsonRpcHttpServiceTest Signed-off-by: Iryoung Jeong --------- Signed-off-by: Iryoung Jeong Co-authored-by: Matilda-Clerke --- .../jsonrpc/internal/methods/EthGetBlockByNumber.java | 2 +- .../ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java | 2 +- .../internal/methods/EthGetBlockByNumberTest.java | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java index 0a26a24ee38..761870ddd12 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumber.java @@ -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); } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java index 52f2ee050cd..f919a5cf359 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java @@ -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()); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java index fd92b55ba48..619d0a82f4b 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java @@ -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); } @@ -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); }