5098 branch 9 update invalid block count params (#7410)

* 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/7452/head
Matilda-Clerke 3 months ago committed by GitHub
parent bca34cb61f
commit 47fff38cf6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 11
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java
  2. 9
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadBodiesByRangeV1.java
  3. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java
  4. 10
      ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java

@ -88,9 +88,15 @@ public class EthFeeHistory implements JsonRpcMethod {
public JsonRpcResponse response(final JsonRpcRequestContext request) {
final Object requestId = request.getRequest().getId();
final int blockCount = request.getRequiredParameter(0, UnsignedIntParameter.class).getValue();
final int blockCount;
try {
blockCount = request.getRequiredParameter(0, UnsignedIntParameter.class).getValue();
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid block count parameter (index 0)", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e);
}
if (isInvalidBlockCount(blockCount)) {
return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_PARAMS);
return new JsonRpcErrorResponse(requestId, RpcErrorType.INVALID_BLOCK_COUNT_PARAMS);
}
final BlockParameter highestBlock;
try {
@ -99,6 +105,7 @@ public class EthFeeHistory implements JsonRpcMethod {
throw new InvalidJsonRpcParameters(
"Invalid highest block parameter (index 1)", RpcErrorType.INVALID_BLOCK_PARAMS, e);
}
final Optional<List<Double>> maybeRewardPercentiles =
request.getOptionalParameter(2, Double[].class).map(Arrays::asList);

@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;
import org.hyperledger.besu.ethereum.ProtocolContext;
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.ExecutionEngineJsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedLongParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
@ -59,7 +60,13 @@ public class EngineGetPayloadBodiesByRangeV1 extends ExecutionEngineJsonRpcMetho
final long startBlockNumber =
request.getRequiredParameter(0, UnsignedLongParameter.class).getValue();
final long count = request.getRequiredParameter(1, UnsignedLongParameter.class).getValue();
final long count;
try {
count = request.getRequiredParameter(1, UnsignedLongParameter.class).getValue();
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid block count params (index 1)", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e);
}
final Object reqId = request.getRequest().getId();
LOG.atTrace()

@ -241,11 +241,11 @@ public class EthFeeHistoryTest {
assertThat(
((JsonRpcErrorResponse) feeHistoryRequest("0x0", "latest", new double[] {100.0}))
.getErrorType())
.isEqualTo(RpcErrorType.INVALID_PARAMS);
.isEqualTo(RpcErrorType.INVALID_BLOCK_COUNT_PARAMS);
assertThat(
((JsonRpcErrorResponse) feeHistoryRequest("0x401", "latest", new double[] {100.0}))
.getErrorType())
.isEqualTo(RpcErrorType.INVALID_PARAMS);
.isEqualTo(RpcErrorType.INVALID_BLOCK_COUNT_PARAMS);
}
@Test

@ -16,9 +16,11 @@ package org.hyperledger.besu.ethereum.retesteth.methods;
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.JsonRpcMethod;
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.blockcreation.PoWBlockCreator;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
@ -44,7 +46,13 @@ public class TestMineBlocks implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
long blocksToMine = requestContext.getRequiredParameter(0, Long.class);
long blocksToMine = 0;
try {
blocksToMine = requestContext.getRequiredParameter(0, Long.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid blocks to mine (index 0)", RpcErrorType.INVALID_BLOCK_COUNT_PARAMS, e);
}
while (blocksToMine-- > 0) {
if (!mineNewBlock()) {
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), false);

Loading…
Cancel
Save