11import { expect } from "chai" ;
22import { ethers } from "ethers" ;
33import {
4- EvmTokenRouter ,
54 EvmMatchingEngine ,
6- errorDecoder ,
7- OrderResponse ,
5+ EvmTokenRouter ,
86 MessageDecoder ,
7+ OrderResponse ,
8+ errorDecoder ,
99} from "../src" ;
10- import { IERC20__factory } from "../src/types" ;
1110import {
1211 ChainType ,
13- parseLiquidityLayerEnvFile ,
1412 CircleAttester ,
1513 GuardianNetwork ,
1614 LOCALHOSTS ,
@@ -20,21 +18,18 @@ import {
2018 ValidNetwork ,
2119 WALLET_PRIVATE_KEYS ,
2220 burnAllUsdc ,
23- mineWait ,
2421 mine ,
25- mintNativeUsdc ,
2622 mineToGracePeriod ,
2723 mineToPenaltyPeriod ,
24+ mineWait ,
25+ mintNativeUsdc ,
26+ parseLiquidityLayerEnvFile ,
2827 tryNativeToUint8Array ,
2928} from "../src/testing" ;
29+ import { IERC20__factory } from "../src/types" ;
3030
3131import { toChainId } from "@wormhole-foundation/sdk-base" ;
32- import {
33- deserialize ,
34- keccak256 ,
35- serializePayload ,
36- toUniversal ,
37- } from "@wormhole-foundation/sdk-definitions" ;
32+ import { deserialize , keccak256 , toUniversal } from "@wormhole-foundation/sdk-definitions" ;
3833import "@wormhole-foundation/sdk-evm" ;
3934
4035// Cannot send a fast market order from the matching engine chain.
@@ -330,7 +325,7 @@ describe("Fast Market Order Business Logic -- CCTP to CCTP", function (this: Moc
330325 await mintNativeUsdc ( usdc , playerAddress , initialDeposit , false ) ;
331326 await usdc . approve ( engine . address , initialDeposit ) ;
332327
333- // sleep because otherwise nonce collisions (??)
328+ // give it time to hit the mempool
334329 await sleep ( 1 ) ;
335330
336331 bids [ i ] . balance = await usdc . balanceOf ( playerAddress ) ;
@@ -725,6 +720,7 @@ describe("Fast Market Order Business Logic -- CCTP to CCTP", function (this: Moc
725720 await mintNativeUsdc ( usdc , playerAddress , initialDeposit , false ) ;
726721 await usdc . approve ( engine . address , initialDeposit ) ;
727722
723+ // give it time to hit the mempool
728724 await sleep ( 1 ) ;
729725
730726 bids [ i ] . balance = await usdc . balanceOf ( playerAddress ) ;
@@ -1163,7 +1159,6 @@ describe("Fast Market Order Business Logic -- CCTP to CCTP", function (this: Moc
11631159 ) ;
11641160 } ) ;
11651161 } ) ;
1166-
11671162 describe ( `No Auction - Deadline Exceeded` , ( ) => {
11681163 before ( `From Network -- Mint USDC` , async ( ) => {
11691164 if ( fromEnv . chainId == MATCHING_ENGINE_CHAIN ) {
@@ -1281,22 +1276,24 @@ describe("Fast Market Order Business Logic -- CCTP to CCTP", function (this: Moc
12811276 // Prepare usdc for the auction.
12821277 const usdc = IERC20__factory . connect ( engineEnv . tokenAddress , initialBidder ) ;
12831278 await mintNativeUsdc ( usdc , await initialBidder . getAddress ( ) , initialDeposit ) ;
1284- await usdc . approve ( engine . address , initialDeposit ) ;
1279+ await usdc
1280+ . approve ( engine . address , initialDeposit )
1281+ . then ( ( tx ) => mineWait ( engineProvider , tx ) ) ;
12851282
12861283 let failedGracefully = false ;
12871284 const receipt = await engine
12881285 . connect ( initialBidder . provider ! )
12891286 . placeInitialBid ( fastVaa , fastOrder . maxFee )
1290- . then ( async ( txReq ) => {
1291- txReq . nonce = await initialBidder . getNonce ( "pending" ) ;
1292- return initialBidder . sendTransaction ( txReq ) ;
1293- } )
1294- . then ( ( tx ) => mineWait ( engineProvider , tx ) )
1287+ . then ( async ( txReq ) => await initialBidder . sendTransaction ( txReq ) )
12951288 . catch ( ( err ) => {
12961289 const error = errorDecoder ( err ) ;
12971290 if ( error . selector == "ErrDeadlineExceeded" ) {
12981291 failedGracefully = true ;
12991292 }
1293+
1294+ // We got a failed transaction so we need to
1295+ // reset the NonceManagers local tracker
1296+ initialBidder . reset ( ) ;
13001297 } ) ;
13011298
13021299 expect ( failedGracefully ) . is . true ;
@@ -1319,15 +1316,10 @@ describe("Fast Market Order Business Logic -- CCTP to CCTP", function (this: Moc
13191316 const usdc = IERC20__factory . connect ( engineEnv . tokenAddress , engineProvider ) ;
13201317 const feeRecipientBefore = await usdc . balanceOf ( engineEnv . feeRecipient ! ) ;
13211318
1322- await sleep ( 1 ) ;
1323-
13241319 const receipt = await engine
13251320 . connect ( initialBidder . provider ! )
13261321 . executeSlowOrderAndRedeem ( fastVaa , params )
1327- . then ( async ( txReq ) => {
1328- //txReq.nonce = await initialBidder.getNonce("pending");
1329- return initialBidder . sendTransaction ( txReq ) ;
1330- } )
1322+ . then ( ( txReq ) => initialBidder . sendTransaction ( txReq ) )
13311323 . then ( ( tx ) => mineWait ( engineProvider , tx ) )
13321324 . catch ( ( err ) => {
13331325 console . log ( err ) ;
0 commit comments