From 0ec773573f192c3a2b375445c889a51252350690 Mon Sep 17 00:00:00 2001 From: "Rob Moore (MakerX)" Date: Mon, 25 Mar 2024 11:27:57 +0800 Subject: [PATCH] chore: Improving test performance (this code triggered teh 17s indexer delay much more!) --- tests/filterFixture.ts | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/tests/filterFixture.ts b/tests/filterFixture.ts index d152f1b..8bc8d8b 100644 --- a/tests/filterFixture.ts +++ b/tests/filterFixture.ts @@ -1,28 +1,11 @@ import { algorandFixture } from '@algorandfoundation/algokit-utils/testing' import { AlgorandFixtureConfig } from '@algorandfoundation/algokit-utils/types/testing' import { SendAtomicTransactionComposerResults, SendTransactionResult } from '@algorandfoundation/algokit-utils/types/transaction' -import { Account, Indexer } from 'algosdk' +import { Account } from 'algosdk' import { expect, vitest } from 'vitest' import { Arc28EventGroup, TransactionFilter } from '../src/types' import { GetSubscribedTransactions, SendXTransactions } from './transactions' -export async function waitForIndexerToIndexRound(round: number, indexer: Indexer): Promise { - let caughtUp = false - let tries = 0 - while (!caughtUp) { - const status = await indexer.makeHealthCheck().do() - if (Number(status.round) >= round) { - caughtUp = true - } else { - tries++ - if (tries > 20) { - throw new Error(`Indexer did not catch up to round ${round} within 20s; received round ${2} instead`) - } - await new Promise((resolve) => setTimeout(resolve, 1000)) - } - } -} - export function filterFixture(fixtureConfig?: AlgorandFixtureConfig) { const localnet = algorandFixture(fixtureConfig) let systemAccount: Account @@ -46,10 +29,9 @@ export function filterFixture(fixtureConfig?: AlgorandFixtureConfig) { const subscribeIndexer = async (filter: TransactionFilter, result: SendTransactionResult, arc28Events?: Arc28EventGroup[]) => { const start = +new Date() // Ensure there is another transaction so algod subscription can process something - const { txIds } = await SendXTransactions(1, systemAccount, localnet.context.algod) + await SendXTransactions(2, systemAccount, localnet.context.algod) // Wait for indexer to catch up - //await localnet.context.waitForIndexerTransaction(txIds[0]) - await waitForIndexerToIndexRound(Number(result.confirmation!.confirmedRound), localnet.context.indexer) + await localnet.context.waitForIndexerTransaction(result.transaction.txID()) const durationInSeconds = (+new Date() - start) / 1000 // eslint-disable-next-line no-console console.debug(`Prepared for subscribing to indexer in ${durationInSeconds} seconds`)