Skip to content

Commit

Permalink
fix: Update builder to withGas to match the json eth_call
Browse files Browse the repository at this point in the history
Signed-off-by: Usman Saleem <[email protected]>
  • Loading branch information
usmansaleem committed Jul 16, 2024
1 parent 343ec7c commit 868eb9f
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +117,7 @@ public static final class JsonCallParameterBuilder {
private Optional<Boolean> strict = Optional.empty();
private Address from;
private Address to;
private long gasLimit = -1;
private long gas = -1;
private Optional<Wei> maxPriorityFeePerGas = Optional.empty();
private Optional<Wei> maxFeePerGas = Optional.empty();
private Optional<Wei> maxFeePerBlobGas = Optional.empty();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -351,7 +349,7 @@ public JsonCallParameter build() {
return new JsonCallParameter(
from,
to,
gasLimit,
gas,
gasPrice,
maxPriorityFeePerGas,
maxFeePerGas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void inputAndDataWithDifferentValueAsPayLoadCauseException() {

@Test
public void extraParametersAreIgnoredIgnored() throws JsonProcessingException {
//0x96 = 150
final String json =
"""
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 868eb9f

Please sign in to comment.