Skip to content

Commit aec31b1

Browse files
test: add test case for updating srcTxHash during polling
1 parent 6fcd269 commit aec31b1

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

packages/bridge-status-controller/src/bridge-status-controller.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,75 @@ describe('BridgeStatusController', () => {
721721
},
722722
);
723723

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+
724793
// Cleanup
725794
jest.restoreAllMocks();
726795
});

0 commit comments

Comments
 (0)