Skip to content

Commit

Permalink
Merge pull request #12 from wormhole-foundation/use-sleep
Browse files Browse the repository at this point in the history
use sleep instead of explicit promise
  • Loading branch information
derpy-duck authored Aug 8, 2023
2 parents 5cf4b0c + 386e900 commit 63f1257
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
24 changes: 9 additions & 15 deletions ts-scripts/hello_wormhole.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from "@jest/globals";
import { ethers } from "ethers";
import { getHelloWormhole, getWallet, getDeliveryHash } from "./utils";
import { getHelloWormhole, getWallet, getDeliveryHash, sleep } from "./utils";
import { CHAIN_ID_TO_NAME } from "@certusone/wormhole-sdk";

const sourceChain = 6;
Expand Down Expand Up @@ -39,20 +39,14 @@ describe("Hello Wormhole Integration Tests on Testnet", () => {
{ network: "TESTNET" }
);
console.log("Waiting for delivery...");
await new Promise((resolve) => {
let seconds = 0;
const interval = setInterval(async () => {
seconds += 1;
const completed =
await targetHelloWormholeContract.seenDeliveryVaaHashes(
deliveryHash
);
if (completed) {
resolve("done");
clearInterval(interval);
}
}, 1000);
});
while (true) {
await sleep(1000);
const completed =
await targetHelloWormholeContract.seenDeliveryVaaHashes(deliveryHash);
if (completed) {
break;
}
}

console.log(`Reading greeting`);
const readGreeting = await targetHelloWormholeContract.latestGreeting();
Expand Down
2 changes: 2 additions & 0 deletions ts-scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ import {
CHAINS,
} from "@certusone/wormhole-sdk";

export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

// Temporarily here - will move to the typescript SDK soon so it can be directly imported from there!
export async function getDeliveryHash(
rx: ethers.ContractReceipt,
Expand Down

0 comments on commit 63f1257

Please sign in to comment.