Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for chainId and EIP-1559 fee market in linea_estimateGas #94

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ protected void assertMinGasPriceLowerBound(final Wei baseFee, final Wei estimate
public void lineaEstimateGasPriorityFeeMinGasPriceLowerBound() {
final Account sender = accounts.getSecondaryBenefactor();

final CallParams callParams = new CallParams(sender.getAddress(), null, "", "", "0", null);
final CallParams callParams =
new CallParams(null, sender.getAddress(), null, "", "", "0", null, null, null);

final var reqLinea = new LineaEstimateGasRequest(callParams);
final var respLinea = reqLinea.execute(minerNode.nodeRequests()).getResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ public void estimateGasFailsForExceedingModuleLineCountTest() throws Exception {

final EstimateGasTest.CallParams callParams =
new EstimateGasTest.CallParams(
null,
sender.getAddress(),
simpleStorage.getContractAddress(),
null,
payload.toHexString(),
"0",
null,
null,
null);

final var reqLinea = new EstimateGasTest.BadLineaEstimateGasRequest(callParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package linea.plugin.acc.test.rpc.linea;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
Expand All @@ -27,6 +28,7 @@
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import linea.plugin.acc.test.LineaPluginTestBase;
import linea.plugin.acc.test.TestCommandLineOptionsBuilder;
import linea.plugin.acc.test.tests.web3j.generated.SimpleStorage;
Expand Down Expand Up @@ -95,7 +97,15 @@ public void lineaEstimateGasMatchesEthEstimateGas() {

final CallParams callParams =
new CallParams(
sender.getAddress(), sender.getAddress(), null, Bytes.EMPTY.toHexString(), "0", null);
null,
sender.getAddress(),
sender.getAddress(),
null,
Bytes.EMPTY.toHexString(),
"0",
null,
null,
null);

final var reqEth = new RawEstimateGasRequest(callParams);
final var reqLinea = new LineaEstimateGasRequest(callParams);
Expand All @@ -111,12 +121,84 @@ public void passingGasPriceFieldWorks() {

final CallParams callParams =
new CallParams(
null,
sender.getAddress(),
sender.getAddress(),
null,
Bytes.EMPTY.toHexString(),
"0",
"0x1234");
"0x1234",
null,
null);

final var reqLinea = new LineaEstimateGasRequest(callParams);
final var respLinea = reqLinea.execute(minerNode.nodeRequests());
assertThat(respLinea.hasError()).isFalse();
assertThat(respLinea.getResult()).isNotNull();
}

@Test
public void passingChainIdFieldWorks() {

final Account sender = accounts.getSecondaryBenefactor();

final CallParams callParams =
new CallParams(
"0x539",
sender.getAddress(),
sender.getAddress(),
null,
Bytes.EMPTY.toHexString(),
"0",
"0x1234",
null,
null);

final var reqLinea = new LineaEstimateGasRequest(callParams);
final var respLinea = reqLinea.execute(minerNode.nodeRequests());
assertThat(respLinea.hasError()).isFalse();
assertThat(respLinea.getResult()).isNotNull();
}

@Test
public void passingEIP1559FieldsWorks() {

final Account sender = accounts.getSecondaryBenefactor();

final CallParams callParams =
new CallParams(
null,
sender.getAddress(),
sender.getAddress(),
null,
Bytes.EMPTY.toHexString(),
"0",
null,
"0x1234",
"0x1");

final var reqLinea = new LineaEstimateGasRequest(callParams);
final var respLinea = reqLinea.execute(minerNode.nodeRequests());
assertThat(respLinea.hasError()).isFalse();
assertThat(respLinea.getResult()).isNotNull();
}

@Test
public void passingChainIdAndEIP1559FieldsWorks() {

final Account sender = accounts.getSecondaryBenefactor();

final CallParams callParams =
new CallParams(
"0x539",
sender.getAddress(),
sender.getAddress(),
null,
Bytes.EMPTY.toHexString(),
"0",
null,
"0x1234",
null);

final var reqLinea = new LineaEstimateGasRequest(callParams);
final var respLinea = reqLinea.execute(minerNode.nodeRequests());
Expand All @@ -135,12 +217,15 @@ public void passingStateOverridesWorks() {

final CallParams callParams =
new CallParams(
"0x539",
sender.getAddress(),
sender.getAddress(),
"1",
Bytes.EMPTY.toHexString(),
"0",
"0x1234");
"0x1234",
null,
null);

final var zeroBalance = Map.of("balance", Wei.ZERO.toHexString());

Expand Down Expand Up @@ -172,7 +257,15 @@ public void lineaEstimateGasIsProfitable() {

final CallParams callParams =
new CallParams(
sender.getAddress(), sender.getAddress(), null, payload.toHexString(), "0", null);
null,
sender.getAddress(),
sender.getAddress(),
null,
payload.toHexString(),
"0",
null,
null,
null);

final var reqLinea = new LineaEstimateGasRequest(callParams);
final var respLinea = reqLinea.execute(minerNode.nodeRequests()).getResult();
Expand Down Expand Up @@ -223,7 +316,16 @@ protected void assertIsProfitable(
public void invalidParametersLineaEstimateGasRequestReturnErrorResponse() {
final Account sender = accounts.getSecondaryBenefactor();
final CallParams callParams =
new CallParams(sender.getAddress(), null, "", "", String.valueOf(Integer.MAX_VALUE), null);
new CallParams(
null,
sender.getAddress(),
null,
"",
"",
String.valueOf(Integer.MAX_VALUE),
null,
null,
null);
final var reqLinea = new BadLineaEstimateGasRequest(callParams);
final var respLinea = reqLinea.execute(minerNode.nodeRequests());
assertThat(respLinea.getCode()).isEqualTo(RpcErrorType.INVALID_PARAMS.getCode());
Expand All @@ -237,7 +339,15 @@ public void revertedTransactionReturnErrorResponse() throws Exception {
final var reqLinea =
new BadLineaEstimateGasRequest(
new CallParams(
sender.getAddress(), simpleStorage.getContractAddress(), "", "", "0", null));
null,
sender.getAddress(),
simpleStorage.getContractAddress(),
"",
"",
"0",
null,
null,
null));
final var respLinea = reqLinea.execute(minerNode.nodeRequests());
assertThat(respLinea.getCode()).isEqualTo(-32000);
assertThat(respLinea.getMessage()).isEqualTo("Execution reverted");
Expand All @@ -250,11 +360,14 @@ public void failedTransactionReturnErrorResponse() {
final var reqLinea =
new BadLineaEstimateGasRequest(
new CallParams(
null,
sender.getAddress(),
null,
"",
Accounts.GENESIS_ACCOUNT_TWO_PRIVATE_KEY,
"0",
null,
null,
null));
final var respLinea = reqLinea.execute(minerNode.nodeRequests());
assertThat(respLinea.getCode()).isEqualTo(-32000);
Expand Down Expand Up @@ -374,8 +487,17 @@ public String execute(final NodeRequests nodeRequests) {
static class RawEstimateGasResponse extends org.web3j.protocol.core.Response<String> {}
}

@JsonInclude(NON_NULL)
record CallParams(
String from, String to, String value, String data, String gas, String gasPrice) {}
String chainId,
String from,
String to,
String value,
String data,
String gas,
String gasPrice,
String maxFeePerGas,
String maxPriorityFeePerGas) {}

record StateOverride(String account, String balance) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,8 @@ private Transaction createTransactionForSimulation(
.signature(FAKE_SIGNATURE_FOR_SIZE_CALCULATION);

if (isBaseFeeTransaction(callParameters)) {
callParameters.getMaxFeePerGas().ifPresent(txBuilder::maxFeePerGas);
callParameters.getMaxPriorityFeePerGas().ifPresent(txBuilder::maxPriorityFeePerGas);
callParameters.getMaxFeePerBlobGas().ifPresent(txBuilder::maxFeePerBlobGas);
fab-10 marked this conversation as resolved.
Show resolved Hide resolved
txBuilder.maxFeePerGas(callParameters.getMaxFeePerGas().orElse(Wei.ZERO));
txBuilder.maxPriorityFeePerGas(callParameters.getMaxPriorityFeePerGas().orElse(Wei.ZERO));
} else {
txBuilder.gasPrice(
callParameters.getGasPrice() != null
Expand All @@ -503,6 +502,22 @@ private Transaction createTransactionForSimulation(

callParameters.getAccessList().ifPresent(txBuilder::accessList);

final var txType = txBuilder.guessType().getTransactionType();

if (txType.supportsBlob()) {
txBuilder.maxFeePerBlobGas(callParameters.getMaxFeePerBlobGas().orElse(Wei.ZERO));
}

callParameters
.getChainId()
.ifPresentOrElse(
txBuilder::chainId,
() -> {
if (txType.requiresChainId()) {
blockchainService.getChainId().ifPresent(txBuilder::chainId);
}
});

return txBuilder.build();
}

Expand Down
Loading