@@ -525,33 +525,46 @@ describe('SelectedNetworkController', () => {
525
525
} ) ;
526
526
527
527
describe ( 'when the requesting domain is a snap (starts with "npm:" or "local:"' , ( ) => {
528
- it ( 'skips setting the networkClientId for the passed in domain ' , ( ) => {
528
+ it ( 'sets the networkClientId for the passed in snap ID ' , ( ) => {
529
529
const { controller, mockHasPermissions } = setup ( {
530
530
state : { domains : { } } ,
531
531
useRequestQueuePreference : true ,
532
532
} ) ;
533
533
mockHasPermissions . mockReturnValue ( true ) ;
534
- const snapDomainOne = 'npm:@metamask/bip32-example-snap' ;
535
- const snapDomainTwo = 'local:@metamask/bip32-example-snap' ;
536
- const nonSnapDomain = 'example.com' ;
534
+ const domain = 'npm:foo-snap' ;
537
535
const networkClientId = 'network1' ;
536
+ controller . setNetworkClientIdForDomain ( domain , networkClientId ) ;
537
+ expect ( controller . state . domains [ domain ] ) . toBe ( networkClientId ) ;
538
+ } ) ;
538
539
540
+ it ( 'updates the provider and block tracker proxy when they already exist for the snap ID' , ( ) => {
541
+ const { controller, mockProviderProxy, mockHasPermissions } = setup ( {
542
+ state : { domains : { } } ,
543
+ useRequestQueuePreference : true ,
544
+ } ) ;
545
+ mockHasPermissions . mockReturnValue ( true ) ;
546
+ const initialNetworkClientId = '123' ;
547
+
548
+ // creates the proxy for the new domain
539
549
controller . setNetworkClientIdForDomain (
540
- nonSnapDomain ,
541
- networkClientId ,
542
- ) ;
543
- controller . setNetworkClientIdForDomain (
544
- snapDomainOne ,
545
- networkClientId ,
550
+ 'npm:foo-snap' ,
551
+ initialNetworkClientId ,
546
552
) ;
553
+ const newNetworkClientId = 'abc' ;
554
+
555
+ expect ( mockProviderProxy . setTarget ) . toHaveBeenCalledTimes ( 1 ) ;
556
+
557
+ // calls setTarget on the proxy
547
558
controller . setNetworkClientIdForDomain (
548
- snapDomainTwo ,
549
- networkClientId ,
559
+ 'npm:foo-snap' ,
560
+ newNetworkClientId ,
550
561
) ;
551
562
552
- expect ( controller . state . domains ) . toStrictEqual ( {
553
- [ nonSnapDomain ] : networkClientId ,
554
- } ) ;
563
+ expect ( mockProviderProxy . setTarget ) . toHaveBeenNthCalledWith (
564
+ 2 ,
565
+ expect . objectContaining ( { request : expect . any ( Function ) } ) ,
566
+ ) ;
567
+ expect ( mockProviderProxy . setTarget ) . toHaveBeenCalledTimes ( 2 ) ;
555
568
} ) ;
556
569
} ) ;
557
570
0 commit comments