From 6b4c5ae89a563928df2f1ae9f25a2cf87e4c5748 Mon Sep 17 00:00:00 2001 From: Diego Essaya Date: Thu, 21 Sep 2023 11:47:48 -0300 Subject: [PATCH] fix(evm): allow estimateGas with no funds --- packages/vm/core/evm/evmtest/evm_test.go | 17 +++++++++++++++++ packages/vm/vmimpl/runreq.go | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/packages/vm/core/evm/evmtest/evm_test.go b/packages/vm/core/evm/evmtest/evm_test.go index 4a96989a44..addcfa3cf3 100644 --- a/packages/vm/core/evm/evmtest/evm_test.go +++ b/packages/vm/core/evm/evmtest/evm_test.go @@ -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() diff --git a/packages/vm/vmimpl/runreq.go b/packages/vm/vmimpl/runreq.go index d5e19543e0..4693fad423 100644 --- a/packages/vm/vmimpl/runreq.go +++ b/packages/vm/vmimpl/runreq.go @@ -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