@@ -6,7 +6,13 @@ import type EthQuery from '@metamask/eth-query';
66import { CHAIN_IDS } from '../constants' ;
77import type { TransactionMeta } from '../types' ;
88import type { UpdateGasRequest } from './gas' ;
9- import { addGasBuffer , estimateGas , updateGas , FIXED_GAS } from './gas' ;
9+ import {
10+ addGasBuffer ,
11+ estimateGas ,
12+ updateGas ,
13+ FIXED_GAS ,
14+ DEFAULT_GAS_MULTIPLIER ,
15+ } from './gas' ;
1016
1117jest . mock ( '@metamask/controller-utils' , ( ) => ( {
1218 ...jest . requireActual ( '@metamask/controller-utils' ) ,
@@ -16,7 +22,6 @@ jest.mock('@metamask/controller-utils', () => ({
1622const GAS_MOCK = 100 ;
1723const BLOCK_GAS_LIMIT_MOCK = 1234567 ;
1824const BLOCK_NUMBER_MOCK = '0x5678' ;
19- const CODE_MOCK = '0x987' ;
2025// TODO: Replace `any` with type
2126// eslint-disable-next-line @typescript-eslint/no-explicit-any
2227const ETH_QUERY_MOCK = { } as any as EthQuery ;
@@ -127,11 +132,27 @@ describe('gas', () => {
127132 ) ;
128133 } ) ;
129134
135+ it ( 'to estimate if not custom network and no to parameter' , async ( ) => {
136+ updateGasRequest . providerConfig . type = NetworkType . mainnet ;
137+ const gasEstimation = Math . ceil ( GAS_MOCK * DEFAULT_GAS_MULTIPLIER ) ;
138+ delete updateGasRequest . txMeta . txParams . to ;
139+ mockQuery ( {
140+ getBlockByNumberResponse : { gasLimit : toHex ( BLOCK_GAS_LIMIT_MOCK ) } ,
141+ estimateGasResponse : toHex ( GAS_MOCK ) ,
142+ } ) ;
143+
144+ await updateGas ( updateGasRequest ) ;
145+
146+ expect ( updateGasRequest . txMeta . txParams . gas ) . toBe ( toHex ( gasEstimation ) ) ;
147+ expect ( updateGasRequest . txMeta . originalGasEstimate ) . toBe (
148+ updateGasRequest . txMeta . txParams . gas ,
149+ ) ;
150+ } ) ;
151+
130152 it ( 'to estimate if estimate greater than 90% of block gas limit' , async ( ) => {
131153 const estimatedGas = Math . ceil ( BLOCK_GAS_LIMIT_MOCK * 0.9 + 10 ) ;
132154
133155 mockQuery ( {
134- getCodeResponse : CODE_MOCK ,
135156 getBlockByNumberResponse : { gasLimit : toHex ( BLOCK_GAS_LIMIT_MOCK ) } ,
136157 estimateGasResponse : toHex ( estimatedGas ) ,
137158 } ) ;
@@ -150,7 +171,6 @@ describe('gas', () => {
150171 const estimatedGas = Math . round ( estimatedGasPadded / 1.5 ) ;
151172
152173 mockQuery ( {
153- getCodeResponse : CODE_MOCK ,
154174 getBlockByNumberResponse : { gasLimit : toHex ( BLOCK_GAS_LIMIT_MOCK ) } ,
155175 estimateGasResponse : toHex ( estimatedGas ) ,
156176 } ) ;
@@ -173,7 +193,6 @@ describe('gas', () => {
173193 updateGasRequest . providerConfig . chainId = CHAIN_IDS . OPTIMISM ;
174194
175195 mockQuery ( {
176- getCodeResponse : CODE_MOCK ,
177196 getBlockByNumberResponse : { gasLimit : toHex ( BLOCK_GAS_LIMIT_MOCK ) } ,
178197 estimateGasResponse : toHex ( estimatedGas ) ,
179198 } ) ;
@@ -194,7 +213,6 @@ describe('gas', () => {
194213 const estimatedGas = Math . ceil ( estimatedGasPadded / 1.5 ) ;
195214
196215 mockQuery ( {
197- getCodeResponse : CODE_MOCK ,
198216 getBlockByNumberResponse : { gasLimit : toHex ( BLOCK_GAS_LIMIT_MOCK ) } ,
199217 estimateGasResponse : toHex ( estimatedGas ) ,
200218 } ) ;
@@ -210,19 +228,6 @@ describe('gas', () => {
210228 } ) ;
211229
212230 describe ( 'to fixed value' , ( ) => {
213- it ( 'if not custom network and no to parameter' , async ( ) => {
214- updateGasRequest . providerConfig . type = NetworkType . mainnet ;
215- delete updateGasRequest . txMeta . txParams . to ;
216-
217- await updateGas ( updateGasRequest ) ;
218-
219- expect ( updateGasRequest . txMeta . txParams . gas ) . toBe ( FIXED_GAS ) ;
220- expect ( updateGasRequest . txMeta . originalGasEstimate ) . toBe (
221- updateGasRequest . txMeta . txParams . gas ,
222- ) ;
223- expectEstimateGasNotCalled ( ) ;
224- } ) ;
225-
226231 it ( 'if not custom network and to parameter and no data and no code' , async ( ) => {
227232 updateGasRequest . providerConfig . type = NetworkType . mainnet ;
228233 delete updateGasRequest . txMeta . txParams . data ;
@@ -264,7 +269,6 @@ describe('gas', () => {
264269 const fallbackGas = Math . floor ( BLOCK_GAS_LIMIT_MOCK * 0.95 ) ;
265270
266271 mockQuery ( {
267- getCodeResponse : CODE_MOCK ,
268272 getBlockByNumberResponse : {
269273 gasLimit : toHex ( BLOCK_GAS_LIMIT_MOCK ) ,
270274 } ,
@@ -281,7 +285,6 @@ describe('gas', () => {
281285
282286 it ( 'sets simulationFails property' , async ( ) => {
283287 mockQuery ( {
284- getCodeResponse : CODE_MOCK ,
285288 getBlockByNumberResponse : {
286289 gasLimit : toHex ( BLOCK_GAS_LIMIT_MOCK ) ,
287290 number : BLOCK_NUMBER_MOCK ,
0 commit comments