Skip to content

Commit

Permalink
Change JSON RPC Error-32602 (Invalid Params) to return with http stat…
Browse files Browse the repository at this point in the history
…us code 200 (#4967)

* Handle INVALID_PARAMS with a 200 http status code

* Change tests to expect INVALID_PARAMS with a 200 http status code

* Add change log entry

* Change test to handle jsonRPC result rather than raised exception

Signed-off-by: Gabriel Fukushima <[email protected]>
  • Loading branch information
gfukushima authored Jan 20, 2023
1 parent 61abde6 commit 857db71
Show file tree
Hide file tree
Showing 39 changed files with 49 additions and 51 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Breaking Changes

- Changed JsonRpc http service to return the error -32602 (Invalid params) with a 200 http status code

### Additions and Improvements
- Added option to evm CLI tool to allow code execution at specific forks [#4913](https://github.com/hyperledger/besu/pull/4913)
- Improve get account performance by using the world state updater cache [#4897](https://github.com/hyperledger/besu/pull/4897)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.hyperledger.besu.tests.acceptance.privacy;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.web3j.utils.Restriction.UNRESTRICTED;

import org.hyperledger.besu.tests.acceptance.dsl.privacy.ParameterizedEnclaveTestBase;
Expand Down Expand Up @@ -43,7 +42,6 @@
import org.web3j.protocol.core.methods.request.Transaction;
import org.web3j.protocol.core.methods.response.EthCall;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.protocol.exceptions.ClientConnectionException;
import org.web3j.protocol.http.HttpService;
import org.web3j.tx.Contract;
import org.web3j.utils.Restriction;
Expand Down Expand Up @@ -141,7 +139,7 @@ public void shouldReturnEmptyResultWithNonExistingPrivacyGroup() throws IOExcept
}

@Test
public void mustNotSucceedWithWronglyEncodedFunction() {
public void mustNotSucceedWithWronglyEncodedFunction() throws IOException {

final String privacyGroupId =
minerNode.execute(createPrivacyGroup("myGroupName", "my group description", minerNode));
Expand All @@ -162,9 +160,8 @@ public void mustNotSucceedWithWronglyEncodedFunction() {

final Request<Object, EthCall> priv_call = privCall(privacyGroupId, eventEmitter, true, false);

assertThatExceptionOfType(ClientConnectionException.class)
.isThrownBy(() -> priv_call.send())
.withMessageContaining("Invalid params");
final String errorMessage = priv_call.send().getError().getMessage();
assertThat(errorMessage).isEqualTo("Invalid params");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ private static HttpResponseStatus status(final JsonRpcResponse response) {
private static HttpResponseStatus statusCodeFromError(final JsonRpcError error) {
switch (error) {
case INVALID_REQUEST:
case INVALID_PARAMS:
case PARSE_ERROR:
return HttpResponseStatus.BAD_REQUEST;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ public void getBlockByHashWithMissingHashParameter() throws Exception {
.thenReturn(Optional.empty());

try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(400);
assertThat(resp.code()).isEqualTo(200);
// Check general format of result
final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.INVALID_PARAMS;
Expand All @@ -783,7 +783,7 @@ public void getBlockByHashWithMissingBooleanParameter() throws Exception {
JSON);

try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(400);
assertThat(resp.code()).isEqualTo(200);
// Check general format of result
final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.INVALID_PARAMS;
Expand All @@ -806,7 +806,7 @@ public void getBlockByHashWithInvalidHashParameterWithOddLength() throws Excepti
JSON);

try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(400);
assertThat(resp.code()).isEqualTo(200);
// Check general format of result
final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.INVALID_PARAMS;
Expand All @@ -829,7 +829,7 @@ public void getBlockByHashWithInvalidHashParameterThatIsTooShort() throws Except
JSON);

try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(400);
assertThat(resp.code()).isEqualTo(200);
// Check general format of result
final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.INVALID_PARAMS;
Expand All @@ -853,7 +853,7 @@ public void getBlockByHashWithInvalidBooleanParameter() throws Exception {
JSON);

try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(400);
assertThat(resp.code()).isEqualTo(200);
// Check general format of result
final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.INVALID_PARAMS;
Expand All @@ -873,7 +873,7 @@ public void getBlockByHashWithAllParametersMissing() throws Exception {
JSON);

try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(400);
assertThat(resp.code()).isEqualTo(200);
// Check general format of result
final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.INVALID_PARAMS;
Expand All @@ -893,7 +893,7 @@ public void getBlockByHashWithNoParameters() throws Exception {
JSON);

try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(400);
assertThat(resp.code()).isEqualTo(200);
// Check general format of result
final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.INVALID_PARAMS;
Expand Down Expand Up @@ -978,7 +978,7 @@ public void getBlockByNumberForInvalidBlockParameter() throws Exception {
JSON);

try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(400);
assertThat(resp.code()).isEqualTo(200);
// Check general format of result
final String respBody = resp.body().string();
final JsonObject json = new JsonObject(respBody);
Expand Down Expand Up @@ -2035,7 +2035,7 @@ public void ethGetStorageAtInvalidParameterStorageIndex() throws Exception {
JSON);

try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(400);
assertThat(resp.code()).isEqualTo(200);
// Check general format of result
final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = JsonRpcError.INVALID_PARAMS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"message":"Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"message": "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"message": "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"message": "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"message": "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"message": "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"message": "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"message": "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Loading

0 comments on commit 857db71

Please sign in to comment.