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

[NIT-2620] Add test for gas estimation with RPC gas limit #2451

Merged
merged 4 commits into from
Jul 10, 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
3 changes: 2 additions & 1 deletion execution/nodeInterface/virtual-contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ func init() {
return
}
posterCost, _ := state.L1PricingState().PosterDataCost(msg, l1pricing.BatchPosterAddress, brotliCompressionLevel)
posterCostInL2Gas := arbos.GetPosterGas(state, header.BaseFee, msg.TxRunMode, posterCost)
// Use estimate mode because this is used to raise the gas cap, so we don't want to underestimate.
posterCostInL2Gas := arbos.GetPosterGas(state, header.BaseFee, core.MessageGasEstimationMode, posterCost)
*gascap = arbmath.SaturatingUAdd(*gascap, posterCostInL2Gas)
}

Expand Down
32 changes: 32 additions & 0 deletions system_tests/estimation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,35 @@ func TestDisableL1Charging(t *testing.T) {
_, err = builder.L2.Client.CallContract(ctx, ethereum.CallMsg{To: &addr, Gas: gasWithoutL1Charging, SkipL1Charging: true}, nil)
Require(t, err)
}

func TestGasEstimationWithRPCGasLimit(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

builder := NewNodeBuilder(ctx).DefaultConfig(t, true)
cleanup := builder.Build(t)
defer cleanup()

execConfigA := builder.execConfig
execConfigA.RPC.RPCGasCap = params.TxGas
testClientA, cleanupA := builder.Build2ndNode(t, &SecondNodeParams{execConfig: execConfigA})
defer cleanupA()
addr := common.HexToAddress("0x12345678")
estimateGas, err := testClientA.Client.EstimateGas(ctx, ethereum.CallMsg{To: &addr})
Require(t, err)
if estimateGas <= params.TxGas {
Fatal(t, "Incorrect gas estimate")
}

_, err = testClientA.Client.CallContract(ctx, ethereum.CallMsg{To: &addr}, nil)
Require(t, err)

execConfigB := builder.execConfig
execConfigB.RPC.RPCGasCap = params.TxGas - 1
testClientB, cleanupB := builder.Build2ndNode(t, &SecondNodeParams{execConfig: execConfigB})
defer cleanupB()
_, err = testClientB.Client.EstimateGas(ctx, ethereum.CallMsg{To: &addr})
if err == nil {
Fatal(t, "EstimateGas passed with insufficient gas")
}
}
Loading