Skip to content

Commit

Permalink
Merge pull request #2885 from dessaya/fix-estimategas-no-funds
Browse files Browse the repository at this point in the history
fix(evm): allow estimateGas with no funds
  • Loading branch information
fijter authored Sep 23, 2023
2 parents 35ea20e + 6b4c5ae commit da186f5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/vm/core/evm/evmtest/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,23 @@ func TestLoopWithGasLeft(t *testing.T) {
require.Greater(t, usedGas[1], usedGas[0])
}

func TestEstimateGasWithoutFunds(t *testing.T) {
env := initEVM(t)
ethKey, _ := env.soloChain.NewEthereumAccountWithL2Funds()
iscTest := env.deployISCTestContract(ethKey)

callData, err := iscTest.abi.Pack("loopWithGasLeft")
require.NoError(t, err)
estimatedGas, err := env.evmChain.EstimateGas(ethereum.CallMsg{
From: common.Address{},
To: &iscTest.address,
Data: callData,
}, nil)
require.NoError(t, err)
require.NotZero(t, estimatedGas)
t.Log(estimatedGas)
}

func TestLoopWithGasLeftEstimateGas(t *testing.T) {
env := initEVM(t)
ethKey, ethAddr := env.soloChain.NewEthereumAccountWithL2Funds()
Expand Down
4 changes: 4 additions & 0 deletions packages/vm/vmimpl/runreq.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ func (reqctx *requestContext) calculateAffordableGasBudget() (budget, maxTokensT
gasBudget = reqctx.vm.chainInfo.GasLimits.MinGasPerRequest
}

if reqctx.vm.task.EstimateGasMode {
return gasBudget, math.MaxUint64
}

// calculate how many tokens for gas fee can be guaranteed after taking into account the allowance
guaranteedFeeTokens := reqctx.calcGuaranteedFeeTokens()
// calculate how many tokens maximum will be charged taking into account the budget
Expand Down

0 comments on commit da186f5

Please sign in to comment.