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 113b884
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 53 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
46 changes: 19 additions & 27 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 @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
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 113b884

Please sign in to comment.