@@ -460,6 +460,79 @@ describe('SmartTransactionsController', () => {
460
460
} as NetworkState ) ;
461
461
expect ( checkPollSpy ) . toHaveBeenCalled ( ) ;
462
462
} ) ;
463
+
464
+ it ( 'calls "ensureUniqueSmartTransactions" on network change if it is a new chainId' , ( ) => {
465
+ const { smartTransactionsState } = smartTransactionsController . state ;
466
+ const smartTransactionsForChainId = createStateAfterSuccess ( ) ;
467
+ smartTransactionsForChainId . push ( {
468
+ // Duplicate a smart transaction with the same uuid.
469
+ ...smartTransactionsForChainId [ 0 ] ,
470
+ status : 'pending' ,
471
+ } ) ;
472
+ smartTransactionsController . update ( {
473
+ smartTransactionsState : {
474
+ ...smartTransactionsState ,
475
+ smartTransactions : {
476
+ [ ChainId . mainnet ] :
477
+ smartTransactionsForChainId as SmartTransaction [ ] ,
478
+ } ,
479
+ } ,
480
+ } ) ;
481
+ smartTransactionsController . config . chainId = ChainId . sepolia ;
482
+ networkListener ( {
483
+ providerConfig : {
484
+ chainId : ChainId . mainnet ,
485
+ type : 'rpc' ,
486
+ ticker : 'ETH' ,
487
+ } ,
488
+ selectedNetworkClientId : 'networkClientId' ,
489
+ networkConfigurations : { } ,
490
+ networksMetadata : { } ,
491
+ } as NetworkState ) ;
492
+ const uniqueSmartTransactionsForChainId =
493
+ smartTransactionsController . state . smartTransactionsState
494
+ . smartTransactions [ ChainId . mainnet ] ;
495
+ expect ( uniqueSmartTransactionsForChainId ) . toHaveLength ( 1 ) ;
496
+ expect ( uniqueSmartTransactionsForChainId ) . toStrictEqual ( [
497
+ smartTransactionsForChainId [ 0 ] ,
498
+ ] ) ;
499
+ } ) ;
500
+
501
+ it ( 'does not call "ensureUniqueSmartTransactions" on network change for the same chainId' , ( ) => {
502
+ const { smartTransactionsState } = smartTransactionsController . state ;
503
+ const smartTransactionsForChainId = createStateAfterSuccess ( ) ;
504
+ smartTransactionsForChainId . push ( {
505
+ // Duplicate a smart transaction with the same uuid.
506
+ ...smartTransactionsForChainId [ 0 ] ,
507
+ status : 'pending' ,
508
+ } ) ;
509
+ smartTransactionsController . update ( {
510
+ smartTransactionsState : {
511
+ ...smartTransactionsState ,
512
+ smartTransactions : {
513
+ [ ChainId . mainnet ] :
514
+ smartTransactionsForChainId as SmartTransaction [ ] ,
515
+ } ,
516
+ } ,
517
+ } ) ;
518
+ networkListener ( {
519
+ providerConfig : {
520
+ chainId : ChainId . mainnet ,
521
+ type : 'rpc' ,
522
+ ticker : 'ETH' ,
523
+ } ,
524
+ selectedNetworkClientId : 'networkClientId' ,
525
+ networkConfigurations : { } ,
526
+ networksMetadata : { } ,
527
+ } as NetworkState ) ;
528
+ const currentSmartTransactionsForChainId =
529
+ smartTransactionsController . state . smartTransactionsState
530
+ . smartTransactions [ ChainId . mainnet ] ;
531
+ expect ( currentSmartTransactionsForChainId ) . toHaveLength ( 2 ) ;
532
+ expect ( currentSmartTransactionsForChainId ) . toStrictEqual (
533
+ smartTransactionsForChainId ,
534
+ ) ;
535
+ } ) ;
463
536
} ) ;
464
537
465
538
describe ( 'checkPoll' , ( ) => {
0 commit comments