@@ -258,10 +258,9 @@ const testHistory = [
258
258
] ;
259
259
260
260
const ethereumChainIdDec = parseInt ( CHAIN_IDS . ETHEREUM , 16 ) ;
261
+ const goerliChainIdDec = parseInt ( CHAIN_IDS . GOERLI , 16 ) ;
261
262
262
263
const trackMetaMetricsEventSpy = jest . fn ( ) ;
263
- const getNetworkClientByIdSpy = jest . fn ( ) ;
264
-
265
264
const defaultState = {
266
265
smartTransactionsState : {
267
266
smartTransactions : {
@@ -307,7 +306,24 @@ describe('SmartTransactionsController', () => {
307
306
provider : jest . fn ( ) ,
308
307
confirmExternalTransaction : confirmExternalMock ,
309
308
trackMetaMetricsEvent : trackMetaMetricsEventSpy ,
310
- getNetworkClientById : getNetworkClientByIdSpy ,
309
+ getNetworkClientById : jest . fn ( ) . mockImplementation ( ( networkClientId ) => {
310
+ switch ( networkClientId ) {
311
+ case 'mainnet' :
312
+ return {
313
+ configuration : {
314
+ chainId : CHAIN_IDS . ETHEREUM ,
315
+ } ,
316
+ } ;
317
+ case 'goerli' :
318
+ return {
319
+ configuration : {
320
+ chainId : CHAIN_IDS . GOERLI ,
321
+ } ,
322
+ } ;
323
+ default :
324
+ throw new Error ( 'Invalid network client id' ) ;
325
+ }
326
+ } ) ,
311
327
} ) ;
312
328
// eslint-disable-next-line jest/prefer-spy-on
313
329
smartTransactionsController . subscribe = jest . fn ( ) ;
@@ -490,25 +506,24 @@ describe('SmartTransactionsController', () => {
490
506
} ) ;
491
507
492
508
it ( 'should add fee data to feesByChainId state using the networkClientId passed in to identify the appropriate chain' , async ( ) => {
493
- const goerliChainIdDec = parseInt ( CHAIN_IDS . GOERLI , 16 ) ;
494
- getNetworkClientByIdSpy . mockImplementation ( ( networkClientId ) => {
495
- switch ( networkClientId ) {
496
- case 'mainnet' :
497
- return {
498
- configuration : {
499
- chainId : CHAIN_IDS . ETHEREUM ,
500
- } ,
501
- } ;
502
- case 'goerli' :
503
- return {
504
- configuration : {
505
- chainId : CHAIN_IDS . GOERLI ,
506
- } ,
507
- } ;
508
- default :
509
- throw new Error ( 'Invalid network client id' ) ;
510
- }
511
- } ) ;
509
+ // getNetworkClientByIdSpy.mockImplementation((networkClientId) => {
510
+ // switch (networkClientId) {
511
+ // case 'mainnet':
512
+ // return {
513
+ // configuration: {
514
+ // chainId: CHAIN_IDS.ETHEREUM,
515
+ // },
516
+ // };
517
+ // case 'goerli':
518
+ // return {
519
+ // configuration: {
520
+ // chainId: CHAIN_IDS.GOERLI,
521
+ // },
522
+ // };
523
+ // default:
524
+ // throw new Error('Invalid network client id');
525
+ // }
526
+ // });
512
527
513
528
const tradeTx = createUnsignedTransaction ( goerliChainIdDec ) ;
514
529
const approvalTx = createUnsignedTransaction ( goerliChainIdDec ) ;
@@ -681,6 +696,30 @@ describe('SmartTransactionsController', () => {
681
696
const liveness = await smartTransactionsController . fetchLiveness ( ) ;
682
697
expect ( liveness ) . toBe ( true ) ;
683
698
} ) ;
699
+
700
+ it ( 'fetches liveness and sets in feesByChainId state for the Smart Transactions API for the chainId of the networkClientId passed in' , async ( ) => {
701
+ nock ( API_BASE_URL )
702
+ . get ( `/networks/${ goerliChainIdDec } /health` )
703
+ . replyWithError ( 'random error' ) ;
704
+
705
+ expect (
706
+ smartTransactionsController . state . smartTransactionsState
707
+ . livenessByChainId ,
708
+ ) . toStrictEqual ( {
709
+ [ CHAIN_IDS . ETHEREUM ] : true ,
710
+ [ CHAIN_IDS . GOERLI ] : true ,
711
+ } ) ;
712
+
713
+ await smartTransactionsController . fetchLiveness ( 'goerli' ) ;
714
+
715
+ expect (
716
+ smartTransactionsController . state . smartTransactionsState
717
+ . livenessByChainId ,
718
+ ) . toStrictEqual ( {
719
+ [ CHAIN_IDS . ETHEREUM ] : true ,
720
+ [ CHAIN_IDS . GOERLI ] : false ,
721
+ } ) ;
722
+ } ) ;
684
723
} ) ;
685
724
686
725
describe ( 'updateSmartTransaction' , ( ) => {
@@ -898,25 +937,6 @@ describe('SmartTransactionsController', () => {
898
937
} ,
899
938
} ) ;
900
939
901
- getNetworkClientByIdSpy . mockImplementation ( ( networkClientId ) => {
902
- switch ( networkClientId ) {
903
- case 'mainnet' :
904
- return {
905
- configuration : {
906
- chainId : CHAIN_IDS . ETHEREUM ,
907
- } ,
908
- } ;
909
- case 'goerli' :
910
- return {
911
- configuration : {
912
- chainId : CHAIN_IDS . GOERLI ,
913
- } ,
914
- } ;
915
- default :
916
- throw new Error ( 'Invalid network client id' ) ;
917
- }
918
- } ) ;
919
-
920
940
jest . useFakeTimers ( ) ;
921
941
const handleFetchSpy = jest . spyOn ( utils , 'handleFetch' ) ;
922
942
0 commit comments