Skip to content

Commit

Permalink
fix signer for correct nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Jun 26, 2024
1 parent e7c57b9 commit 828bb00
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 49 deletions.
2 changes: 1 addition & 1 deletion evm/ts/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions evm/ts/src/testing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand Down
39 changes: 16 additions & 23 deletions evm/ts/tests/04__fastMarketOrder.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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) => {
Expand Down
48 changes: 25 additions & 23 deletions evm/ts/tests/run_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 828bb00

Please sign in to comment.