From 38226ab2d25443a895fe95dd03f9201916a2d0a0 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Mon, 15 Jul 2024 16:48:30 +1000 Subject: [PATCH 01/11] fix: Ignore unknown values fail for values like 0x..." Signed-off-by: Usman Saleem --- .../internal/methods/AbstractEstimateGas.java | 11 ------- .../internal/methods/EthCreateAccessList.java | 2 ++ .../internal/methods/EthEstimateGas.java | 2 ++ .../parameters/JsonCallParameter.java | 2 ++ .../parameters/JsonCallParameterTest.java | 17 +++++++++- .../core/json/IgnoreFieldDeserializer.java | 31 +++++++++++++++++++ 6 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/json/IgnoreFieldDeserializer.java diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractEstimateGas.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractEstimateGas.java index 237eef2e022..ef8ca5b316d 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractEstimateGas.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AbstractEstimateGas.java @@ -17,7 +17,6 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcErrorConverter; 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.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; @@ -94,16 +93,6 @@ protected long processEstimateGas( return ((long) ((gasUsedByTransaction + gasStipend) * subCallMultiplier)); } - protected JsonCallParameter validateAndGetCallParams(final JsonRpcRequestContext request) { - final JsonCallParameter callParams = request.getRequiredParameter(0, JsonCallParameter.class); - if (callParams.getGasPrice() != null - && (callParams.getMaxFeePerGas().isPresent() - || callParams.getMaxPriorityFeePerGas().isPresent())) { - throw new InvalidJsonRpcParameters("gasPrice cannot be used with baseFee or maxFeePerGas"); - } - return callParams; - } - protected JsonRpcErrorResponse errorResponse( final JsonRpcRequestContext request, final TransactionSimulatorResult result) { diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessList.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessList.java index b6b9f5171fa..2be5047a24a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessList.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessList.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; +import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonCallParameterUtil.validateAndGetCallParams; + import org.hyperledger.besu.datatypes.AccessListEntry; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java index c0631bf44cb..ca084ba0fbb 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGas.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; +import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonCallParameterUtil.validateAndGetCallParams; + 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.parameters.JsonCallParameter; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java index b084ebc9135..74ff7805a07 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.json.GasDeserializer; import org.hyperledger.besu.ethereum.core.json.HexStringDeserializer; +import org.hyperledger.besu.ethereum.core.json.IgnoreFieldDeserializer; import org.hyperledger.besu.ethereum.transaction.CallParameter; import java.util.List; @@ -83,6 +84,7 @@ public Optional isMaybeStrict() { } @JsonAnySetter + @JsonDeserialize(using = IgnoreFieldDeserializer.class) public void logUnknownProperties(final String key, final Object value) { LOG.debug( "unknown property - {} with value - {} and type - {} caught during serialization", diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java index b74c68f97df..f2bbae4bbee 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java @@ -25,7 +25,7 @@ public class JsonCallParameterTest { private final ObjectMapper objectMapper = new ObjectMapper(); @Test - public void acceptsAndCapMaxValueForGasLimit() throws JsonProcessingException { + public void acceptsAndCapMaxValueForGas() throws JsonProcessingException { final String json = """ { @@ -37,4 +37,19 @@ public void acceptsAndCapMaxValueForGasLimit() throws JsonProcessingException { assertThat(callParameter.getGasLimit()).isEqualTo(Long.MAX_VALUE); } + + @Test + public void extraParameterIsIgnored() throws JsonProcessingException { + final String json = + """ + { + "gas": "0x96", + "gasLimit": "0xfa" + } + """; + + final JsonCallParameter callParameter = objectMapper.readValue(json, JsonCallParameter.class); + + assertThat(callParameter.getGasLimit()).isEqualTo(150); + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/json/IgnoreFieldDeserializer.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/json/IgnoreFieldDeserializer.java new file mode 100644 index 00000000000..7200dd650cb --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/json/IgnoreFieldDeserializer.java @@ -0,0 +1,31 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.core.json; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; + +public class IgnoreFieldDeserializer extends JsonDeserializer { + @Override + public Object deserialize( + final JsonParser jsonParser, final DeserializationContext deserializationContext) + throws IOException, JacksonException { + return null; + } +} From 609ad1b4c0cc262aa850ee7d91e9afbd01fccf20 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Mon, 15 Jul 2024 18:43:55 +1000 Subject: [PATCH 02/11] fix: Use Builder for JsonCallParameter Signed-off-by: Usman Saleem --- .../fork/frontier/EthCallIntegrationTest.java | 291 ++++++------------ .../EthCreateAccessListIntegrationTest.java | 128 +++----- .../EthEstimateGasIntegrationTest.java | 98 +++--- .../fork/london/EthCallIntegrationTest.java | 190 ++++-------- .../london/EthEstimateGasIntegrationTest.java | 84 ++--- .../parameters/JsonCallParameter.java | 171 ++++++++-- .../jsonrpc/internal/methods/EthCallTest.java | 27 +- .../methods/EthCreateAccessListTest.java | 48 ++- .../internal/methods/EthEstimateGasTest.java | 47 ++- .../privacy/methods/priv/PrivCallTest.java | 60 ++-- 10 files changed, 474 insertions(+), 670 deletions(-) diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCallIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCallIntegrationTest.java index 14aa15c5c8f..a05b6786ced 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCallIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCallIntegrationTest.java @@ -64,20 +64,12 @@ public void setUp() { @Test public void shouldReturnExpectedResultForCallAtLatestBlock() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - null, - null, - null, - null, - Bytes.fromHexString("0x12a7b914"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withInput(Bytes.fromHexString("0x12a7b914")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( @@ -91,20 +83,12 @@ public void shouldReturnExpectedResultForCallAtLatestBlock() { @Test public void shouldReturnExpectedResultForCallAtSpecificBlock() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - null, - null, - null, - null, - Bytes.fromHexString("0x12a7b914"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withInput(Bytes.fromHexString("0x12a7b914")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "0x8"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( @@ -118,21 +102,13 @@ public void shouldReturnExpectedResultForCallAtSpecificBlock() { @Test public void shouldReturnSuccessWhenCreatingContract() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - null, - null, - null, - null, - null, - null, - Bytes.fromHexString( - "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withInput( + Bytes.fromHexString( + "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( @@ -147,20 +123,13 @@ public void shouldReturnSuccessWhenCreatingContract() { @Test public void shouldReturnErrorWithGasLimitTooLow() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - 0L, - null, - null, - null, - null, - Bytes.fromHexString("0x12a7b914"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withGasLimit(0L) + .withInput(Bytes.fromHexString("0x12a7b914")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, RpcErrorType.INTRINSIC_GAS_EXCEEDS_LIMIT); @@ -173,20 +142,14 @@ public void shouldReturnErrorWithGasLimitTooLow() { @Test public void shouldReturnErrorWithGasPriceTooHighAndStrict() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - Wei.fromHexString("0x10000000000000"), - null, - null, - null, - Bytes.fromHexString("0x12a7b914"), - null, - true, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withGasPrice(Wei.fromHexString("0x10000000000000")) + .withInput(Bytes.fromHexString("0x12a7b914")) + .withStrict(true) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE); @@ -199,20 +162,14 @@ public void shouldReturnErrorWithGasPriceTooHighAndStrict() { @Test public void shouldReturnSuccessWithGasPriceTooHighNotStrict() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - Wei.fromHexString("0x10000000000000"), - null, - null, - null, - Bytes.fromHexString("0x12a7b914"), - null, - false, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withGasPrice(Wei.fromHexString("0x10000000000000")) + .withInput(Bytes.fromHexString("0x12a7b914")) + .withStrict(false) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( @@ -226,20 +183,13 @@ public void shouldReturnSuccessWithGasPriceTooHighNotStrict() { @Test public void shouldReturnErrorWithGasPriceTooHigh() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - Wei.fromHexString("0x10000000000000"), - null, - null, - null, - Bytes.fromHexString("0x12a7b914"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withGasPrice(Wei.fromHexString("0x10000000000000")) + .withInput(Bytes.fromHexString("0x12a7b914")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE); @@ -252,20 +202,13 @@ public void shouldReturnErrorWithGasPriceTooHigh() { @Test public void shouldReturnSuccessWithValidGasPrice() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - Wei.fromHexString("0x10"), - null, - null, - null, - Bytes.fromHexString("0x12a7b914"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withGasPrice(Wei.fromHexString("0x10")) + .withInput(Bytes.fromHexString("0x12a7b914")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( @@ -279,20 +222,13 @@ public void shouldReturnSuccessWithValidGasPrice() { @Test public void shouldReturnErrorWithGasPriceAndEmptyBalance() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xdeadbeef00000000000000000000000000000000"), - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - Wei.fromHexString("0x10"), - null, - null, - null, - Bytes.fromHexString("0x12a7b914"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xdeadbeef00000000000000000000000000000000")) + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withGasPrice(Wei.fromHexString("0x10")) + .withInput(Bytes.fromHexString("0x12a7b914")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE); @@ -305,20 +241,13 @@ public void shouldReturnErrorWithGasPriceAndEmptyBalance() { @Test public void shouldReturnSuccessWithZeroGasPriceAndEmptyBalance() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xdeadbeef00000000000000000000000000000000"), - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - Wei.fromHexString("0x0"), - null, - null, - null, - Bytes.fromHexString("0x12a7b914"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xdeadbeef00000000000000000000000000000000")) + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withGasPrice(Wei.fromHexString("0x0")) + .withInput(Bytes.fromHexString("0x12a7b914")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( @@ -332,20 +261,12 @@ public void shouldReturnSuccessWithZeroGasPriceAndEmptyBalance() { @Test public void shouldReturnSuccessWithoutGasPriceAndEmptyBalance() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xdeadbeef00000000000000000000000000000000"), - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - null, - null, - null, - null, - Bytes.fromHexString("0x12a7b914"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xdeadbeef00000000000000000000000000000000")) + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withInput(Bytes.fromHexString("0x12a7b914")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( @@ -359,20 +280,13 @@ public void shouldReturnSuccessWithoutGasPriceAndEmptyBalance() { @Test public void shouldReturnSuccessWithInvalidGasPricingAndEmptyBalance() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xdeadbeef00000000000000000000000000000000"), - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - null, - Wei.fromHexString("0x0A"), - null, - null, - Bytes.fromHexString("0x12a7b914"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xdeadbeef00000000000000000000000000000000")) + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withMaxPriorityFeePerGas(Wei.fromHexString("0x0A")) + .withInput(Bytes.fromHexString("0x12a7b914")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( @@ -386,20 +300,10 @@ public void shouldReturnSuccessWithInvalidGasPricingAndEmptyBalance() { @Test public void shouldReturnEmptyHashResultForCallWithOnlyToField() { final JsonCallParameter callParameter = - new JsonCallParameter( - null, - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x"); @@ -411,20 +315,13 @@ public void shouldReturnEmptyHashResultForCallWithOnlyToField() { @Test public void shouldReturnSuccessWithInputAndDataFieldSetToSameValue() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - null, - null, - null, - null, - Bytes.fromHexString("0x12a7b914"), - Bytes.fromHexString("0x12a7b914"), - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withInput(Bytes.fromHexString("0x12a7b914")) + .withData(Bytes.fromHexString("0x12a7b914")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCreateAccessListIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCreateAccessListIntegrationTest.java index e68fd29d18b..a50e2677f5b 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCreateAccessListIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCreateAccessListIntegrationTest.java @@ -79,10 +79,11 @@ public void shouldSucceedWhenCreateAccessListMultipleReads() { "0x0000000000000000000000000000000000000000000000000000000000000003")))); final JsonCallParameter callParameter = - createAccessListJsonCallParameters( - "0x658bdf435d810c91414ec09147daa6db62406379", - "0xbb00000000000000000000000000000000000000", - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x658bdf435d810c91414ec09147daa6db62406379")) + .withTo(Address.fromHexString("0xbb00000000000000000000000000000000000000")) + .withAccessList(null) + .build(); assertAccessListExpectedResult(callParameter, expectedAccessListEntryList, expectedGasUsed); } @@ -101,10 +102,11 @@ public void shouldSucceedWhenCreateAccessListMultipleReads_withAccessListParam() "0x0000000000000000000000000000000000000000000000000000000000000003")))); final JsonCallParameter callParameter = - createAccessListJsonCallParameters( - "0x658bdf435d810c91414ec09147daa6db62406379", - "0xbb00000000000000000000000000000000000000", - expectedAccessListEntryList); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x658bdf435d810c91414ec09147daa6db62406379")) + .withTo(Address.fromHexString("0xbb00000000000000000000000000000000000000")) + .withAccessList(expectedAccessListEntryList) + .build(); assertAccessListExpectedResult(callParameter, expectedAccessListEntryList, expectedGasUsed); } @@ -115,10 +117,11 @@ public void shouldSucceedWhenCreateAccessListSimpleTransfer() { final List expectedAccessListEntryList = new ArrayList<>(); final JsonCallParameter callParameter = - createAccessListJsonCallParameters( - "0x658bdf435d810c91414ec09147daa6db62406379", - "0x0100000000000000000000000000000000000000", - expectedAccessListEntryList); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x658bdf435d810c91414ec09147daa6db62406379")) + .withTo(Address.fromHexString("0x0100000000000000000000000000000000000000")) + .withAccessList(expectedAccessListEntryList) + .build(); assertAccessListExpectedResult(callParameter, expectedAccessListEntryList, expectedGasUsed); } @@ -129,10 +132,11 @@ public void shouldSucceedWhenCreateAccessListSimpleContract() { final List expectedAccessListEntryList = new ArrayList<>(); final JsonCallParameter callParameter = - createAccessListJsonCallParameters( - "0x658bdf435d810c91414ec09147daa6db62406379", - "0xaa00000000000000000000000000000000000000", - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x658bdf435d810c91414ec09147daa6db62406379")) + .withTo(Address.fromHexString("0xaa00000000000000000000000000000000000000")) + .withAccessList(null) + .build(); assertAccessListExpectedResult(callParameter, expectedAccessListEntryList, expectedGasUsed); } @@ -140,8 +144,8 @@ public void shouldSucceedWhenCreateAccessListSimpleContract() { @Test public void shouldReturnExpectedValueForEmptyCallParameter() { final JsonCallParameter callParameter = - new JsonCallParameter( - null, null, null, null, null, null, null, null, null, null, null, null, null); + new JsonCallParameter.JsonCallParameterBuilder().build(); + final JsonRpcRequestContext request = requestWithParams(callParameter); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0xcf08)); @@ -154,20 +158,12 @@ public void shouldReturnExpectedValueForEmptyCallParameter() { @Test public void shouldReturnExpectedValueForTransfer() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x8888f1f195afa192cfee860698584c030f4c9db1"), - null, - null, - null, - null, - Wei.ZERO, - null, - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x8888f1f195afa192cfee860698584c030f4c9db1")) + .withValue(Wei.ZERO) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0x5208)); @@ -180,21 +176,13 @@ public void shouldReturnExpectedValueForTransfer() { @Test public void shouldReturnExpectedValueForContractDeploy() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - null, - null, - null, - null, - null, - null, - Bytes.fromHexString( - "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withInput( + Bytes.fromHexString( + "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0x1f081)); @@ -207,21 +195,16 @@ public void shouldReturnExpectedValueForContractDeploy() { @Test public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpectedValue() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0x0000000000000000000000000000000000000000"), - null, - 1L, - Wei.fromHexString("0x9999999999"), - null, - null, - null, - Bytes.fromHexString( - "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"), - null, - false, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x0000000000000000000000000000000000000000")) + .withGasLimit(1L) + .withGasPrice(Wei.fromHexString("0x9999999999")) + .withInput( + Bytes.fromHexString( + "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029")) + .withStrict(false) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0x1f081)); @@ -234,8 +217,7 @@ public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpec @Test public void shouldReturnExpectedValueForInsufficientGas() { final JsonCallParameter callParameter = - new JsonCallParameter( - null, null, 1L, null, null, null, null, null, null, null, null, null, null); + new JsonCallParameter.JsonCallParameterBuilder().withGasLimit(1L).build(); final JsonRpcRequestContext request = requestWithParams(callParameter); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0xcf08)); @@ -257,24 +239,6 @@ private void assertAccessListExpectedResult( assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse); } - private JsonCallParameter createAccessListJsonCallParameters( - final String from, final String to, final List accessList) { - return new JsonCallParameter( - Address.fromHexString(from), - Address.fromHexString(to), - null, - null, - null, - null, - null, - null, - null, - null, - accessList, - null, - null); - } - private JsonRpcRequestContext requestWithParams(final Object... params) { return new JsonRpcRequestContext(new JsonRpcRequest("2.0", "eth_createAccessList", params)); } diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java index a461539030f..6ab89808d4f 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java @@ -66,8 +66,7 @@ public void setUp() { @Test public void shouldReturnExpectedValueForEmptyCallParameter() { final JsonCallParameter callParameter = - new JsonCallParameter( - null, null, null, null, null, null, null, null, null, null, null, null, null); + new JsonCallParameter.JsonCallParameterBuilder().build(); final JsonRpcRequestContext request = requestWithParams(callParameter); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x5208"); @@ -79,20 +78,12 @@ public void shouldReturnExpectedValueForEmptyCallParameter() { @Test public void shouldReturnExpectedValueForTransfer() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x8888f1f195afa192cfee860698584c030f4c9db1"), - null, - null, - null, - null, - Wei.ONE, - null, - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x8888f1f195afa192cfee860698584c030f4c9db1")) + .withValue(Wei.ONE) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x5208"); @@ -104,21 +95,13 @@ public void shouldReturnExpectedValueForTransfer() { @Test public void shouldReturnExpectedValueForContractDeploy() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - null, - null, - null, - null, - null, - null, - Bytes.fromHexString( - "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withInput( + Bytes.fromHexString( + "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x1b551"); @@ -130,21 +113,16 @@ public void shouldReturnExpectedValueForContractDeploy() { @Test public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpectedValue() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0x0000000000000000000000000000000000000000"), - null, - 1L, - Wei.fromHexString("0x9999999999"), - null, - null, - null, - Bytes.fromHexString( - "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"), - null, - false, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x0000000000000000000000000000000000000000")) + .withGasLimit(1L) + .withGasPrice(Wei.fromHexString("0x9999999999")) + .withInput( + Bytes.fromHexString( + "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029")) + .withStrict(false) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x1b551"); @@ -156,21 +134,16 @@ public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpec @Test public void shouldNotIgnoreSenderBalanceAccountWhenStrictModeDisabledAndThrowError() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"), - null, - 1L, - Wei.fromHexString("0x9999999999"), - null, - null, - null, - Bytes.fromHexString( - "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"), - null, - true, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) + .withGasLimit(1L) + .withGasPrice(Wei.fromHexString("0x9999999999")) + .withInput( + Bytes.fromHexString( + "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029")) + .withStrict(true) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter); final ValidationResult validationResult = ValidationResult.invalid( @@ -186,8 +159,7 @@ public void shouldNotIgnoreSenderBalanceAccountWhenStrictModeDisabledAndThrowErr @Test public void shouldReturnExpectedValueForInsufficientGas() { final JsonCallParameter callParameter = - new JsonCallParameter( - null, null, 1L, null, null, null, null, null, null, null, null, null, null); + new JsonCallParameter.JsonCallParameterBuilder().withGasLimit(1L).build(); final JsonRpcRequestContext request = requestWithParams(callParameter); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x5208"); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthCallIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthCallIntegrationTest.java index e92076123b2..5f03d7f4d5f 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthCallIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthCallIntegrationTest.java @@ -64,20 +64,12 @@ public void setUp() { @Test public void shouldReturnSuccessWithoutGasPriceAndEmptyBalance() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xdeadbeef00000000000000000000000000000000"), - Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517"), - null, - null, - null, - null, - null, - Bytes.fromHexString("0x2e64cec1"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xdeadbeef00000000000000000000000000000000")) + .withTo(Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517")) + .withInput(Bytes.fromHexString("0x2e64cec1")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( @@ -91,20 +83,13 @@ public void shouldReturnSuccessWithoutGasPriceAndEmptyBalance() { @Test public void shouldReturnErrorWithGasPriceTooHigh() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517"), - null, - Wei.fromHexString("0x10000000000000"), - null, - null, - null, - Bytes.fromHexString("0x2e64cec1"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517")) + .withGasPrice(Wei.fromHexString("0x10000000000000")) + .withInput(Bytes.fromHexString("0x2e64cec1")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE); @@ -117,20 +102,13 @@ public void shouldReturnErrorWithGasPriceTooHigh() { @Test public void shouldReturnSuccessWithValidGasPrice() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517"), - null, - Wei.fromHexString("0x3B9ACA01"), - null, - null, - null, - Bytes.fromHexString("0x2e64cec1"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517")) + .withGasPrice(Wei.fromHexString("0x3B9ACA01")) + .withInput(Bytes.fromHexString("0x2e64cec1")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( @@ -144,20 +122,13 @@ public void shouldReturnSuccessWithValidGasPrice() { @Test public void shouldReturnErrorWithGasPriceLessThanCurrentBaseFee() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517"), - null, - Wei.fromHexString("0x0A"), - null, - null, - null, - Bytes.fromHexString("0x2e64cec1"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517")) + .withGasPrice(Wei.fromHexString("0x0A")) + .withInput(Bytes.fromHexString("0x2e64cec1")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, RpcErrorType.GAS_PRICE_BELOW_CURRENT_BASE_FEE); @@ -170,20 +141,13 @@ public void shouldReturnErrorWithGasPriceLessThanCurrentBaseFee() { @Test public void shouldReturnSuccessWithValidMaxFeePerGas() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517"), - null, - null, - null, - Wei.fromHexString("0x3B9ACA01"), - null, - Bytes.fromHexString("0x2e64cec1"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517")) + .withMaxFeePerGas(Wei.fromHexString("0x3B9ACA01")) + .withInput(Bytes.fromHexString("0x2e64cec1")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( @@ -197,20 +161,14 @@ public void shouldReturnSuccessWithValidMaxFeePerGas() { @Test public void shouldReturnSuccessWithValidMaxFeePerGasAndMaxPriorityFeePerGas() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517"), - null, - null, - Wei.fromHexString("0x3B9ACA00"), - Wei.fromHexString("0x3B9ACA01"), - null, - Bytes.fromHexString("0x2e64cec1"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517")) + .withMaxPriorityFeePerGas(Wei.fromHexString("0x3B9ACA00")) + .withMaxFeePerGas(Wei.fromHexString("0x3B9ACA01")) + .withInput(Bytes.fromHexString("0x2e64cec1")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse( @@ -224,20 +182,13 @@ public void shouldReturnSuccessWithValidMaxFeePerGasAndMaxPriorityFeePerGas() { @Test public void shouldReturnErrorWithValidMaxFeePerGasLessThanCurrentBaseFee() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517"), - null, - null, - null, - Wei.fromHexString("0x0A"), - null, - Bytes.fromHexString("0x2e64cec1"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517")) + .withMaxFeePerGas(Wei.fromHexString("0x0A")) + .withInput(Bytes.fromHexString("0x2e64cec1")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, RpcErrorType.GAS_PRICE_BELOW_CURRENT_BASE_FEE); @@ -250,20 +201,14 @@ public void shouldReturnErrorWithValidMaxFeePerGasLessThanCurrentBaseFee() { @Test public void shouldReturnErrorWithValidMaxFeePerGasLessThanMaxPriorityFeePerGas() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517"), - null, - null, - Wei.fromHexString("0x3B9ACA02"), - Wei.fromHexString("0x3B9ACA01"), - null, - Bytes.fromHexString("0x2e64cec1"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517")) + .withMaxPriorityFeePerGas(Wei.fromHexString("0x3B9ACA02")) + .withMaxFeePerGas(Wei.fromHexString("0x3B9ACA01")) + .withInput(Bytes.fromHexString("0x2e64cec1")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse( @@ -277,20 +222,13 @@ public void shouldReturnErrorWithValidMaxFeePerGasLessThanMaxPriorityFeePerGas() @Test public void shouldReturnErrorWithMaxFeePerGasAndEmptyBalance() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xdeadbeef00000000000000000000000000000000"), - Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517"), - null, - null, - null, - Wei.fromHexString("0x3B9ACA01"), - null, - Bytes.fromHexString("0x2e64cec1"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xdeadbeef00000000000000000000000000000000")) + .withTo(Address.fromHexString("0x9b8397f1b0fecd3a1a40cdd5e8221fa461898517")) + .withMaxFeePerGas(Wei.fromHexString("0x3B9ACA01")) + .withInput(Bytes.fromHexString("0x2e64cec1")) + .build(); + final JsonRpcRequestContext request = requestWithParams(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, RpcErrorType.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthEstimateGasIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthEstimateGasIntegrationTest.java index 0a3ba1be7fe..84447dfc9d3 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthEstimateGasIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/london/EthEstimateGasIntegrationTest.java @@ -67,20 +67,11 @@ public void setUp() { @Test public void shouldReturnExpectedValueForTransfer() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x8888f1f195afa192cfee860698584c030f4c9db1"), - null, - null, - null, - null, - Wei.ONE, - null, - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x8888f1f195afa192cfee860698584c030f4c9db1")) + .withValue(Wei.ONE) + .build(); final JsonRpcResponse response = method.response(requestWithParams(callParameter)); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x5208"); @@ -89,22 +80,13 @@ public void shouldReturnExpectedValueForTransfer() { @Test public void shouldReturnExpectedValueForTransfer_WithAccessList() { - final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - Address.fromHexString("0x8888f1f195afa192cfee860698584c030f4c9db1"), - null, - null, - null, - null, - Wei.ONE, - null, - null, - null, - createAccessList(), - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withTo(Address.fromHexString("0x8888f1f195afa192cfee860698584c030f4c9db1")) + .withValue(Wei.ONE) + .withAccessList(createAccessList()) + .build(); final JsonRpcResponse response = method.response(requestWithParams(callParameter)); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x62d4"); @@ -114,21 +96,13 @@ public void shouldReturnExpectedValueForTransfer_WithAccessList() { @Test public void shouldReturnExpectedValueForContractDeploy() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - null, - null, - null, - null, - null, - null, - Bytes.fromHexString( - "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"), - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withInput( + Bytes.fromHexString( + "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029")) + .build(); + final JsonRpcResponse response = method.response(requestWithParams(callParameter)); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x1f081"); assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse); @@ -137,21 +111,13 @@ public void shouldReturnExpectedValueForContractDeploy() { @Test public void shouldReturnExpectedValueForContractDeploy_WithAccessList() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"), - null, - null, - null, - null, - null, - null, - Bytes.fromHexString( - "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"), - null, - null, - createAccessList(), - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) + .withInput( + Bytes.fromHexString( + "0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029")) + .withAccessList(createAccessList()) + .build(); final JsonRpcResponse response = method.response(requestWithParams(callParameter)); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x2014d"); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java index 74ff7805a07..5d183a83d56 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java @@ -27,7 +27,6 @@ import java.util.Optional; import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @@ -36,47 +35,41 @@ import org.slf4j.LoggerFactory; @JsonIgnoreProperties(ignoreUnknown = true) +@JsonDeserialize(builder = JsonCallParameter.JsonCallParameterBuilder.class) public class JsonCallParameter extends CallParameter { private static final Logger LOG = LoggerFactory.getLogger(JsonCallParameter.class); private final Optional strict; - @JsonCreator - public JsonCallParameter( - @JsonProperty("from") final Address from, - @JsonProperty("to") final Address to, - @JsonDeserialize(using = GasDeserializer.class) @JsonProperty("gas") final Long gasLimit, - @JsonProperty("gasPrice") final Wei gasPrice, - @JsonProperty("maxPriorityFeePerGas") final Wei maxPriorityFeePerGas, - @JsonProperty("maxFeePerGas") final Wei maxFeePerGas, - @JsonProperty("value") final Wei value, - @JsonDeserialize(using = HexStringDeserializer.class) @JsonProperty("data") final Bytes data, - @JsonDeserialize(using = HexStringDeserializer.class) @JsonProperty("input") - final Bytes input, - @JsonProperty("strict") final Boolean strict, - @JsonProperty("accessList") final List accessList, - @JsonProperty("maxFeePerBlobGas") final Wei maxFeePerBlobGas, - @JsonProperty("blobVersionedHashes") final List blobVersionedHashes) { + private JsonCallParameter( + final Address from, + final Address to, + final Long gasLimit, + final Wei gasPrice, + final Optional maxPriorityFeePerGas, + final Optional maxFeePerGas, + final Wei value, + final Bytes payload, + final Optional strict, + final Optional> accessList, + final Optional maxFeePerBlobGas, + final Optional> blobVersionedHashes) { super( from, to, - gasLimit != null ? gasLimit : -1L, + gasLimit, gasPrice, - Optional.ofNullable(maxPriorityFeePerGas), - Optional.ofNullable(maxFeePerGas), + maxPriorityFeePerGas, + maxFeePerGas, value, - Optional.ofNullable(input != null ? input : data).orElse(null), - Optional.ofNullable(accessList), - Optional.ofNullable(maxFeePerBlobGas), - Optional.ofNullable(blobVersionedHashes)); + payload, + accessList, + maxFeePerBlobGas, + blobVersionedHashes); - if (input != null && data != null && !input.equals(data)) { - throw new IllegalArgumentException("Only one of 'input' or 'data' should be provided"); - } - - this.strict = Optional.ofNullable(strict); + this.strict = strict; } public Optional isMaybeStrict() { @@ -92,4 +85,124 @@ public void logUnknownProperties(final String key, final Object value) { value, value.getClass()); } + + public static final class JsonCallParameterBuilder { + private Optional strict = Optional.empty(); + private Address from; + private Address to; + private long gasLimit = -1; + private Optional maxPriorityFeePerGas = Optional.empty(); + private Optional maxFeePerGas = Optional.empty(); + private Optional maxFeePerBlobGas = Optional.empty(); + private Wei gasPrice; + private Wei value; + private Bytes data; + private Bytes input; + private Optional> accessList = Optional.empty(); + private Optional> blobVersionedHashes = Optional.empty(); + + public JsonCallParameterBuilder() {} + + public JsonCallParameterBuilder withStrict(final Boolean strict) { + this.strict = Optional.ofNullable(strict); + return this; + } + + public JsonCallParameterBuilder withFrom(final Address from) { + this.from = from; + return this; + } + + public JsonCallParameterBuilder withTo(final Address to) { + this.to = to; + return this; + } + + @JsonDeserialize(using = GasDeserializer.class) + @JsonProperty("gas") + public JsonCallParameterBuilder withGasLimit(final Long gasLimit) { + this.gasLimit = Optional.ofNullable(gasLimit).orElse(-1L); + return this; + } + + public JsonCallParameterBuilder withMaxPriorityFeePerGas(final Wei maxPriorityFeePerGas) { + this.maxPriorityFeePerGas = Optional.ofNullable(maxPriorityFeePerGas); + return this; + } + + public JsonCallParameterBuilder withMaxFeePerGas(final Wei maxFeePerGas) { + this.maxFeePerGas = Optional.ofNullable(maxFeePerGas); + return this; + } + + public JsonCallParameterBuilder withMaxFeePerBlobGas(final Wei maxFeePerBlobGas) { + this.maxFeePerBlobGas = Optional.ofNullable(maxFeePerBlobGas); + return this; + } + + public JsonCallParameterBuilder withGasPrice(final Wei gasPrice) { + this.gasPrice = gasPrice; + return this; + } + + public JsonCallParameterBuilder withValue(final Wei value) { + this.value = value; + return this; + } + + @JsonDeserialize(using = HexStringDeserializer.class) + public JsonCallParameterBuilder withData(final Bytes data) { + this.data = data; + return this; + } + + @JsonDeserialize(using = HexStringDeserializer.class) + public JsonCallParameterBuilder withInput(final Bytes input) { + this.input = input; + return this; + } + + public JsonCallParameterBuilder withAccessList(final List accessList) { + this.accessList = Optional.ofNullable(accessList); + return this; + } + + public JsonCallParameterBuilder withBlobVersionedHashes( + final List blobVersionedHashes) { + this.blobVersionedHashes = Optional.ofNullable(blobVersionedHashes); + return this; + } + + @JsonAnySetter + @JsonDeserialize(using = IgnoreFieldDeserializer.class) + public void withUnknownProperties(final String key, final Object value) { + LOG.debug( + "unknown property - {} with value - {} and type - {} caught during serialization", + key, + value, + value.getClass()); + } + + public JsonCallParameter build() { + if (input != null && data != null && !input.equals(data)) { + throw new IllegalArgumentException("Only one of 'input' or 'data' should be provided"); + } + + final Bytes payload = input != null ? input : data; + + return new JsonCallParameter( + from, + to, + gasLimit, + gasPrice, + maxPriorityFeePerGas, + maxFeePerGas, + value, + payload, + strict, + accessList, + maxFeePerBlobGas, + blobVersionedHashes); + } + } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java index 261f8de505d..f4cb238b5aa 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java @@ -115,8 +115,7 @@ public void shouldReturnInternalErrorWhenProcessorReturnsEmpty() { @Test public void shouldAcceptRequestWhenMissingOptionalFields() { final JsonCallParameter callParameter = - new JsonCallParameter( - null, null, null, null, null, null, null, null, null, Boolean.FALSE, null, null, null); + new JsonCallParameter.JsonCallParameterBuilder().withStrict(Boolean.FALSE).build(); final JsonRpcRequestContext request = ethCallRequest(callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, Bytes.of().toString()); @@ -444,20 +443,16 @@ private JsonCallParameter callParameter() { private JsonCallParameter callParameter( final Wei gasPrice, final Wei maxFeesPerGas, final Wei maxPriorityFeesPerGas) { - return new JsonCallParameter( - Address.fromHexString("0x0"), - Address.fromHexString("0x0"), - 0L, - gasPrice, - maxFeesPerGas, - maxPriorityFeesPerGas, - Wei.ZERO, - Bytes.EMPTY, - null, - null, - null, - null, - null); + return new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x0")) + .withTo(Address.fromHexString("0x0")) + .withGasLimit(0L) + .withGasPrice(gasPrice) + .withMaxFeePerGas(maxFeesPerGas) + .withMaxPriorityFeePerGas(maxPriorityFeesPerGas) + .withValue(Wei.ZERO) + .withInput(Bytes.EMPTY) + .build(); } private JsonRpcRequestContext ethCallRequest( diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java index d23c10f23b4..b01a9147440 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java @@ -305,20 +305,15 @@ private void mockTransactionSimulatorResult( } private JsonCallParameter legacyTransactionCallParameter(final Wei gasPrice) { - return new JsonCallParameter( - Address.fromHexString("0x0"), - Address.fromHexString("0x0"), - 0L, - gasPrice, - null, - null, - Wei.ZERO, - Bytes.EMPTY, - null, - false, - null, - null, - null); + return new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x0")) + .withTo(Address.fromHexString("0x0")) + .withGasLimit(0L) + .withGasPrice(gasPrice) + .withValue(Wei.ZERO) + .withInput(Bytes.EMPTY) + .withStrict(Boolean.FALSE) + .build(); } private CallParameter eip1559TransactionCallParameter() { @@ -336,20 +331,17 @@ private CallParameter eip1559TransactionCallParameter( private JsonCallParameter eip1559TransactionCallParameter( final Optional gasPrice, final List accessListEntries) { - return new JsonCallParameter( - Address.fromHexString("0x0"), - Address.fromHexString("0x0"), - null, - gasPrice.orElse(null), - Wei.fromHexString("0x10"), - Wei.fromHexString("0x10"), - Wei.ZERO, - Bytes.EMPTY, - null, - false, - accessListEntries, - null, - null); + return new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x0")) + .withTo(Address.fromHexString("0x0")) + .withGasPrice(gasPrice.orElse(null)) + .withMaxFeePerGas(Wei.fromHexString("0x10")) + .withMaxPriorityFeePerGas(Wei.fromHexString("0x10")) + .withValue(Wei.ZERO) + .withInput(Bytes.EMPTY) + .withStrict(Boolean.FALSE) + .withAccessList(accessListEntries) + .build(); } private List createAccessList() { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java index aa52a31c1f9..388840fd69a 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java @@ -465,20 +465,15 @@ private JsonCallParameter defaultLegacyTransactionCallParameter(final Wei gasPri private JsonCallParameter legacyTransactionCallParameter( final Wei gasPrice, final boolean isStrict) { - return new JsonCallParameter( - Address.fromHexString("0x0"), - Address.fromHexString("0x0"), - 0L, - gasPrice, - null, - null, - Wei.ZERO, - Bytes.EMPTY, - null, - isStrict, - null, - null, - null); + return new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x0")) + .withTo(Address.fromHexString("0x0")) + .withGasLimit(0L) + .withGasPrice(gasPrice) + .withValue(Wei.ZERO) + .withInput(Bytes.EMPTY) + .withStrict(isStrict) + .build(); } private CallParameter modifiedLegacyTransactionCallParameter(final Wei gasPrice) { @@ -499,20 +494,16 @@ private CallParameter eip1559TransactionCallParameter() { } private JsonCallParameter eip1559TransactionCallParameter(final Optional gasPrice) { - return new JsonCallParameter( - Address.fromHexString("0x0"), - Address.fromHexString("0x0"), - null, - gasPrice.orElse(null), - Wei.fromHexString("0x10"), - Wei.fromHexString("0x10"), - Wei.ZERO, - Bytes.EMPTY, - null, - false, - null, - null, - null); + return new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x0")) + .withTo(Address.fromHexString("0x0")) + .withGasPrice(gasPrice.orElse(null)) + .withMaxPriorityFeePerGas(Wei.fromHexString("0x10")) + .withMaxFeePerGas(Wei.fromHexString("0x10")) + .withValue(Wei.ZERO) + .withInput(Bytes.EMPTY) + .withStrict(false) + .build(); } private CallParameter modifiedEip1559TransactionCallParameter() { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCallTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCallTest.java index 8456fa2847b..4be273f7258 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCallTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCallTest.java @@ -75,20 +75,13 @@ public void shouldReturnCorrectMethodName() { @Test public void shouldThrowInvalidJsonRpcParametersExceptionWhenMissingToField() { final JsonCallParameter callParameter = - new JsonCallParameter( - Address.fromHexString("0x0"), - null, - 0L, - Wei.ZERO, - null, - null, - Wei.ZERO, - Bytes.EMPTY, - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x0")) + .withGasLimit(0L) + .withGasPrice(Wei.ZERO) + .withValue(Wei.ZERO) + .withInput(Bytes.EMPTY) + .build(); final JsonRpcRequestContext request = ethCallRequest(privacyGroupId, callParameter, "latest"); final Throwable thrown = catchThrowable(() -> method.response(request)); @@ -113,20 +106,9 @@ public void shouldReturnNullWhenProcessorReturnsEmpty() { @Test public void shouldAcceptRequestWhenMissingOptionalFields() { final JsonCallParameter callParameter = - new JsonCallParameter( - null, - Address.fromHexString("0x0"), - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null); + new JsonCallParameter.JsonCallParameterBuilder() + .withTo(Address.fromHexString("0x0")) + .build(); final JsonRpcRequestContext request = ethCallRequest(privacyGroupId, callParameter, "latest"); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, Bytes.of().toString()); @@ -196,20 +178,14 @@ public void shouldThrowCorrectExceptionWhenNoPrivacyGroupSpecified() { } private JsonCallParameter callParameter() { - return new JsonCallParameter( - Address.fromHexString("0x0"), - Address.fromHexString("0x0"), - 0L, - Wei.ZERO, - null, - null, - Wei.ZERO, - Bytes.EMPTY, - null, - null, - null, - null, - null); + return new JsonCallParameter.JsonCallParameterBuilder() + .withFrom(Address.fromHexString("0x0")) + .withTo(Address.fromHexString("0x0")) + .withGasLimit(0L) + .withGasPrice(Wei.ZERO) + .withValue(Wei.ZERO) + .withInput(Bytes.EMPTY) + .build(); } private JsonRpcRequestContext ethCallRequest( From 034388b7d434452a998bc35e48b0818c48b5156a Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Mon, 15 Jul 2024 18:57:45 +1000 Subject: [PATCH 03/11] fix: Remove deserializer which is not required anymore Signed-off-by: Usman Saleem --- .../parameters/JsonCallParameter.java | 24 +++++++------- .../parameters/JsonCallParameterTest.java | 5 +-- .../core/json/IgnoreFieldDeserializer.java | 31 ------------------- 3 files changed, 14 insertions(+), 46 deletions(-) delete mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/json/IgnoreFieldDeserializer.java diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java index 5d183a83d56..ba2b750e9f7 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java @@ -20,7 +20,6 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.json.GasDeserializer; import org.hyperledger.besu.ethereum.core.json.HexStringDeserializer; -import org.hyperledger.besu.ethereum.core.json.IgnoreFieldDeserializer; import org.hyperledger.besu.ethereum.transaction.CallParameter; import java.util.List; @@ -34,6 +33,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * This class is used to deserialize JSON parameters for a call to the JSON-RPC method eth_call. + */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(builder = JsonCallParameter.JsonCallParameterBuilder.class) public class JsonCallParameter extends CallParameter { @@ -72,20 +74,17 @@ private JsonCallParameter( this.strict = strict; } + /** + * Returns whether the call should be executed in strict mode. + * @return Optional strict mode flag + */ public Optional isMaybeStrict() { return strict; } - @JsonAnySetter - @JsonDeserialize(using = IgnoreFieldDeserializer.class) - public void logUnknownProperties(final String key, final Object value) { - LOG.debug( - "unknown property - {} with value - {} and type - {} caught during serialization", - key, - value, - value.getClass()); - } - + /** + * Builder for {@link JsonCallParameter}. Used by Jackson to deserialize {@code JsonCallParameter}. + */ public static final class JsonCallParameterBuilder { private Optional strict = Optional.empty(); private Address from; @@ -174,13 +173,12 @@ public JsonCallParameterBuilder withBlobVersionedHashes( } @JsonAnySetter - @JsonDeserialize(using = IgnoreFieldDeserializer.class) public void withUnknownProperties(final String key, final Object value) { LOG.debug( "unknown property - {} with value - {} and type - {} caught during serialization", key, value, - value.getClass()); + value != null ? value.getClass() : "NULL"); } public JsonCallParameter build() { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java index f2bbae4bbee..5a77f847a90 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java @@ -39,12 +39,13 @@ public void acceptsAndCapMaxValueForGas() throws JsonProcessingException { } @Test - public void extraParameterIsIgnored() throws JsonProcessingException { + public void extraParametersAreIgnoredIgnored() throws JsonProcessingException { final String json = """ { "gas": "0x96", - "gasLimit": "0xfa" + "gasLimit": "0xfa", + "extraField": "extra" } """; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/json/IgnoreFieldDeserializer.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/json/IgnoreFieldDeserializer.java deleted file mode 100644 index 7200dd650cb..00000000000 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/json/IgnoreFieldDeserializer.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright contributors to Hyperledger Besu. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.core.json; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JacksonException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; - -public class IgnoreFieldDeserializer extends JsonDeserializer { - @Override - public Object deserialize( - final JsonParser jsonParser, final DeserializationContext deserializationContext) - throws IOException, JacksonException { - return null; - } -} From 0d5c2a1ca5d620d69923f74ba3a148f63367e129 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Mon, 15 Jul 2024 19:11:28 +1000 Subject: [PATCH 04/11] javadoc Signed-off-by: Usman Saleem --- .../parameters/JsonCallParameter.java | 164 +++++++++++++++++- 1 file changed, 162 insertions(+), 2 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java index ba2b750e9f7..df50e226a46 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java @@ -34,7 +34,34 @@ import org.slf4j.LoggerFactory; /** - * This class is used to deserialize JSON parameters for a call to the JSON-RPC method eth_call. + * This class is used to deserialize JSON parameters for a call to the JSON-RPC method eth_call. It + * extends {@link CallParameter} by adding support for JSON-specific fields such as strict mode, + * access lists, and blob versioned hashes. It also handles unknown JSON properties gracefully. + * + *

To build an instance of this class, use the {@link JsonCallParameterBuilder}: + * + *

{@code
+ * JsonCallParameter param = new JsonCallParameter.JsonCallParameterBuilder()
+ *     .withFrom(Address.fromHexString("0x..."))
+ *     .withTo(Address.fromHexString("0x..."))
+ *     .withGasLimit(21000L)
+ *     .withGasPrice(Wei.of(1000000000L))
+ *     .withValue(Wei.ZERO)
+ *     .withInput(Bytes.fromHexString("0x..."))
+ *     .withStrict(true) // Optional
+ *     .withAccessList(accessList) // Optional
+ *     .withMaxFeePerGas(Wei.of(2)) // Optional
+ *     .withMaxPriorityFeePerGas(Wei.of(1)) // Optional
+ *     .withMaxFeePerBlobGas(Wei.of(3)) // Optional
+ *     .withBlobVersionedHashes(blobVersionedHashes) // Optional
+ *     .build();
+ * }
+ * + *

Note: Only one of 'data' or 'input' should be provided to the builder. If both are provided + * and their values differ, an {@link IllegalArgumentException} is thrown. + * + *

Unknown JSON properties encountered during deserialization are logged but do not affect the + * deserialization process, allowing for flexibility in JSON formats. */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonDeserialize(builder = JsonCallParameter.JsonCallParameterBuilder.class) @@ -76,6 +103,7 @@ private JsonCallParameter( /** * Returns whether the call should be executed in strict mode. + * * @return Optional strict mode flag */ public Optional isMaybeStrict() { @@ -83,7 +111,8 @@ public Optional isMaybeStrict() { } /** - * Builder for {@link JsonCallParameter}. Used by Jackson to deserialize {@code JsonCallParameter}. + * Builder for {@link JsonCallParameter}. Used by Jackson to deserialize {@code + * JsonCallParameter}. */ public static final class JsonCallParameterBuilder { private Optional strict = Optional.empty(); @@ -100,23 +129,57 @@ public static final class JsonCallParameterBuilder { private Optional> accessList = Optional.empty(); private Optional> blobVersionedHashes = Optional.empty(); + /** Default constructor. */ public JsonCallParameterBuilder() {} + /** + * Sets the strict mode for the {@link JsonCallParameter}. If strict mode is enabled, the call + * will be executed with stricter validation rules. This is optional and defaults to not being + * in strict mode if not specified. + * + * @param strict the strict mode flag, can be {@code null} to indicate the absence of a strict + * mode preference + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ public JsonCallParameterBuilder withStrict(final Boolean strict) { this.strict = Optional.ofNullable(strict); return this; } + /** + * Sets the "from" address for the {@link JsonCallParameter}. This address represents the sender + * of the call. + * + * @param from the sender's address + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ public JsonCallParameterBuilder withFrom(final Address from) { this.from = from; return this; } + /** + * Sets the "to" address for the {@link JsonCallParameter}. This address represents the + * recipient of the call. + * + * @param to the recipient's address + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ public JsonCallParameterBuilder withTo(final Address to) { this.to = to; return this; } + /** + * Sets the gas limit for the {@link JsonCallParameter}. The gas limit specifies the maximum + * amount of gas that the call is allowed to consume. If the actual gas consumed exceeds this + * limit, the call is reverted. By default, if not specified, the gas limit is set to -1, + * indicating that it is not set. + * + * @param gasLimit the gas limit for the call, can be {@code null} to indicate that the gas + * limit is not set + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ @JsonDeserialize(using = GasDeserializer.class) @JsonProperty("gas") public JsonCallParameterBuilder withGasLimit(final Long gasLimit) { @@ -124,54 +187,141 @@ public JsonCallParameterBuilder withGasLimit(final Long gasLimit) { return this; } + /** + * Sets the maximum priority fee per gas for the {@link JsonCallParameter}. This fee is used to + * incentivize miners to include the transaction in a block. It is an optional parameter, and if + * not specified, it defaults to an empty {@link Optional}. + * + * @param maxPriorityFeePerGas the maximum priority fee per gas, can be {@code null} to indicate + * no preference + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ public JsonCallParameterBuilder withMaxPriorityFeePerGas(final Wei maxPriorityFeePerGas) { this.maxPriorityFeePerGas = Optional.ofNullable(maxPriorityFeePerGas); return this; } + /** + * Sets the maximum fee per gas for the {@link JsonCallParameter}. This fee represents the + * maximum amount of gas that the sender is willing to pay. It is an optional parameter, and if + * not specified, it defaults to an empty {@link Optional}. + * + * @param maxFeePerGas the maximum fee per gas, can be {@code null} to indicate no preference + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ public JsonCallParameterBuilder withMaxFeePerGas(final Wei maxFeePerGas) { this.maxFeePerGas = Optional.ofNullable(maxFeePerGas); return this; } + /** + * Sets the maximum fee per blob gas for the {@link JsonCallParameter}. This fee is specific to + * certain types of transactions and is an optional parameter. If not specified, it defaults to + * an empty {@link Optional}. + * + * @param maxFeePerBlobGas the maximum fee per blob gas, can be {@code null} to indicate no + * preference + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ public JsonCallParameterBuilder withMaxFeePerBlobGas(final Wei maxFeePerBlobGas) { this.maxFeePerBlobGas = Optional.ofNullable(maxFeePerBlobGas); return this; } + /** + * Sets the gas price for the {@link JsonCallParameter}. The gas price is used to calculate the + * transaction fee as the product of gas price and gas used. It is an optional parameter, and if + * not specified, it defaults to the network's current gas price. + * + * @param gasPrice the gas price, can be {@code null} to indicate that the network's current gas + * price should be used + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ public JsonCallParameterBuilder withGasPrice(final Wei gasPrice) { this.gasPrice = gasPrice; return this; } + /** + * Sets the value to be transferred with the call for the {@link JsonCallParameter}. This value + * is the amount of Wei to be transferred from the sender to the recipient. It is an optional + * parameter, and if not specified, it defaults to 0, indicating that no value is transferred. + * + * @param value the value to be transferred, can be {@code null} to indicate no value is + * transferred + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ public JsonCallParameterBuilder withValue(final Wei value) { this.value = value; return this; } + /** + * Sets the data for the {@link JsonCallParameter}. This data represents the payload of the + * call. Note: Only one of 'data' or 'input' should be provided. If both are provided and their + * values differ, an exception will be thrown during the build process. + * + * @param data the payload data + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ @JsonDeserialize(using = HexStringDeserializer.class) public JsonCallParameterBuilder withData(final Bytes data) { this.data = data; return this; } + /** + * Sets the input for the {@link JsonCallParameter}. This input is an alternative representation + * of the payload for the call. Note: Only one of 'input' or 'data' should be provided. If both + * are provided and their values differ, an exception will be thrown during the build process. + * + * @param input the payload input + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ @JsonDeserialize(using = HexStringDeserializer.class) public JsonCallParameterBuilder withInput(final Bytes input) { this.input = input; return this; } + /** + * Sets the access list for the {@link JsonCallParameter}. The access list is a list of + * addresses and storage keys that the transaction plans to access. This is an optional + * parameter, and if not specified, it defaults to an empty {@link Optional}. + * + * @param accessList the access list, can be {@code null} to indicate no access list is provided + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ public JsonCallParameterBuilder withAccessList(final List accessList) { this.accessList = Optional.ofNullable(accessList); return this; } + /** + * Sets the blob versioned hashes for the {@link JsonCallParameter}. This is a list of versioned + * hashes related to blob transactions, allowing for more complex transaction types. It is an + * optional parameter, and if not specified, it defaults to an empty {@link Optional}. + * + * @param blobVersionedHashes the list of versioned hashes, can be {@code null} to indicate no + * versioned hashes are provided + * @return the {@link JsonCallParameterBuilder} instance for chaining + */ public JsonCallParameterBuilder withBlobVersionedHashes( final List blobVersionedHashes) { this.blobVersionedHashes = Optional.ofNullable(blobVersionedHashes); return this; } + /** + * Handles unknown JSON properties during deserialization. This method is invoked when an + * unknown property is encountered in the JSON being deserialized into a {@link + * JsonCallParameter} object. It logs the unknown property's key, value, and the value's type if + * the value is not null. This allows for flexibility in JSON formats and aids in debugging + * issues related to unexpected properties. + * + * @param key the key of the unknown property + * @param value the value of the unknown property, which can be any type + */ @JsonAnySetter public void withUnknownProperties(final String key, final Object value) { LOG.debug( @@ -181,6 +331,16 @@ public void withUnknownProperties(final String key, final Object value) { value != null ? value.getClass() : "NULL"); } + /** + * Builds a {@link JsonCallParameter} instance based on the provided parameters. This method + * also validates that only one of 'input' or 'data' is provided. If both are provided and their + * values differ, an {@link IllegalArgumentException} is thrown. This ensures the integrity of + * the payload data for the call. + * + * @return a new {@link JsonCallParameter} instance with the specified configuration + * @throws IllegalArgumentException if both 'input' and 'data' are provided and their values are + * not equal + */ public JsonCallParameter build() { if (input != null && data != null && !input.equals(data)) { throw new IllegalArgumentException("Only one of 'input' or 'data' should be provided"); From f2c1e7b20a23032a2989329ce6fac5d1dd9e08e2 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Mon, 15 Jul 2024 19:47:29 +1000 Subject: [PATCH 05/11] fix(test): Fix expected exception message Signed-off-by: Usman Saleem --- .../api/jsonrpc/internal/methods/EthCreateAccessListTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java index b01a9147440..62861272864 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java @@ -142,7 +142,7 @@ public void shouldReturnGasEstimateErrorWhenGasPricePresentForEip1559Transaction Assertions.assertThatThrownBy(() -> method.response(request)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("gasPrice cannot be used with baseFee or maxFeePerGas"); + .hasMessageContaining("gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas"); } @Test From e237bdeebd7492e51267daa2b1832b6f3de9abc3 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Mon, 15 Jul 2024 19:57:56 +1000 Subject: [PATCH 06/11] changelog Signed-off-by: Usman Saleem --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70714d2055e..f1c91e554ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - implement gnark-crypto for eip-2537 [#7316](https://github.com/hyperledger/besu/pull/7316) ### Bug fixes +- Fix `eth_call` deserialization to correctly ignore unknown fields in the transaction object. [#7323](https://github.com/hyperledger/besu/pull/7323) ## 24.7.0 From 37517e1d922a5dab2d96828a8c195bd1e7816de3 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Mon, 15 Jul 2024 20:28:34 +1000 Subject: [PATCH 07/11] add additional unit tests Signed-off-by: Usman Saleem --- .../parameters/JsonCallParameterTest.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java index 5a77f847a90..ac065dc98ec 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java @@ -15,9 +15,12 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; public class JsonCallParameterTest { @@ -38,6 +41,64 @@ public void acceptsAndCapMaxValueForGas() throws JsonProcessingException { assertThat(callParameter.getGasLimit()).isEqualTo(Long.MAX_VALUE); } + @Test + public void dataAsPayLoad() throws JsonProcessingException { + final String json = + """ + { + "data": "0x1234" + } + """; + + final JsonCallParameter callParameter = objectMapper.readValue(json, JsonCallParameter.class); + + assertThat(callParameter.getPayload()).isEqualTo(Bytes.fromHexString("0x1234")); + } + + @Test + public void inputAsPayLoad() throws JsonProcessingException { + final String json = + """ + { + "input": "0x1234" + } + """; + + final JsonCallParameter callParameter = objectMapper.readValue(json, JsonCallParameter.class); + + assertThat(callParameter.getPayload()).isEqualTo(Bytes.fromHexString("0x1234")); + } + + @Test + public void inputAndDataWithSameValueAsPayLoad() throws JsonProcessingException { + final String json = + """ + { + "input": "0x1234", + "data": "0x1234" + } + """; + + final JsonCallParameter callParameter = objectMapper.readValue(json, JsonCallParameter.class); + + assertThat(callParameter.getPayload()).isEqualTo(Bytes.fromHexString("0x1234")); + } + + @Test + public void inputAndDataWithDifferentValueAsPayLoadCauseException() { + final String json = + """ + { + "input": "0x1234", + "data": "0x1235" + } + """; + + assertThatExceptionOfType(JsonMappingException.class) + .isThrownBy(() -> objectMapper.readValue(json, JsonCallParameter.class)) + .withMessageContaining("problem: Only one of 'input' or 'data' should be provided"); + } + @Test public void extraParametersAreIgnoredIgnored() throws JsonProcessingException { final String json = From 343ec7c464bd10ab7bd89ee0cab641a69131f862 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Mon, 15 Jul 2024 21:20:21 +1000 Subject: [PATCH 08/11] fix(test): Fix unit test Signed-off-by: Usman Saleem --- .../api/jsonrpc/internal/methods/EthEstimateGasTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java index 388840fd69a..291e1844853 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java @@ -167,7 +167,7 @@ public void shouldReturnGasEstimateErrorWhenGasPricePresentForEip1559Transaction mockTransientProcessorResultGasEstimate(1L, false, false); Assertions.assertThatThrownBy(() -> method.response(request)) .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessageContaining("gasPrice cannot be used with baseFee or maxFeePerGas"); + .hasMessageContaining("gasPrice cannot be used with maxFeePerGas or maxPriorityFeePerGas"); } @Test From 868eb9fd379e93d194b18025f68e8ebddd077af0 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Tue, 16 Jul 2024 12:50:37 +1000 Subject: [PATCH 09/11] fix: Update builder to withGas to match the json eth_call Signed-off-by: Usman Saleem --- .../fork/frontier/EthCallIntegrationTest.java | 2 +- .../EthCreateAccessListIntegrationTest.java | 4 ++-- .../frontier/EthEstimateGasIntegrationTest.java | 6 +++--- .../internal/parameters/JsonCallParameter.java | 14 ++++++-------- .../api/jsonrpc/internal/methods/EthCallTest.java | 2 +- .../internal/methods/EthCreateAccessListTest.java | 2 +- .../internal/methods/EthEstimateGasTest.java | 2 +- .../internal/parameters/JsonCallParameterTest.java | 1 + .../privacy/methods/priv/PrivCallTest.java | 4 ++-- 9 files changed, 18 insertions(+), 19 deletions(-) diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCallIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCallIntegrationTest.java index a05b6786ced..886f7bc0158 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCallIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCallIntegrationTest.java @@ -126,7 +126,7 @@ public void shouldReturnErrorWithGasLimitTooLow() { new JsonCallParameter.JsonCallParameterBuilder() .withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) .withTo(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) - .withGasLimit(0L) + .withGas(0L) .withInput(Bytes.fromHexString("0x12a7b914")) .build(); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCreateAccessListIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCreateAccessListIntegrationTest.java index a50e2677f5b..49b9659fd9d 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCreateAccessListIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthCreateAccessListIntegrationTest.java @@ -197,7 +197,7 @@ public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpec final JsonCallParameter callParameter = new JsonCallParameter.JsonCallParameterBuilder() .withFrom(Address.fromHexString("0x0000000000000000000000000000000000000000")) - .withGasLimit(1L) + .withGas(1L) .withGasPrice(Wei.fromHexString("0x9999999999")) .withInput( Bytes.fromHexString( @@ -217,7 +217,7 @@ public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpec @Test public void shouldReturnExpectedValueForInsufficientGas() { final JsonCallParameter callParameter = - new JsonCallParameter.JsonCallParameterBuilder().withGasLimit(1L).build(); + new JsonCallParameter.JsonCallParameterBuilder().withGas(1L).build(); final JsonRpcRequestContext request = requestWithParams(callParameter); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0xcf08)); diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java index 6ab89808d4f..d17a2774e6c 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/fork/frontier/EthEstimateGasIntegrationTest.java @@ -115,7 +115,7 @@ public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpec final JsonCallParameter callParameter = new JsonCallParameter.JsonCallParameterBuilder() .withFrom(Address.fromHexString("0x0000000000000000000000000000000000000000")) - .withGasLimit(1L) + .withGas(1L) .withGasPrice(Wei.fromHexString("0x9999999999")) .withInput( Bytes.fromHexString( @@ -136,7 +136,7 @@ public void shouldNotIgnoreSenderBalanceAccountWhenStrictModeDisabledAndThrowErr final JsonCallParameter callParameter = new JsonCallParameter.JsonCallParameterBuilder() .withFrom(Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f")) - .withGasLimit(1L) + .withGas(1L) .withGasPrice(Wei.fromHexString("0x9999999999")) .withInput( Bytes.fromHexString( @@ -159,7 +159,7 @@ public void shouldNotIgnoreSenderBalanceAccountWhenStrictModeDisabledAndThrowErr @Test public void shouldReturnExpectedValueForInsufficientGas() { final JsonCallParameter callParameter = - new JsonCallParameter.JsonCallParameterBuilder().withGasLimit(1L).build(); + new JsonCallParameter.JsonCallParameterBuilder().withGas(1L).build(); final JsonRpcRequestContext request = requestWithParams(callParameter); final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, "0x5208"); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java index df50e226a46..1a73f084a8a 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java @@ -27,7 +27,6 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.apache.tuweni.bytes.Bytes; import org.slf4j.Logger; @@ -118,7 +117,7 @@ public static final class JsonCallParameterBuilder { private Optional strict = Optional.empty(); private Address from; private Address to; - private long gasLimit = -1; + private long gas = -1; private Optional maxPriorityFeePerGas = Optional.empty(); private Optional maxFeePerGas = Optional.empty(); private Optional maxFeePerBlobGas = Optional.empty(); @@ -176,14 +175,13 @@ public JsonCallParameterBuilder withTo(final Address to) { * limit, the call is reverted. By default, if not specified, the gas limit is set to -1, * indicating that it is not set. * - * @param gasLimit the gas limit for the call, can be {@code null} to indicate that the gas - * limit is not set + * @param gas the gas limit for the call, can be {@code null} to indicate that the gas limit is + * not set * @return the {@link JsonCallParameterBuilder} instance for chaining */ @JsonDeserialize(using = GasDeserializer.class) - @JsonProperty("gas") - public JsonCallParameterBuilder withGasLimit(final Long gasLimit) { - this.gasLimit = Optional.ofNullable(gasLimit).orElse(-1L); + public JsonCallParameterBuilder withGas(final Long gas) { + this.gas = Optional.ofNullable(gas).orElse(-1L); return this; } @@ -351,7 +349,7 @@ public JsonCallParameter build() { return new JsonCallParameter( from, to, - gasLimit, + gas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java index f4cb238b5aa..7570fe342c2 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java @@ -446,7 +446,7 @@ private JsonCallParameter callParameter( return new JsonCallParameter.JsonCallParameterBuilder() .withFrom(Address.fromHexString("0x0")) .withTo(Address.fromHexString("0x0")) - .withGasLimit(0L) + .withGas(0L) .withGasPrice(gasPrice) .withMaxFeePerGas(maxFeesPerGas) .withMaxPriorityFeePerGas(maxPriorityFeesPerGas) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java index 62861272864..8812a1e0a6a 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCreateAccessListTest.java @@ -308,7 +308,7 @@ private JsonCallParameter legacyTransactionCallParameter(final Wei gasPrice) { return new JsonCallParameter.JsonCallParameterBuilder() .withFrom(Address.fromHexString("0x0")) .withTo(Address.fromHexString("0x0")) - .withGasLimit(0L) + .withGas(0L) .withGasPrice(gasPrice) .withValue(Wei.ZERO) .withInput(Bytes.EMPTY) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java index 291e1844853..a6f5008b29e 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java @@ -468,7 +468,7 @@ private JsonCallParameter legacyTransactionCallParameter( return new JsonCallParameter.JsonCallParameterBuilder() .withFrom(Address.fromHexString("0x0")) .withTo(Address.fromHexString("0x0")) - .withGasLimit(0L) + .withGas(0L) .withGasPrice(gasPrice) .withValue(Wei.ZERO) .withInput(Bytes.EMPTY) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java index ac065dc98ec..fc5b9349290 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java @@ -101,6 +101,7 @@ public void inputAndDataWithDifferentValueAsPayLoadCauseException() { @Test public void extraParametersAreIgnoredIgnored() throws JsonProcessingException { + //0x96 = 150 final String json = """ { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCallTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCallTest.java index 4be273f7258..0919ea48e92 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCallTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/priv/PrivCallTest.java @@ -77,7 +77,7 @@ public void shouldThrowInvalidJsonRpcParametersExceptionWhenMissingToField() { final JsonCallParameter callParameter = new JsonCallParameter.JsonCallParameterBuilder() .withFrom(Address.fromHexString("0x0")) - .withGasLimit(0L) + .withGas(0L) .withGasPrice(Wei.ZERO) .withValue(Wei.ZERO) .withInput(Bytes.EMPTY) @@ -181,7 +181,7 @@ private JsonCallParameter callParameter() { return new JsonCallParameter.JsonCallParameterBuilder() .withFrom(Address.fromHexString("0x0")) .withTo(Address.fromHexString("0x0")) - .withGasLimit(0L) + .withGas(0L) .withGasPrice(Wei.ZERO) .withValue(Wei.ZERO) .withInput(Bytes.EMPTY) From 4f04a6b511f092e390833a0c4443c1dcca6ab93c Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Tue, 16 Jul 2024 12:55:37 +1000 Subject: [PATCH 10/11] spotless fix Signed-off-by: Usman Saleem --- .../api/jsonrpc/internal/parameters/JsonCallParameterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java index fc5b9349290..ea1191a1fc2 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java @@ -101,7 +101,7 @@ public void inputAndDataWithDifferentValueAsPayLoadCauseException() { @Test public void extraParametersAreIgnoredIgnored() throws JsonProcessingException { - //0x96 = 150 + // 0x96 = 150 final String json = """ { From ccba20e70b8813395ed9a01274ec00602fad94a0 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Tue, 16 Jul 2024 15:20:34 +1000 Subject: [PATCH 11/11] fix javadoc Signed-off-by: Usman Saleem --- .../internal/parameters/JsonCallParameter.java | 11 +++++------ .../internal/parameters/JsonCallParameterTest.java | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java index 1a73f084a8a..987b68c2e2f 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameter.java @@ -43,7 +43,7 @@ * JsonCallParameter param = new JsonCallParameter.JsonCallParameterBuilder() * .withFrom(Address.fromHexString("0x...")) * .withTo(Address.fromHexString("0x...")) - * .withGasLimit(21000L) + * .withGas(21000L) * .withGasPrice(Wei.of(1000000000L)) * .withValue(Wei.ZERO) * .withInput(Bytes.fromHexString("0x...")) @@ -159,7 +159,7 @@ public JsonCallParameterBuilder withFrom(final Address from) { /** * Sets the "to" address for the {@link JsonCallParameter}. This address represents the - * recipient of the call. + * recipient of the call. It can be null for contract creation transactions. * * @param to the recipient's address * @return the {@link JsonCallParameterBuilder} instance for chaining @@ -170,10 +170,9 @@ public JsonCallParameterBuilder withTo(final Address to) { } /** - * Sets the gas limit for the {@link JsonCallParameter}. The gas limit specifies the maximum - * amount of gas that the call is allowed to consume. If the actual gas consumed exceeds this - * limit, the call is reverted. By default, if not specified, the gas limit is set to -1, - * indicating that it is not set. + * Sets the gas for the {@link JsonCallParameter} used for transaction execution. eth_call uses + * 0 gas but this parameter may be needed by some executions. By default, if not specified, the + * gas is set to -1, indicating that it is not set. * * @param gas the gas limit for the call, can be {@code null} to indicate that the gas limit is * not set diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java index ea1191a1fc2..97d7feeeb13 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/JsonCallParameterTest.java @@ -100,7 +100,7 @@ public void inputAndDataWithDifferentValueAsPayLoadCauseException() { } @Test - public void extraParametersAreIgnoredIgnored() throws JsonProcessingException { + public void extraParametersAreIgnored() throws JsonProcessingException { // 0x96 = 150 final String json = """