11import {
2- PPOMClass ,
32 VERSION_INFO ,
43 buildDummyResponse ,
54 buildFetchSpy ,
@@ -369,59 +368,6 @@ describe('PPOMController', () => {
369368 'Aborting validation as not all files could not be downloaded for the network with chainId: 0x1' ,
370369 ) ;
371370 } ) ;
372-
373- it ( 'should reset PPOM when network is switched' , async ( ) => {
374- buildFetchSpy ( ) ;
375- let callBack : any ;
376- const freeMock = jest . fn ( ) ;
377- ppomController = buildPPOMController ( {
378- storageBackend : buildStorageBackend ( {
379- read : async ( ) : Promise < any > => {
380- throw new Error ( 'not found' ) ;
381- } ,
382- } ) ,
383- onNetworkChange : ( func : any ) => {
384- callBack = func ;
385- } ,
386- chainId : '0x2' ,
387- ppomProvider : {
388- ppomInit : ( ) => undefined ,
389- PPOM : new PPOMClass ( undefined , freeMock ) ,
390- } ,
391- } ) ;
392- callBack ( { providerConfig : { chainId : '0x1' } } ) ;
393- await flushPromises ( ) ;
394- jest . runOnlyPendingTimers ( ) ;
395- await flushPromises ( ) ;
396- callBack ( { providerConfig : { chainId : '0x2' } } ) ;
397- await flushPromises ( ) ;
398- expect ( freeMock ) . toHaveBeenCalledTimes ( 1 ) ;
399- } ) ;
400-
401- it ( 'should not throw error if PPOM init on network changs fails' , async ( ) => {
402- buildFetchSpy ( ) ;
403- let callBack : any ;
404- const newMock = jest . fn ( ) . mockImplementation ( ( ) => {
405- throw Error ( 'test' ) ;
406- } ) ;
407- ppomController = buildPPOMController ( {
408- onNetworkChange : ( func : any ) => {
409- callBack = func ;
410- } ,
411- chainId : '0x1' ,
412- ppomProvider : {
413- ppomInit : ( ) => undefined ,
414- PPOM : new PPOMClass ( newMock ) ,
415- } ,
416- } ) ;
417- callBack ( { providerConfig : { chainId : '0x2' } } ) ;
418- await flushPromises ( ) ;
419- jest . runOnlyPendingTimers ( ) ;
420- await flushPromises ( ) ;
421- callBack ( { providerConfig : { chainId : '0x1' } } ) ;
422- await flushPromises ( ) ;
423- expect ( newMock ) . toHaveBeenCalledTimes ( 1 ) ;
424- } ) ;
425371 } ) ;
426372
427373 describe ( 'updatePPOM' , ( ) => {
@@ -479,25 +425,6 @@ describe('PPOMController', () => {
479425 expect ( spy ) . toHaveBeenCalledTimes ( 9 ) ;
480426 } ) ;
481427
482- it ( 'should set dataFetched to true for supported chainIds in chainStatus' , async ( ) => {
483- buildFetchSpy ( ) ;
484- let callBack : any ;
485- ppomController = buildPPOMController ( {
486- onNetworkChange : ( func : any ) => {
487- callBack = func ;
488- } ,
489- } ) ;
490- jest . runOnlyPendingTimers ( ) ;
491- callBack ( { providerConfig : { chainId : '0x2' } } ) ;
492- await ppomController . updatePPOM ( ) ;
493- jest . runOnlyPendingTimers ( ) ;
494- await flushPromises ( ) ;
495- const chainIdData1 = ppomController . state . chainStatus [ '0x1' ] ;
496- const chainIdData2 = ppomController . state . chainStatus [ '0x2' ] ;
497- expect ( chainIdData1 . dataFetched ) . toBe ( true ) ;
498- expect ( chainIdData2 . dataFetched ) . toBe ( false ) ;
499- } ) ;
500-
501428 it ( 'should get files for only supported chains in chainStatus' , async ( ) => {
502429 const spy = buildFetchSpy ( {
503430 status : 200 ,
@@ -566,20 +493,21 @@ describe('PPOMController', () => {
566493 buildFetchSpy ( ) ;
567494 let callBack : any ;
568495 ppomController = buildPPOMController ( {
496+ chainId : '0x2' ,
569497 onNetworkChange : ( func : any ) => {
570498 callBack = func ;
571499 } ,
572500 } ) ;
573501 jest . runOnlyPendingTimers ( ) ;
574502 await flushPromises ( ) ;
575- const chainIdData1 = ppomController . state . chainStatus [ '0x1 ' ] ;
503+ const chainIdData1 = ppomController . state . chainStatus [ '0x2 ' ] ;
576504 expect ( chainIdData1 ) . toBeDefined ( ) ;
577- callBack ( { providerConfig : { chainId : '0x2' } } ) ;
578505 callBack ( { providerConfig : { chainId : '0x3' } } ) ;
506+ callBack ( { providerConfig : { chainId : '0x4' } } ) ;
579507 jest . advanceTimersByTime ( NETWORK_CACHE_DURATION ) ;
580508 jest . runOnlyPendingTimers ( ) ;
581509 await flushPromises ( ) ;
582- const chainIdData2 = ppomController . state . chainStatus [ '0x1 ' ] ;
510+ const chainIdData2 = ppomController . state . chainStatus [ '0x2 ' ] ;
583511 expect ( chainIdData2 ) . toBeUndefined ( ) ;
584512 } ) ;
585513
@@ -599,48 +527,6 @@ describe('PPOMController', () => {
599527 await flushPromises ( ) ;
600528 expect ( spy ) . toHaveBeenCalledTimes ( 6 ) ;
601529 } ) ;
602-
603- it ( 'should re-init ppom when new set of files are fetched' , async ( ) => {
604- buildFetchSpy ( ) ;
605- const newMock = jest . fn ( ) ;
606- ppomController = buildPPOMController ( {
607- ppomProvider : {
608- ppomInit : ( ) => undefined ,
609- PPOM : new PPOMClass ( newMock ) ,
610- } ,
611- fileFetchScheduleDuration : 0 ,
612- } ) ;
613- await flushPromises ( ) ;
614- jest . advanceTimersByTime ( REFRESH_TIME_INTERVAL ) ;
615- await flushPromises ( ) ;
616- expect ( newMock ) . toHaveBeenCalledTimes ( 1 ) ;
617-
618- buildFetchSpy (
619- {
620- status : 200 ,
621- json : ( ) => [
622- ...VERSION_INFO ,
623- {
624- name : 'data2' ,
625- chainId : '0x1' ,
626- version : '1.0.3' ,
627- checksum :
628- '409a7f83ac6b31dc8c77e3ec18038f209bd2f545e0f4177c2e2381aa4e067b49' ,
629- filePath : 'data2' ,
630- } ,
631- ] ,
632- } ,
633- undefined ,
634- 2 ,
635- ) ;
636- await flushPromises ( ) ;
637-
638- jest . advanceTimersByTime ( REFRESH_TIME_INTERVAL ) ;
639- await flushPromises ( ) ;
640- jest . advanceTimersByTime ( 1 ) ;
641- await flushPromises ( ) ;
642- expect ( newMock ) . toHaveBeenCalledTimes ( 3 ) ;
643- } ) ;
644530 } ) ;
645531
646532 describe ( 'onNetworkChange' , ( ) => {
@@ -687,6 +573,7 @@ describe('PPOMController', () => {
687573 buildFetchSpy ( ) ;
688574 let callBack : any ;
689575 ppomController = buildPPOMController ( {
576+ chainId : '0x2' ,
690577 onNetworkChange : ( func : any ) => {
691578 callBack = func ;
692579 } ,
@@ -695,50 +582,25 @@ describe('PPOMController', () => {
695582 expect ( Object . keys ( ppomController . state . chainStatus ) ) . toHaveLength ( 1 ) ;
696583
697584 jest . useFakeTimers ( ) . setSystemTime ( new Date ( '2023-01-02' ) ) ;
698- callBack ( { providerConfig : { chainId : '0x2 ' } } ) ;
585+ callBack ( { providerConfig : { chainId : '0x3 ' } } ) ;
699586
700587 jest . useFakeTimers ( ) . setSystemTime ( new Date ( '2023-01-05' ) ) ;
701588 callBack ( { providerConfig : { chainId : '0x5' } } ) ;
702589
703590 jest . useFakeTimers ( ) . setSystemTime ( new Date ( '2023-01-03' ) ) ;
704- callBack ( { providerConfig : { chainId : '0x3 ' } } ) ;
591+ callBack ( { providerConfig : { chainId : '0x4 ' } } ) ;
705592
706593 jest . useFakeTimers ( ) . setSystemTime ( new Date ( '2023-01-04' ) ) ;
707- callBack ( { providerConfig : { chainId : '0x4 ' } } ) ;
594+ callBack ( { providerConfig : { chainId : '0x6 ' } } ) ;
708595
709596 expect ( Object . keys ( ppomController . state . chainStatus ) ) . toHaveLength ( 5 ) ;
710597
711598 jest . useFakeTimers ( ) . setSystemTime ( new Date ( '2023-01-06' ) ) ;
712- callBack ( { providerConfig : { chainId : '0x6 ' } } ) ;
599+ callBack ( { providerConfig : { chainId : '0x7 ' } } ) ;
713600 expect ( Object . keys ( ppomController . state . chainStatus ) ) . toHaveLength ( 5 ) ;
714601
715602 expect ( ppomController . state . chainStatus [ '0x1' ] ) . toBeUndefined ( ) ;
716603 } ) ;
717-
718- it ( 'should reset PPOM when network is changed' , async ( ) => {
719- buildFetchSpy ( ) ;
720- const freeMock = jest . fn ( ) . mockReturnValue ( 'abc' ) ;
721- let callBack : any ;
722- ppomController = buildPPOMController ( {
723- onNetworkChange : ( func : any ) => {
724- callBack = func ;
725- } ,
726- chainId : '0x1' ,
727- ppomProvider : {
728- ppomInit : ( ) => undefined ,
729- PPOM : new PPOMClass ( undefined , freeMock ) ,
730- } ,
731- } ) ;
732-
733- await flushPromises ( ) ;
734- jest . advanceTimersByTime ( REFRESH_TIME_INTERVAL ) ;
735- await flushPromises ( ) ;
736-
737- expect ( freeMock ) . toHaveBeenCalledTimes ( 0 ) ;
738- callBack ( { providerConfig : { chainId : '0x2' } } ) ;
739- callBack ( { providerConfig : { chainId : '0x1' } } ) ;
740- expect ( freeMock ) . toHaveBeenCalledTimes ( 1 ) ;
741- } ) ;
742604 } ) ;
743605
744606 describe ( 'onPreferencesChange' , ( ) => {
0 commit comments