@@ -2,7 +2,11 @@ import type EthQuery from '@metamask/eth-query';
22import type { Hex } from '@metamask/utils' ;
33
44import { flushPromises } from '../../../../tests/helpers' ;
5- import type { GasFeeFlowResponse } from '../types' ;
5+ import type {
6+ GasFeeFlowResponse ,
7+ Layer1GasFeeFlow ,
8+ Layer1GasFeeFlowResponse ,
9+ } from '../types' ;
610import {
711 TransactionStatus ,
812 type GasFeeFlow ,
@@ -38,6 +42,10 @@ const GAS_FEE_FLOW_RESPONSE_MOCK: GasFeeFlowResponse = {
3842 } ,
3943} ;
4044
45+ const LAYER_1_GAS_FEE_FLOW_RESPONSE_MOCK : Layer1GasFeeFlowResponse = {
46+ layer1Fee : '0x123' ,
47+ } ;
48+
4149/**
4250 * Creates a mock GasFeeFlow.
4351 * @returns The mock GasFeeFlow.
@@ -49,9 +57,21 @@ function createGasFeeFlowMock(): jest.Mocked<GasFeeFlow> {
4957 } ;
5058}
5159
60+ /**
61+ * Creates a mock Layer1GasFeeFlow.
62+ * @returns The mock GasFeeFlow.
63+ */
64+ function createLayer1GasFeeFlowMock ( ) : jest . Mocked < Layer1GasFeeFlow > {
65+ return {
66+ matchesTransaction : jest . fn ( ) ,
67+ getLayer1Fee : jest . fn ( ) ,
68+ } ;
69+ }
70+
5271describe ( 'GasFeePoller' , ( ) => {
5372 let constructorOptions : ConstructorParameters < typeof GasFeePoller > [ 0 ] ;
5473 let gasFeeFlowMock : jest . Mocked < GasFeeFlow > ;
74+ let layer1GasFeeFlowMock : jest . Mocked < Layer1GasFeeFlow > ;
5575 let triggerOnStateChange : ( ) => void ;
5676 let getTransactionsMock : jest . MockedFunction < ( ) => TransactionMeta [ ] > ;
5777
@@ -63,6 +83,12 @@ describe('GasFeePoller', () => {
6383 gasFeeFlowMock . matchesTransaction . mockReturnValue ( true ) ;
6484 gasFeeFlowMock . getGasFees . mockResolvedValue ( GAS_FEE_FLOW_RESPONSE_MOCK ) ;
6585
86+ layer1GasFeeFlowMock = createLayer1GasFeeFlowMock ( ) ;
87+ layer1GasFeeFlowMock . matchesTransaction . mockReturnValue ( true ) ;
88+ layer1GasFeeFlowMock . getLayer1Fee . mockResolvedValue (
89+ LAYER_1_GAS_FEE_FLOW_RESPONSE_MOCK ,
90+ ) ;
91+
6692 getTransactionsMock = jest . fn ( ) ;
6793 getTransactionsMock . mockReturnValue ( [ TRANSACTION_META_MOCK ] ) ;
6894
@@ -71,6 +97,7 @@ describe('GasFeePoller', () => {
7197 getEthQuery : ( ) => ( { } as EthQuery ) ,
7298 getGasFeeControllerEstimates : jest . fn ( ) ,
7399 getTransactions : getTransactionsMock ,
100+ layer1GasFeeFlows : [ layer1GasFeeFlowMock ] ,
74101 onStateChange : ( listener : ( ) => void ) => {
75102 triggerOnStateChange = listener ;
76103 } ,
@@ -88,11 +115,21 @@ describe('GasFeePoller', () => {
88115 triggerOnStateChange ( ) ;
89116 await flushPromises ( ) ;
90117
91- expect ( listener ) . toHaveBeenCalledTimes ( 1 ) ;
92- expect ( listener ) . toHaveBeenCalledWith ( {
93- ...TRANSACTION_META_MOCK ,
94- gasFeeEstimates : GAS_FEE_FLOW_RESPONSE_MOCK . estimates ,
95- } ) ;
118+ expect ( listener ) . toHaveBeenCalledTimes ( 2 ) ;
119+ expect ( listener . mock . calls ) . toMatchObject ( [
120+ [
121+ {
122+ ...TRANSACTION_META_MOCK ,
123+ gasFeeEstimates : GAS_FEE_FLOW_RESPONSE_MOCK . estimates ,
124+ } ,
125+ ] ,
126+ [
127+ {
128+ ...TRANSACTION_META_MOCK ,
129+ layer1GasFee : LAYER_1_GAS_FEE_FLOW_RESPONSE_MOCK . layer1Fee ,
130+ } ,
131+ ] ,
132+ ] ) ;
96133 } ) ;
97134
98135 it ( 'calls gas fee flow' , async ( ) => {
@@ -113,6 +150,22 @@ describe('GasFeePoller', () => {
113150 } ) ;
114151 } ) ;
115152
153+ it ( 'calls layer 1 gas fee flow' , async ( ) => {
154+ const listener = jest . fn ( ) ;
155+
156+ const gasFeePoller = new GasFeePoller ( constructorOptions ) ;
157+ gasFeePoller . hub . on ( 'transaction-updated' , listener ) ;
158+
159+ triggerOnStateChange ( ) ;
160+ await flushPromises ( ) ;
161+
162+ expect ( layer1GasFeeFlowMock . getLayer1Fee ) . toHaveBeenCalledTimes ( 1 ) ;
163+ expect ( layer1GasFeeFlowMock . getLayer1Fee ) . toHaveBeenCalledWith ( {
164+ ethQuery : expect . any ( Object ) ,
165+ transactionMeta : TRANSACTION_META_MOCK ,
166+ } ) ;
167+ } ) ;
168+
116169 it ( 'creates polling timeout' , async ( ) => {
117170 new GasFeePoller ( constructorOptions ) ;
118171
@@ -174,10 +227,11 @@ describe('GasFeePoller', () => {
174227 expect ( listener ) . toHaveBeenCalledTimes ( 0 ) ;
175228 } ) ;
176229
177- it ( 'no gas fee flow matches transaction' , async ( ) => {
230+ it ( 'no fee flow matches transaction' , async ( ) => {
178231 const listener = jest . fn ( ) ;
179232
180233 gasFeeFlowMock . matchesTransaction . mockReturnValue ( false ) ;
234+ layer1GasFeeFlowMock . matchesTransaction . mockReturnValue ( false ) ;
181235
182236 const gasFeePoller = new GasFeePoller ( constructorOptions ) ;
183237 gasFeePoller . hub . on ( 'transaction-updated' , listener ) ;
@@ -188,10 +242,13 @@ describe('GasFeePoller', () => {
188242 expect ( listener ) . toHaveBeenCalledTimes ( 0 ) ;
189243 } ) ;
190244
191- it ( 'gas fee flow throws' , async ( ) => {
245+ it ( 'fee flows throws' , async ( ) => {
192246 const listener = jest . fn ( ) ;
193247
194248 gasFeeFlowMock . getGasFees . mockRejectedValue ( new Error ( 'TestError' ) ) ;
249+ layer1GasFeeFlowMock . getLayer1Fee . mockRejectedValue (
250+ new Error ( 'TestError' ) ,
251+ ) ;
195252
196253 const gasFeePoller = new GasFeePoller ( constructorOptions ) ;
197254 gasFeePoller . hub . on ( 'transaction-updated' , listener ) ;
0 commit comments