Skip to content

Commit

Permalink
wait for success
Browse files Browse the repository at this point in the history
  • Loading branch information
derpy-duck committed Nov 3, 2023
1 parent 231c267 commit e13dd80
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
26 changes: 26 additions & 0 deletions ts-scripts/getStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,29 @@ export async function getStatus(
const status = info.targetChainStatus.events[0].status;
return { status, info: info.stringified || "Info not obtained" };
}

export const DeliveryStatus = relayer.DeliveryStatus;

export const waitForDelivery = async (
sourceChain: ChainName,
transactionHash: string
) => {
let pastStatusString = "";
let waitCount = 0;
while (true) {
let waitTime = 15;
if (waitCount > 5) {
waitTime = 60;
}
await new Promise((resolve) => setTimeout(resolve, 1000 * waitTime));
waitCount += 1;

const res = await getStatus(sourceChain, transactionHash);
if (res.info !== pastStatusString) {
console.log(res.info);
pastStatusString = res.info;
}
if (res.status !== DeliveryStatus.PendingDelivery) break;
console.log(`\nContinuing to wait for delivery\n`);
}
};
18 changes: 3 additions & 15 deletions ts-scripts/hello_wormhole.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { describe, expect, test } from "@jest/globals";
import { ethers } from "ethers";
import { getHelloWormhole, getWallet, getDeliveryHash, sleep } from "./utils";
import { CHAIN_ID_TO_NAME } from "@certusone/wormhole-sdk";
import { waitForDelivery } from "./getStatus";

const sourceChain = 6;
const targetChain = 14;
Expand Down Expand Up @@ -33,26 +34,13 @@ describe("Hello Wormhole Integration Tests on Testnet", () => {
console.log(`Transaction hash: ${tx.hash}`);
const rx = await tx.wait();

const deliveryHash = await getDeliveryHash(
rx,
CHAIN_ID_TO_NAME[sourceChain],
{ network: "TESTNET" }
);
console.log("Waiting for delivery...");
while (true) {
await sleep(1000);
const completed =
await targetHelloWormholeContract.seenDeliveryVaaHashes(deliveryHash);
if (completed) {
break;
}
}
await waitForDelivery(CHAIN_ID_TO_NAME[sourceChain], tx.hash);

console.log(`Reading greeting`);
const readGreeting = await targetHelloWormholeContract.latestGreeting();
console.log(`Latest greeting: ${readGreeting}`);
expect(readGreeting).toBe(arbitraryGreeting);
},
60 * 1000
60 * 1000 * 60
); // timeout
});

0 comments on commit e13dd80

Please sign in to comment.