diff --git a/evm/ts/src/error.ts b/evm/ts/src/error.ts index 1faef59d..e8fe1edd 100644 --- a/evm/ts/src/error.ts +++ b/evm/ts/src/error.ts @@ -13,7 +13,7 @@ export function errorDecoder(ethersError: any): DecodedErr { const { data } = ethersError; if (!data || data.length < 10 || data.substring(0, 2) != "0x") { - throw new Error("data not custom error"); + throw ethersError; } const selector = data.substring(0, 10); diff --git a/evm/ts/src/testing/utils.ts b/evm/ts/src/testing/utils.ts index 6104385b..01749ce5 100644 --- a/evm/ts/src/testing/utils.ts +++ b/evm/ts/src/testing/utils.ts @@ -56,7 +56,8 @@ export async function mineToPenaltyPeriod( export async function mineWait(provider: ethers.JsonRpcProvider, tx: ethers.TransactionResponse) { await mine(provider); - return tx.wait(); + // 1 is default confirms, 5000ms timeout to prevent hanging forever. + return await tx.wait(1, 5000); } export async function mintNativeUsdc( @@ -66,7 +67,7 @@ export async function mintNativeUsdc( mineBlock: boolean = true, ) { if (!usdc.runner) { - throw new Error("provider must be a StaticJsonRpcProvider"); + throw new Error("provider must be a JsonRpcProvider"); } const provider = usdc.runner.provider as ethers.JsonRpcProvider; diff --git a/evm/ts/tests/04__fastMarketOrder.ts b/evm/ts/tests/04__fastMarketOrder.ts index 549d0fc9..cb489214 100644 --- a/evm/ts/tests/04__fastMarketOrder.ts +++ b/evm/ts/tests/04__fastMarketOrder.ts @@ -1,16 +1,14 @@ import { expect } from "chai"; import { ethers } from "ethers"; import { - EvmTokenRouter, EvmMatchingEngine, - errorDecoder, - OrderResponse, + EvmTokenRouter, MessageDecoder, + OrderResponse, + errorDecoder, } from "../src"; -import { IERC20__factory } from "../src/types"; import { ChainType, - parseLiquidityLayerEnvFile, CircleAttester, GuardianNetwork, LOCALHOSTS, @@ -20,21 +18,18 @@ import { ValidNetwork, WALLET_PRIVATE_KEYS, burnAllUsdc, - mineWait, mine, - mintNativeUsdc, mineToGracePeriod, mineToPenaltyPeriod, + mineWait, + mintNativeUsdc, + parseLiquidityLayerEnvFile, tryNativeToUint8Array, } from "../src/testing"; +import { IERC20__factory } from "../src/types"; import { toChainId } from "@wormhole-foundation/sdk-base"; -import { - deserialize, - keccak256, - serializePayload, - toUniversal, -} from "@wormhole-foundation/sdk-definitions"; +import { deserialize, keccak256, toUniversal } from "@wormhole-foundation/sdk-definitions"; import "@wormhole-foundation/sdk-evm"; // 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 await mintNativeUsdc(usdc, playerAddress, initialDeposit, false); await usdc.approve(engine.address, initialDeposit); - // sleep because otherwise nonce collisions (??) + // give it time to hit the mempool await sleep(1); bids[i].balance = await usdc.balanceOf(playerAddress); @@ -725,6 +720,7 @@ describe("Fast Market Order Business Logic -- CCTP to CCTP", function (this: Moc await mintNativeUsdc(usdc, playerAddress, initialDeposit, false); await usdc.approve(engine.address, initialDeposit); + // give it time to hit the mempool await sleep(1); bids[i].balance = await usdc.balanceOf(playerAddress); @@ -1163,7 +1159,6 @@ describe("Fast Market Order Business Logic -- CCTP to CCTP", function (this: Moc ); }); }); - describe(`No Auction - Deadline Exceeded`, () => { before(`From Network -- Mint USDC`, async () => { if (fromEnv.chainId == MATCHING_ENGINE_CHAIN) { @@ -1281,22 +1276,24 @@ describe("Fast Market Order Business Logic -- CCTP to CCTP", function (this: Moc // Prepare usdc for the auction. const usdc = IERC20__factory.connect(engineEnv.tokenAddress, initialBidder); await mintNativeUsdc(usdc, await initialBidder.getAddress(), initialDeposit); - await usdc.approve(engine.address, initialDeposit); + await usdc + .approve(engine.address, initialDeposit) + .then((tx) => mineWait(engineProvider, tx)); let failedGracefully = false; const receipt = await engine .connect(initialBidder.provider!) .placeInitialBid(fastVaa, fastOrder.maxFee) - .then(async (txReq) => { - txReq.nonce = await initialBidder.getNonce("pending"); - return initialBidder.sendTransaction(txReq); - }) - .then((tx) => mineWait(engineProvider, tx)) + .then(async (txReq) => await initialBidder.sendTransaction(txReq)) .catch((err) => { const error = errorDecoder(err); if (error.selector == "ErrDeadlineExceeded") { failedGracefully = true; } + + // We got a failed transaction so we need to + // reset the NonceManagers local tracker + initialBidder.reset(); }); expect(failedGracefully).is.true; @@ -1319,15 +1316,10 @@ describe("Fast Market Order Business Logic -- CCTP to CCTP", function (this: Moc const usdc = IERC20__factory.connect(engineEnv.tokenAddress, engineProvider); const feeRecipientBefore = await usdc.balanceOf(engineEnv.feeRecipient!); - await sleep(1); - const receipt = await engine .connect(initialBidder.provider!) .executeSlowOrderAndRedeem(fastVaa, params) - .then(async (txReq) => { - //txReq.nonce = await initialBidder.getNonce("pending"); - return initialBidder.sendTransaction(txReq); - }) + .then((txReq) => initialBidder.sendTransaction(txReq)) .then((tx) => mineWait(engineProvider, tx)) .catch((err) => { console.log(err); diff --git a/evm/ts/tests/run_integration_test.sh b/evm/ts/tests/run_integration_test.sh index dc14c9ec..95cbdb30 100644 --- a/evm/ts/tests/run_integration_test.sh +++ b/evm/ts/tests/run_integration_test.sh @@ -8,33 +8,35 @@ LOGS=$ROOT/.anvil mkdir -p $LOGS pgrep anvil > /dev/null + if [ $? -eq 0 ]; then echo "anvil already running, run 'pkill anvil' if you want to stop it to reset state" -else - echo "starting anvil" - - # Avalanche (ME and CCTP). - anvil --port 8547 \ - -m "myth like bonus scare over problem client lizard pioneer submit female collect" \ - --no-mining \ - --fork-url $AVALANCHE_RPC > $LOGS/avalanche.log & - - # Ethereum (CCTP). - anvil --port 8548 \ - -m "myth like bonus scare over problem client lizard pioneer submit female collect" \ - --no-mining \ - --fork-url $ETHEREUM_RPC > $LOGS/ethereum.log & - - # Base (CCTP). - anvil --port 8549 \ - -m "myth like bonus scare over problem client lizard pioneer submit female collect" \ - --no-mining \ - --fork-url $BASE_RPC > $LOGS/base.log & - - # Chill. - sleep 2 + exit 1 fi +echo "starting anvil" + +# Avalanche (ME and CCTP). +anvil --port 8547 \ + -m "myth like bonus scare over problem client lizard pioneer submit female collect" \ + --no-mining \ + --fork-url $AVALANCHE_RPC > $LOGS/avalanche.log & + +# Ethereum (CCTP). +anvil --port 8548 \ + -m "myth like bonus scare over problem client lizard pioneer submit female collect" \ + --no-mining \ + --fork-url $ETHEREUM_RPC > $LOGS/ethereum.log & + +# Base (CCTP). +anvil --port 8549 \ + -m "myth like bonus scare over problem client lizard pioneer submit female collect" \ + --no-mining \ + --fork-url $BASE_RPC > $LOGS/base.log & + +# Chill. +sleep 2 + # Double-check number of anvil instances. if [ "$( pgrep anvil | wc -l )" -ne 3 ]; then