From e13dd80ea8cf219cd18b4af50d267f751e4b7746 Mon Sep 17 00:00:00 2001 From: derpy-duck <115193320+derpy-duck@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:57:19 -0400 Subject: [PATCH] wait for success --- ts-scripts/getStatus.ts | 26 ++++++++++++++++++++++++++ ts-scripts/hello_wormhole.test.ts | 18 +++--------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/ts-scripts/getStatus.ts b/ts-scripts/getStatus.ts index ec1ed14..0c92b73 100644 --- a/ts-scripts/getStatus.ts +++ b/ts-scripts/getStatus.ts @@ -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`); + } +}; diff --git a/ts-scripts/hello_wormhole.test.ts b/ts-scripts/hello_wormhole.test.ts index 6842943..fd8c4bc 100644 --- a/ts-scripts/hello_wormhole.test.ts +++ b/ts-scripts/hello_wormhole.test.ts @@ -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; @@ -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 });