From 828bb009c641374753a8e73328345d1c96ed5c37 Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Wed, 26 Jun 2024 08:51:34 -0400 Subject: [PATCH] fix signer for correct nonce --- evm/ts/src/error.ts | 2 +- evm/ts/src/testing/utils.ts | 5 +-- evm/ts/tests/04__fastMarketOrder.ts | 39 ++++++++++------------ evm/ts/tests/run_integration_test.sh | 48 +++++++++++++++------------- 4 files changed, 45 insertions(+), 49 deletions(-) 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..6e7b2437 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. @@ -1163,7 +1158,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) { @@ -1283,15 +1277,14 @@ describe("Fast Market Order Business Logic -- CCTP to CCTP", function (this: Moc await mintNativeUsdc(usdc, await initialBidder.getAddress(), initialDeposit); await usdc.approve(engine.address, initialDeposit); + await mine(engineProvider); + await sleep(1); + 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") { @@ -1319,14 +1312,14 @@ 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); + txReq.nonce = await initialBidder.getNonce(); + // use `signer` here since the NonceManager fudges up nonce + // because of the prior test's failed transaction + return await initialBidder.signer.sendTransaction(txReq); }) .then((tx) => mineWait(engineProvider, tx)) .catch((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