5098 branch 20 update invalid param count (#7466)

* 5098: Add RpcErrorTypes

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>

---------

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
Signed-off-by: Matilda-Clerke <matilda.clerke@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/7473/head
Matilda-Clerke 3 months ago committed by GitHub
parent 68d7bd0bd1
commit 35faf06b92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminModifyPeer.java
  2. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByHash.java
  3. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransaction.java
  4. 5
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/PluginsReloadConfiguration.java
  5. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceCallMany.java
  6. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceGet.java
  7. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TraceRawTransaction.java
  8. 20
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactions.java
  9. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3.java
  10. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayload.java
  11. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetEeaTransactionCount.java
  12. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivGetTransactionCount.java
  13. 5
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/PluginJsonRpcMethodTest.java
  14. 8
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminAddPeerTest.java
  15. 8
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminRemovePeerTest.java
  16. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionByHashTest.java
  17. 6
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthSendRawTransactionTest.java
  18. 8
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java
  19. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/Web3Sha3Test.java
  20. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByHash_invalidHashAndIndex.json
  21. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionByHash_invalidParams.json

@ -39,7 +39,7 @@ public abstract class AdminModifyPeer implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
if (requestContext.getRequest().getParamLength() != 1) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
}
try {
final String enodeString = requestContext.getRequiredParameter(0, String.class);

@ -48,7 +48,7 @@ public class EthGetTransactionByHash implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
if (requestContext.getRequest().getParamLength() != 1) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
}
final Hash hash = requestContext.getRequiredParameter(0, Hash.class);
final JsonRpcSuccessResponse jsonRpcSuccessResponse =

@ -66,7 +66,7 @@ public class EthSendRawTransaction implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
if (requestContext.getRequest().getParamLength() != 1) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
}
final String rawTransaction = requestContext.getRequiredParameter(0, String.class);

@ -16,7 +16,6 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
@ -56,9 +55,9 @@ public class PluginsReloadConfiguration implements JsonRpcMethod {
}
reloadPluginConfig(namedPlugins.get(pluginName));
return new JsonRpcSuccessResponse(requestContext.getRequest().getId());
} catch (InvalidJsonRpcParameters invalidJsonRpcParameters) {
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVAlID_PLUGIN_NAME_PARAMS);
}
}

@ -81,7 +81,7 @@ public class TraceCallMany extends TraceCall implements JsonRpcMethod {
if (requestContext.getRequest().getParamLength() != 2) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
}
final TraceCallManyParameter[] transactionsAndTraceTypeParameters;

@ -51,7 +51,7 @@ public class TraceGet extends AbstractTraceByHash implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
if (requestContext.getRequest().getParamLength() != 2) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
}
final Hash transactionHash = requestContext.getRequiredParameter(0, Hash.class);

@ -67,7 +67,7 @@ public class TraceRawTransaction extends AbstractTraceByBlock implements JsonRpc
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
if (requestContext.getRequest().getParamLength() != 2) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
}
final var rawTransaction = requestContext.getRequiredParameter(0, String.class);

@ -16,9 +16,11 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.PendingTransactionsParams;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionPendingResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.transaction.pool.PendingTransactionFilter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.transaction.pool.PendingTransactionFilter.Filter;
@ -54,11 +56,19 @@ public class TxPoolBesuPendingTransactions implements JsonRpcMethod {
transactionPool.getPendingTransactions();
final Integer limit =
requestContext.getOptionalParameter(0, Integer.class).orElse(pendingTransactions.size());
final List<Filter> filters =
requestContext
.getOptionalParameter(1, PendingTransactionsParams.class)
.map(PendingTransactionsParams::filters)
.orElse(Collections.emptyList());
final List<Filter> filters;
try {
filters =
requestContext
.getOptionalParameter(1, PendingTransactionsParams.class)
.map(PendingTransactionsParams::filters)
.orElse(Collections.emptyList());
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid pending transactions parameter (index 1)",
RpcErrorType.INVALID_PENDING_TRANSACTIONS_PARAMS,
e);
}
final Collection<Transaction> pendingTransactionsFiltered =
pendingTransactionFilter.reduce(pendingTransactions, filters, limit);

@ -39,7 +39,7 @@ public class Web3Sha3 implements JsonRpcMethod {
if (requestContext.getRequest().getParamLength() != 1) {
// Do we want custom messages for each different type of invalid params?
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
}
final String data;

@ -19,6 +19,7 @@ import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator
import org.hyperledger.besu.consensus.merge.blockcreation.PayloadIdentifier;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
@ -68,7 +69,13 @@ public abstract class AbstractEngineGetPayload extends ExecutionEngineJsonRpcMet
public JsonRpcResponse syncResponse(final JsonRpcRequestContext request) {
engineCallListener.executionEngineCalled();
final PayloadIdentifier payloadId = request.getRequiredParameter(0, PayloadIdentifier.class);
final PayloadIdentifier payloadId;
try {
payloadId = request.getRequiredParameter(0, PayloadIdentifier.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid payload ID parameter (index 0)", RpcErrorType.INVALID_PAYLOAD_ID_PARAMS, e);
}
mergeMiningCoordinator.finalizeProposalById(payloadId);
final Optional<PayloadWrapper> maybePayload = mergeContext.get().retrievePayloadById(payloadId);
if (maybePayload.isPresent()) {

@ -63,7 +63,7 @@ public class PrivGetEeaTransactionCount implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
if (requestContext.getRequest().getParamLength() != 3) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
}
final Address address;

@ -54,7 +54,7 @@ public class PrivGetTransactionCount implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
if (requestContext.getRequest().getParamLength() != 2) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
}
final Address address;

@ -104,7 +104,7 @@ public class PluginJsonRpcMethodTest extends JsonRpcHttpServiceTestBase {
try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(200);
final JsonObject json = new JsonObject(resp.body().string());
final JsonRpcError expectedError = new JsonRpcError(RpcErrorType.INVALID_PARAMS);
final JsonRpcError expectedError = new JsonRpcError(RpcErrorType.INVALID_PARAM_COUNT);
testHelper.assertValidJsonRpcError(
json, 1, expectedError.getCode(), expectedError.getMessage());
}
@ -173,7 +173,8 @@ public class PluginJsonRpcMethodTest extends JsonRpcHttpServiceTestBase {
private static Object echoPluginRpcMethod(final PluginRpcRequest request) {
final var params = request.getParams();
if (params.length == 0) {
throw new InvalidJsonRpcParameters("parameter is mandatory");
throw new InvalidJsonRpcParameters(
"parameter is mandatory", RpcErrorType.INVALID_PARAM_COUNT);
}
final var input = params[0];
if (input.toString().isBlank()) {

@ -102,7 +102,7 @@ public class AdminAddPeerTest {
final JsonRpcRequestContext request =
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "admin_addPeer", new String[] {}));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actualResponse = method.response(request);
@ -114,7 +114,7 @@ public class AdminAddPeerTest {
final JsonRpcRequestContext request =
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "admin_addPeer", null));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actualResponse = method.response(request);
@ -126,7 +126,7 @@ public class AdminAddPeerTest {
final JsonRpcRequestContext request =
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "admin_addPeer", new String[] {null}));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actualResponse = method.response(request);
@ -221,7 +221,7 @@ public class AdminAddPeerTest {
new JsonRpcRequest("2.0", "admin_addPeer", new String[] {validEnode, validEnode}));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actualResponse = method.response(request);

@ -102,7 +102,7 @@ public class AdminRemovePeerTest {
final JsonRpcRequestContext request =
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "admin_removePeer", new String[] {}));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actualResponse = method.response(request);
@ -114,7 +114,7 @@ public class AdminRemovePeerTest {
final JsonRpcRequestContext request =
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "admin_removePeer", null));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actualResponse = method.response(request);
@ -127,7 +127,7 @@ public class AdminRemovePeerTest {
new JsonRpcRequestContext(
new JsonRpcRequest("2.0", "admin_removePeer", new String[] {null}));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actualResponse = method.response(request);
@ -222,7 +222,7 @@ public class AdminRemovePeerTest {
new JsonRpcRequest("2.0", "admin_removePeer", new String[] {validEnode, validEnode}));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actualResponse = method.response(request);

@ -77,7 +77,7 @@ class EthGetTransactionByHashTest {
final JsonRpcRequestContext context = new JsonRpcRequestContext(request);
final JsonRpcErrorResponse expectedResponse =
new JsonRpcErrorResponse(request.getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actualResponse = method.response(context);

@ -57,7 +57,7 @@ public class EthSendRawTransactionTest {
new JsonRpcRequest("2.0", "eth_sendRawTransaction", new String[] {}));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actualResponse = method.response(request);
@ -70,7 +70,7 @@ public class EthSendRawTransactionTest {
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "eth_sendRawTransaction", null));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actualResponse = method.response(request);
@ -84,7 +84,7 @@ public class EthSendRawTransactionTest {
new JsonRpcRequest("2.0", "eth_sendRawTransaction", new String[] {null}));
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actualResponse = method.response(request);

@ -201,7 +201,7 @@ public class TxPoolBesuPendingTransactionsTest {
assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Unknown field expected one of `eq`, `gt`, `lt`, `action`");
.hasMessageContaining("Invalid pending transactions parameter (index 1)");
}
@Test
@ -229,7 +229,7 @@ public class TxPoolBesuPendingTransactionsTest {
assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("Only one operator per filter type allowed");
.hasMessageContaining("Invalid pending transactions parameter (index 1)");
}
@Test
@ -256,7 +256,7 @@ public class TxPoolBesuPendingTransactionsTest {
assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("The `from` filter only supports the `eq` operator");
.hasMessageContaining("Invalid pending transactions parameter (index 1)");
}
@Test
@ -283,7 +283,7 @@ public class TxPoolBesuPendingTransactionsTest {
assertThatThrownBy(() -> method.response(request))
.isInstanceOf(InvalidJsonRpcParameters.class)
.hasMessageContaining("The `to` filter only supports the `eq` or `action` operator");
.hasMessageContaining("Invalid pending transactions parameter (index 1)");
}
private Set<PendingTransaction> getTransactionPool() {

@ -123,7 +123,7 @@ public class Web3Sha3Test {
"2", "web3_sha3", new Object[] {"0x68656c6c6f20776f726c64", "{encode:'hex'}"}));
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actual = method.response(request);
assertThat(actual).usingRecursiveComparison().isEqualTo(expected);
@ -135,7 +135,7 @@ public class Web3Sha3Test {
new JsonRpcRequestContext(new JsonRpcRequest("2", "web3_sha3", new Object[] {}));
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
new JsonRpcErrorResponse(request.getRequest().getId(), RpcErrorType.INVALID_PARAM_COUNT);
final JsonRpcResponse actual = method.response(request);
assertThat(actual).usingRecursiveComparison().isEqualTo(expected);

@ -13,7 +13,7 @@
"id" : 406,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid number of params"
}
},
"statusCode": 200

@ -10,7 +10,7 @@
"id" : 412,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid number of params"
}
},
"statusCode": 200

Loading…
Cancel
Save