@@ -721,6 +721,75 @@ describe('BridgeStatusController', () => {
721
721
} ,
722
722
) ;
723
723
724
+ // Cleanup
725
+ jest . restoreAllMocks ( ) ;
726
+ } ) ;
727
+ it ( 'updates the srcTxHash when one is available' , async ( ) => {
728
+ // Setup
729
+ jest . useFakeTimers ( ) ;
730
+ let getStateCallCount = 0 ;
731
+
732
+ const messengerMock = {
733
+ call : jest . fn ( ( method : string ) => {
734
+ if ( method === 'AccountsController:getSelectedAccount' ) {
735
+ return { address : '0xaccount1' } ;
736
+ } else if (
737
+ method === 'NetworkController:findNetworkClientIdByChainId'
738
+ ) {
739
+ return 'networkClientId' ;
740
+ } else if ( method === 'NetworkController:getState' ) {
741
+ return { selectedNetworkClientId : 'networkClientId' } ;
742
+ } else if ( method === 'NetworkController:getNetworkClientById' ) {
743
+ return {
744
+ configuration : {
745
+ chainId : numberToHex ( 42161 ) ,
746
+ } ,
747
+ } ;
748
+ } else if ( method === 'TransactionController:getState' ) {
749
+ getStateCallCount += 1 ;
750
+ return {
751
+ transactions : [
752
+ {
753
+ id : 'bridgeTxMetaId1' ,
754
+ hash : getStateCallCount === 0 ? undefined : '0xnewTxHash' ,
755
+ } ,
756
+ ] ,
757
+ } ;
758
+ }
759
+ return null ;
760
+ } ) ,
761
+ publish : jest . fn ( ) ,
762
+ registerActionHandler : jest . fn ( ) ,
763
+ registerInitialEventPayload : jest . fn ( ) ,
764
+ } as unknown as jest . Mocked < BridgeStatusControllerMessenger > ;
765
+
766
+ const bridgeStatusController = new BridgeStatusController ( {
767
+ messenger : messengerMock ,
768
+ clientId : BridgeClientId . EXTENSION ,
769
+ fetchFn : jest . fn ( ) ,
770
+ } ) ;
771
+
772
+ // Start polling with no srcTxHash
773
+ const startPollingArgs = getMockStartPollingForBridgeTxStatusArgs ( ) ;
774
+ startPollingArgs . statusRequest . srcTxHash = undefined ;
775
+ bridgeStatusController . startPollingForBridgeTxStatus ( startPollingArgs ) ;
776
+
777
+ // Verify initial state has no srcTxHash
778
+ expect (
779
+ bridgeStatusController . state . bridgeStatusState . txHistory . bridgeTxMetaId1
780
+ . status . srcChain . txHash ,
781
+ ) . toBeUndefined ( ) ;
782
+
783
+ // Advance timer to trigger polling with new hash
784
+ jest . advanceTimersByTime ( 10000 ) ;
785
+ await flushPromises ( ) ;
786
+
787
+ // Verify the srcTxHash was updated
788
+ expect (
789
+ bridgeStatusController . state . bridgeStatusState . txHistory . bridgeTxMetaId1
790
+ . status . srcChain . txHash ,
791
+ ) . toBe ( '0xnewTxHash' ) ;
792
+
724
793
// Cleanup
725
794
jest . restoreAllMocks ( ) ;
726
795
} ) ;
0 commit comments