From 386e9008ec27e0a7600860c1de7188db0b473ac9 Mon Sep 17 00:00:00 2001 From: derpy-duck <115193320+derpy-duck@users.noreply.github.com> Date: Tue, 8 Aug 2023 14:07:21 -0400 Subject: [PATCH] use sleep instead of explicit promise --- ts-scripts/hello_wormhole.test.ts | 24 +++++++++--------------- ts-scripts/utils.ts | 2 ++ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/ts-scripts/hello_wormhole.test.ts b/ts-scripts/hello_wormhole.test.ts index fd12868..6842943 100644 --- a/ts-scripts/hello_wormhole.test.ts +++ b/ts-scripts/hello_wormhole.test.ts @@ -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; @@ -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(); diff --git a/ts-scripts/utils.ts b/ts-scripts/utils.ts index e61f2c7..12a3582 100644 --- a/ts-scripts/utils.ts +++ b/ts-scripts/utils.ts @@ -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,