1+ import { vi } from "vitest" ;
12import { BigNumber } from "ethers" ;
23import { CHAIN_IDs , TOKEN_SYMBOLS_MAP } from "../../../api/_constants" ;
34import {
@@ -9,15 +10,18 @@ import { LimitsResponse } from "../../../api/_types";
910import { getCachedLimits } from "../../../api/_utils" ;
1011import { getTransferMode } from "../../../api/_bridges/cctp/utils/fill-times" ;
1112
12- jest . mock ( "../../../api/_utils" , ( ) => ( {
13- ...jest . requireActual ( "../../../api/_utils" ) ,
14- getCachedLimits : jest . fn ( ) ,
13+ vi . mock ( "../../../api/_utils" , async ( importOriginal ) => ( {
14+ ...( await importOriginal ( ) ) ,
15+ getCachedLimits : vi . fn ( ) ,
1516} ) ) ;
1617
17- jest . mock ( "../../../api/_bridges/cctp/utils/fill-times" , ( ) => ( {
18- ...jest . requireActual ( "../../../api/_bridges/cctp/utils/fill-times" ) ,
19- getTransferMode : jest . fn ( ) ,
20- } ) ) ;
18+ vi . mock (
19+ "../../../api/_bridges/cctp/utils/fill-times" ,
20+ async ( importOriginal ) => ( {
21+ ...( await importOriginal ( ) ) ,
22+ getTransferMode : vi . fn ( ) ,
23+ } )
24+ ) ;
2125
2226// Helper function to create a token on a specific chain
2327const createToken = (
@@ -86,8 +90,10 @@ describe("#getBridgeStrategyData()", () => {
8690
8791 beforeEach ( ( ) => {
8892 // Reset and setup mock before each test
89- ( getCachedLimits as jest . Mock ) . mockReset ( ) ;
90- ( getCachedLimits as jest . Mock ) . mockResolvedValue ( mockLimitsResponse ( ) ) ;
93+ ( getCachedLimits as ReturnType < typeof vi . fn > ) . mockReset ( ) ;
94+ ( getCachedLimits as ReturnType < typeof vi . fn > ) . mockResolvedValue (
95+ mockLimitsResponse ( )
96+ ) ;
9197 } ) ;
9298
9399 describe ( "Utilization checks" , ( ) => {
@@ -218,7 +224,7 @@ describe("#getBridgeStrategyData()", () => {
218224 const limits = mockLimitsResponse ( {
219225 maxDepositInstant : "100000000" , // 100 USDC
220226 } ) ;
221- ( getCachedLimits as jest . Mock ) . mockResolvedValue ( limits ) ;
227+ ( getCachedLimits as ReturnType < typeof vi . fn > ) . mockResolvedValue ( limits ) ;
222228
223229 const result = await getBridgeStrategyData ( {
224230 ...baseParams ,
@@ -235,7 +241,7 @@ describe("#getBridgeStrategyData()", () => {
235241 const limits = mockLimitsResponse ( {
236242 maxDepositInstant : "100000000" , // 100 USDC
237243 } ) ;
238- ( getCachedLimits as jest . Mock ) . mockResolvedValue ( limits ) ;
244+ ( getCachedLimits as ReturnType < typeof vi . fn > ) . mockResolvedValue ( limits ) ;
239245
240246 const result = await getBridgeStrategyData ( {
241247 ...baseParams ,
@@ -257,7 +263,7 @@ describe("#getBridgeStrategyData()", () => {
257263 utilizedReserves : "500000000000" , // 83.3% utilization
258264 } ,
259265 } ) ;
260- ( getCachedLimits as jest . Mock ) . mockResolvedValue ( limits ) ;
266+ ( getCachedLimits as ReturnType < typeof vi . fn > ) . mockResolvedValue ( limits ) ;
261267
262268 const result = await getBridgeStrategyData ( {
263269 ...baseParams ,
@@ -277,7 +283,7 @@ describe("#getBridgeStrategyData()", () => {
277283 utilizedReserves : "100000000000" , // 33.3% utilization
278284 } ,
279285 } ) ;
280- ( getCachedLimits as jest . Mock ) . mockResolvedValue ( limits ) ;
286+ ( getCachedLimits as ReturnType < typeof vi . fn > ) . mockResolvedValue ( limits ) ;
281287
282288 const result = await getBridgeStrategyData ( {
283289 ...baseParams ,
@@ -385,13 +391,15 @@ describe("#getBridgeStrategyData()", () => {
385391 describe ( "Linea fast mode eligibility" , ( ) => {
386392 beforeEach ( ( ) => {
387393 // Reset getTransferMode mock before each test
388- ( getTransferMode as jest . Mock ) . mockReset ( ) ;
394+ ( getTransferMode as ReturnType < typeof vi . fn > ) . mockReset ( ) ;
389395 } ) ;
390396
391397 test ( "should mark Linea as Fast CCTP eligible when fast mode is available" , async ( ) => {
392398 const amount = BigNumber . from ( "15000000000" ) ; // 15,000 USDC
393399 // Mock getTransferMode to return "fast" mode
394- ( getTransferMode as jest . Mock ) . mockResolvedValue ( "fast" ) ;
400+ ( getTransferMode as ReturnType < typeof vi . fn > ) . mockResolvedValue (
401+ "fast"
402+ ) ;
395403
396404 const result = await getBridgeStrategyData ( {
397405 ...baseParams ,
@@ -412,7 +420,9 @@ describe("#getBridgeStrategyData()", () => {
412420 test ( "should not mark Linea as Fast CCTP eligible when fast mode is unavailable" , async ( ) => {
413421 const amount = BigNumber . from ( "15000000000" ) ; // 15,000 USDC
414422 // Mock getTransferMode to return "standard" mode (fast mode not available)
415- ( getTransferMode as jest . Mock ) . mockResolvedValue ( "standard" ) ;
423+ ( getTransferMode as ReturnType < typeof vi . fn > ) . mockResolvedValue (
424+ "standard"
425+ ) ;
416426
417427 const result = await getBridgeStrategyData ( {
418428 ...baseParams ,
@@ -484,7 +494,7 @@ describe("#getBridgeStrategyData()", () => {
484494 const limits = mockLimitsResponse ( {
485495 maxDepositInstant : "1000000" , // Should match converted amount
486496 } ) ;
487- ( getCachedLimits as jest . Mock ) . mockResolvedValue ( limits ) ;
497+ ( getCachedLimits as ReturnType < typeof vi . fn > ) . mockResolvedValue ( limits ) ;
488498
489499 const result = await getBridgeStrategyData ( {
490500 ...baseParams ,
@@ -516,7 +526,7 @@ describe("#getBridgeStrategyData()", () => {
516526 describe ( "Error handling" , ( ) => {
517527 test ( "should return undefined when getCachedLimits throws error" , async ( ) => {
518528 const amount = BigNumber . from ( "1000000" ) ;
519- ( getCachedLimits as jest . Mock ) . mockRejectedValue (
529+ ( getCachedLimits as ReturnType < typeof vi . fn > ) . mockRejectedValue (
520530 new Error ( "API error" )
521531 ) ;
522532
0 commit comments