5098 branch 13 update invalid call consolidation and privacy group (#7441)

* 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/7455/head
Matilda-Clerke 3 months ago committed by GitHub
parent c61cf0b5af
commit b8c062cdcb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/JsonCallParameterUtil.java
  2. 3
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineNewPayload.java
  3. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCall.java
  4. 13
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroup.java
  5. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCreatePrivacyGroupTest.java
  6. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_blob_zero_versioned_hash.json
  7. 2
      ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_call_invalidWithDifferentInputAndDataAttributes.json

@ -17,13 +17,20 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
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.JsonCallParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
public class JsonCallParameterUtil {
private JsonCallParameterUtil() {}
public static JsonCallParameter validateAndGetCallParams(final JsonRpcRequestContext request) {
final JsonCallParameter callParams = request.getRequiredParameter(0, JsonCallParameter.class);
final JsonCallParameter callParams;
try {
callParams = request.getRequiredParameter(0, JsonCallParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid call parameters (index 0)", RpcErrorType.INVALID_CALL_PARAMS);
}
if (callParams.getGasPrice() != null
&& (callParams.getMaxFeePerGas().isPresent()

@ -197,8 +197,7 @@ public abstract class AbstractEngineNewPayload extends ExecutionEngineJsonRpcMet
if (!getConsolidationRequestValidator(
protocolSchedule.get(), blockParam.getTimestamp(), blockParam.getBlockNumber())
.validateParameter(maybeConsolidationRequests)) {
return new JsonRpcErrorResponse(
reqId, new JsonRpcError(INVALID_PARAMS, "Invalid consolidation request"));
return new JsonRpcErrorResponse(reqId, RpcErrorType.INVALID_CONSOLIDATION_REQUEST_PARAMS);
}
Optional<List<Request>> maybeRequests =

@ -104,9 +104,16 @@ public class PrivCall extends AbstractBlockParameterMethod {
}
private JsonCallParameter validateAndGetCallParams(final JsonRpcRequestContext request) {
final JsonCallParameter callParams = request.getRequiredParameter(1, JsonCallParameter.class);
final JsonCallParameter callParams;
try {
callParams = request.getRequiredParameter(1, JsonCallParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid call parameters (index 1)", RpcErrorType.INVALID_CALL_PARAMS);
}
if (callParams.getTo() == null) {
throw new InvalidJsonRpcParameters("Missing \"to\" field in call arguments");
throw new InvalidJsonRpcParameters(
"Missing \"to\" field in call arguments", RpcErrorType.INVALID_CALL_PARAMS);
}
return callParams;
}

@ -18,12 +18,14 @@ import org.hyperledger.besu.enclave.types.PrivacyGroup;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcEnclaveErrorConverter;
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.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.parameters.CreatePrivacyGroupParameter;
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;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.privacy.PrivacyController;
import org.slf4j.Logger;
@ -50,8 +52,15 @@ public class PrivCreatePrivacyGroup implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
LOG.trace("Executing {}", RpcMethod.PRIV_CREATE_PRIVACY_GROUP.getMethodName());
final CreatePrivacyGroupParameter parameter =
requestContext.getRequiredParameter(0, CreatePrivacyGroupParameter.class);
final CreatePrivacyGroupParameter parameter;
try {
parameter = requestContext.getRequiredParameter(0, CreatePrivacyGroupParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid create privacy group parameter (index 0)",
RpcErrorType.INVALID_CREATE_PRIVACY_GROUP_PARAMS,
e);
}
LOG.trace(
"Creating a privacy group with name {} and description {}",

@ -231,7 +231,7 @@ public class PrivCreatePrivacyGroupTest {
catchThrowableOfType(
() -> privCreatePrivacyGroup.response(request), InvalidJsonRpcParameters.class);
assertThat(response.getMessage()).contains("Invalid json rpc parameter at index 0");
assertThat(response.getMessage()).contains("Invalid create privacy group parameter (index 0)");
}
@Test
@ -249,7 +249,7 @@ public class PrivCreatePrivacyGroupTest {
catchThrowableOfType(
() -> privCreatePrivacyGroup.response(request), InvalidJsonRpcParameters.class);
assertThat(response.getMessage()).isEqualTo("Missing required json rpc parameter at index 0");
assertThat(response.getMessage()).isEqualTo("Invalid create privacy group parameter (index 0)");
}
@Test

@ -17,7 +17,7 @@
"response": {
"jsonrpc": "2.0",
"id": 4,
"error":{"code":-32602,"message":"Invalid params"}
"error":{"code":-32602,"message":"Invalid call params"}
},
"statusCode": 200
}

@ -18,7 +18,7 @@
"id": 3,
"error" : {
"code" : -32602,
"message" : "Invalid params"
"message" : "Invalid call params"
}
},
"statusCode": 200

Loading…
Cancel
Save