@@ -93,6 +93,34 @@ const MockStatusResponse = {
93
93
} ,
94
94
} ,
95
95
} ) ,
96
+ getFailed : ( {
97
+ srcTxHash = '0xsrcTxHash1' ,
98
+ srcChainId = 42161 ,
99
+ destChainId = 10 ,
100
+ } = { } ) => ( {
101
+ status : 'FAILED' as StatusTypes ,
102
+ srcChain : {
103
+ chainId : srcChainId ,
104
+ txHash : srcTxHash ,
105
+ amount : '991250000000000' ,
106
+ token : {
107
+ address : '0x0000000000000000000000000000000000000000' ,
108
+ chainId : srcChainId ,
109
+ symbol : 'ETH' ,
110
+ decimals : 18 ,
111
+ name : 'ETH' ,
112
+ coinKey : 'ETH' ,
113
+ logoURI :
114
+ 'https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png' ,
115
+ priceUSD : '2518.47' ,
116
+ icon : 'https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png' ,
117
+ } ,
118
+ } ,
119
+ destChain : {
120
+ chainId : destChainId ,
121
+ token : { } ,
122
+ } ,
123
+ } ) ,
96
124
} ;
97
125
98
126
const getMockQuote = ( { srcChainId = 42161 , destChainId = 10 } = { } ) => ( {
@@ -536,6 +564,7 @@ describe('BridgeStatusController', () => {
536
564
bridgeStatusController . state . bridgeStatusState . txHistory ,
537
565
) . toStrictEqual ( MockTxHistory . getComplete ( ) ) ;
538
566
567
+ // Cleanup
539
568
jest . restoreAllMocks ( ) ;
540
569
} ) ;
541
570
it ( 'does not poll if the srcTxHash is not available' , async ( ) => {
@@ -604,6 +633,94 @@ describe('BridgeStatusController', () => {
604
633
. status . srcChain . txHash ,
605
634
) . toBeUndefined ( ) ;
606
635
636
+ // Cleanup
637
+ jest . restoreAllMocks ( ) ;
638
+ } ) ;
639
+ it ( 'emits bridgeTransactionComplete event when the status response is complete' , async ( ) => {
640
+ // Setup
641
+ jest . useFakeTimers ( ) ;
642
+ jest . spyOn ( Date , 'now' ) . mockImplementation ( ( ) => {
643
+ return MockTxHistory . getComplete ( ) . bridgeTxMetaId1 . completionTime ?? 10 ;
644
+ } ) ;
645
+
646
+ const messengerMock = getMessengerMock ( ) ;
647
+ const bridgeStatusController = new BridgeStatusController ( {
648
+ messenger : messengerMock ,
649
+ clientId : BridgeClientId . EXTENSION ,
650
+ fetchFn : jest . fn ( ) ,
651
+ } ) ;
652
+
653
+ const fetchBridgeTxStatusSpy = jest
654
+ . spyOn ( bridgeStatusUtils , 'fetchBridgeTxStatus' )
655
+ . mockImplementationOnce ( async ( ) => {
656
+ return MockStatusResponse . getComplete ( ) ;
657
+ } ) ;
658
+
659
+ // Execution
660
+ bridgeStatusController . startPollingForBridgeTxStatus (
661
+ getMockStartPollingForBridgeTxStatusArgs ( ) ,
662
+ ) ;
663
+ jest . advanceTimersByTime ( 10000 ) ;
664
+ await flushPromises ( ) ;
665
+
666
+ // Assertions
667
+ expect ( fetchBridgeTxStatusSpy ) . toHaveBeenCalledTimes ( 1 ) ;
668
+ expect ( messengerMock . publish ) . toHaveBeenCalledWith (
669
+ 'BridgeStatusController:bridgeTransactionComplete' ,
670
+ {
671
+ bridgeHistoryItem : expect . objectContaining ( {
672
+ txMetaId : 'bridgeTxMetaId1' ,
673
+ status : expect . objectContaining ( {
674
+ status : 'COMPLETE' ,
675
+ } ) ,
676
+ } ) ,
677
+ } ,
678
+ ) ;
679
+
680
+ // Cleanup
681
+ jest . restoreAllMocks ( ) ;
682
+ } ) ;
683
+ it ( 'emits bridgeTransactionFailed event when the status response is failed' , async ( ) => {
684
+ // Setup
685
+ jest . useFakeTimers ( ) ;
686
+ jest . spyOn ( Date , 'now' ) . mockImplementation ( ( ) => {
687
+ return MockTxHistory . getComplete ( ) . bridgeTxMetaId1 . completionTime ?? 10 ;
688
+ } ) ;
689
+
690
+ const messengerMock = getMessengerMock ( ) ;
691
+ const bridgeStatusController = new BridgeStatusController ( {
692
+ messenger : messengerMock ,
693
+ clientId : BridgeClientId . EXTENSION ,
694
+ fetchFn : jest . fn ( ) ,
695
+ } ) ;
696
+
697
+ const fetchBridgeTxStatusSpy = jest
698
+ . spyOn ( bridgeStatusUtils , 'fetchBridgeTxStatus' )
699
+ . mockImplementationOnce ( async ( ) => {
700
+ return MockStatusResponse . getFailed ( ) ;
701
+ } ) ;
702
+
703
+ // Execution
704
+ bridgeStatusController . startPollingForBridgeTxStatus (
705
+ getMockStartPollingForBridgeTxStatusArgs ( ) ,
706
+ ) ;
707
+ jest . advanceTimersByTime ( 10000 ) ;
708
+ await flushPromises ( ) ;
709
+
710
+ // Assertions
711
+ expect ( fetchBridgeTxStatusSpy ) . toHaveBeenCalledTimes ( 1 ) ;
712
+ expect ( messengerMock . publish ) . toHaveBeenCalledWith (
713
+ 'BridgeStatusController:bridgeTransactionFailed' ,
714
+ {
715
+ bridgeHistoryItem : expect . objectContaining ( {
716
+ txMetaId : 'bridgeTxMetaId1' ,
717
+ status : expect . objectContaining ( {
718
+ status : 'FAILED' ,
719
+ } ) ,
720
+ } ) ,
721
+ } ,
722
+ ) ;
723
+
607
724
// Cleanup
608
725
jest . restoreAllMocks ( ) ;
609
726
} ) ;
0 commit comments