Change JSON RPC Error-32602 (Invalid Params) to return with http status 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 <gabrielfukushima@gmail.com>
pull/4971/head
Gabriel Fukushima 2 years ago committed by GitHub
parent 61abde6417
commit 857db71e8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 9
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/privacy/PrivCallAcceptanceTest.java
  3. 1
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java
  4. 18
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceTest.java
  5. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_callParamsMissing_block_8.json
  6. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_invalidBlockhash.json
  7. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_illegalRangeLessThan.json
  8. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_invalidBlockHash.json
  9. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBalance_invalidParams.json
  10. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockTransactionCountByHash_invalidParams.json
  11. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getBlockTransactionCountByNumber_invalidParams.json
  12. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_illegalRangeLessThan.json
  13. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_invalidBlockHash.json
  14. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getCode_invalidParams.json
  15. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getLogs_invalidInput.json
  16. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getNewFilter_invalidFilter.json
  17. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_illegalRangeLessThan.json
  18. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_invalidBlockHash.json
  19. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getProof_invalidParams.json
  20. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_illegalRangeLessThan.json
  21. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_invalidBlockHash.json
  22. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getStorageAt_invalidParams.json
  23. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockHashAndIndex_intOverflow.json
  24. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockHashAndIndex_missingParam_00.json
  25. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockHashAndIndex_missingParam_01.json
  26. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockHashAndIndex_missingParams.json
  27. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockHashAndIndex_wrongParamType.json
  28. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByBlockNumberAndIndex_invalidParams.json
  29. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByHash_invalidHashAndIndex.json
  30. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByHash_invalidParams.json
  31. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByHash_typeMismatch.json
  32. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_invalidBlockHash.json
  33. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_invalidBlockNumber.json
  34. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionCount_missingArgument.json
  35. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_sendRawTransaction_invalidByteValueHex.json
  36. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_sendRawTransaction_invalidRawTransaction.json
  37. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_sendRawTransaction_unsignedTransaction.json
  38. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/replay-trace-transaction/flat/trace_replayBlockTransactions_invalidBlockParam.json
  39. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/trace/specs/replay-trace-transaction/flat/trace_replayBlockTransactions_invalidTraceOptions.json

@ -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)

@ -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;
@ -43,7 +42,6 @@ import org.web3j.protocol.core.Request;
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;
@ -141,7 +139,7 @@ public class PrivCallAcceptanceTest extends ParameterizedEnclaveTestBase {
}
@Test
public void mustNotSucceedWithWronglyEncodedFunction() {
public void mustNotSucceedWithWronglyEncodedFunction() throws IOException {
final String privacyGroupId =
minerNode.execute(createPrivacyGroup("myGroupName", "my group description", minerNode));
@ -162,9 +160,8 @@ public class PrivCallAcceptanceTest extends ParameterizedEnclaveTestBase {
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

@ -177,7 +177,6 @@ public class JsonRpcExecutorHandler {
private static HttpResponseStatus statusCodeFromError(final JsonRpcError error) {
switch (error) {
case INVALID_REQUEST:
case INVALID_PARAMS:
case PARSE_ERROR:
return HttpResponseStatus.BAD_REQUEST;
default:

@ -759,7 +759,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
.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;
@ -783,7 +783,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
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;
@ -806,7 +806,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
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;
@ -829,7 +829,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
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;
@ -853,7 +853,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
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;
@ -873,7 +873,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
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;
@ -893,7 +893,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
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;
@ -978,7 +978,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
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);
@ -2035,7 +2035,7 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
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;

@ -20,5 +20,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}

@ -16,5 +16,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}

@ -13,5 +13,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}

@ -16,5 +16,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}

@ -13,5 +13,5 @@
"message": "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}

@ -19,7 +19,7 @@
"message": "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}

@ -15,5 +15,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}

@ -17,5 +17,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}

@ -13,5 +13,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}

@ -17,5 +17,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}

@ -13,5 +13,5 @@
"message" : "Invalid params"
}
},
"statusCode": 400
"statusCode": 200
}
Loading…
Cancel
Save