Skip to content

Commit

Permalink
Merge pull request #2451 from OffchainLabs/rpc_gas_limit
Browse files Browse the repository at this point in the history
[NIT-2620] Add test for gas estimation with RPC gas limit
  • Loading branch information
joshuacolvin0 authored Jul 10, 2024
2 parents 43752ab + 718d60c commit 1173644
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
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")
}
}

0 comments on commit 1173644

Please sign in to comment.