From a5baf9cd8a2679b89aaa55fc6ab27cdccef936fe Mon Sep 17 00:00:00 2001 From: anilhelvaci Date: Wed, 13 Nov 2024 17:55:36 +0300 Subject: [PATCH] chore(sync-tools): move to `@agoric/client-utils`, adhere to testing speed and new type rules Refs: #10378 --- packages/client-utils/src/sync-tools.js | 13 ++++-- .../test/snapshots/exports.test.js.md | 2 + packages/client-utils/test/sync-tools.test.js | 41 +++++++++++-------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/packages/client-utils/src/sync-tools.js b/packages/client-utils/src/sync-tools.js index 65eaa354457..1f02d62a153 100644 --- a/packages/client-utils/src/sync-tools.js +++ b/packages/client-utils/src/sync-tools.js @@ -396,18 +396,23 @@ const checkCommitteeElectionResult = (electionResult, expectedResult) => { * outcome: string; * deadline: bigint; * }} expectedResult - * @param {{follow: (...params: string[]) => Promise; marshaller: import("@endo/marshal").Marshal}} ambientAuthority + * @param {{ + * follow: (...params: string[]) => Promise; + * marshaller: import("@endo/marshal").Marshal, + * log: typeof console.log, + * setTimeout: typeof global.setTimeout + * }} io * @param {WaitUntilOptions} options */ export const waitUntilElectionResult = ( committeePathBase, expectedResult, - ambientAuthority, + io, options, ) => { - const { follow, marshaller } = ambientAuthority; + const { follow, marshaller, log, setTimeout } = io; - const { maxRetries, retryIntervalMs, errorMessage, log } = + const { maxRetries, retryIntervalMs, errorMessage } = overrideDefaultOptions(options); return retryUntilCondition( diff --git a/packages/client-utils/test/snapshots/exports.test.js.md b/packages/client-utils/test/snapshots/exports.test.js.md index 7c39db1562f..4b08b118a85 100644 --- a/packages/client-utils/test/snapshots/exports.test.js.md +++ b/packages/client-utils/test/snapshots/exports.test.js.md @@ -10,6 +10,7 @@ Generated by [AVA](https://avajs.dev). [ 'boardSlottingMarshaller', + 'fetchLatestEcQuestion', 'makeAgoricNames', 'makeFromBoard', 'makeStargateClient', @@ -23,6 +24,7 @@ Generated by [AVA](https://avajs.dev). 'storageHelper', 'waitUntilAccountFunded', 'waitUntilContractDeployed', + 'waitUntilElectionResult', 'waitUntilInvitationReceived', 'waitUntilOfferExited', 'waitUntilOfferResult', diff --git a/packages/client-utils/test/sync-tools.test.js b/packages/client-utils/test/sync-tools.test.js index 38ee93a3d61..ce241538aa5 100644 --- a/packages/client-utils/test/sync-tools.test.js +++ b/packages/client-utils/test/sync-tools.test.js @@ -1,9 +1,7 @@ /* eslint-env node */ // @ts-check import test from 'ava'; -import '@endo/init/debug.js'; -import { makeMarshal } from '@endo/marshal'; -import { Far } from '@endo/far'; +import { makeMarshal, Far } from '@endo/marshal'; import { waitUntilAccountFunded, waitUntilContractDeployed, @@ -82,6 +80,7 @@ const makeFakeBalanceQuery = () => { test.serial('wait until contract is deployed', async t => { const { setValue, follow } = makeFakeFollow(); + setValue([['arbitrary', true]]); const waitP = waitUntilContractDeployed( 'name', { @@ -476,12 +475,13 @@ test.serial('wait election result: question handle is adhered', async t => { { follow: followByPath, marshaller, + log: console.log, + setTimeout, }, { errorMessage: 'Oops, election did not turn out as expected', maxRetries: 3, - retryIntervalMs: 500, - log: console.log, + retryIntervalMs, }, ); @@ -494,12 +494,13 @@ test.serial('wait election result: question handle is adhered', async t => { { follow: followByPath, marshaller, + log: console.log, + setTimeout, }, { errorMessage: 'Oops, election did not turn out as expected', maxRetries: 5, - retryIntervalMs: 1000, - log: console.log, + retryIntervalMs, }, ); @@ -508,7 +509,7 @@ test.serial('wait election result: question handle is adhered', async t => { ...initState, latestOutcome: { outcome: 'win', question: newQuestionHandle }, }); - setTimeout(() => setValue(updatedState), 2000); + setTimeout(() => setValue(updatedState), DEFAULT_TIMEOUT); await t.notThrowsAsync(waitHappyP); }); @@ -532,12 +533,13 @@ test.serial('wait election result: deadline is adhered', async t => { { follow: followByPath, marshaller, + log: console.log, + setTimeout, }, { errorMessage: 'Oops, election did not turn out as expected', maxRetries: 3, - retryIntervalMs: 500, - log: console.log, + retryIntervalMs, }, ); @@ -550,12 +552,13 @@ test.serial('wait election result: deadline is adhered', async t => { { follow: followByPath, marshaller, + log: console.log, + setTimeout, }, { errorMessage: 'Oops, election did not turn out as expected', maxRetries: 5, - retryIntervalMs: 1000, - log: console.log, + retryIntervalMs, }, ); @@ -567,7 +570,7 @@ test.serial('wait election result: deadline is adhered', async t => { questionHandle, }, }); - setTimeout(() => setValue(updatedState), 2000); + setTimeout(() => setValue(updatedState), DEFAULT_TIMEOUT); await t.notThrowsAsync(waitHappyP); }); @@ -591,12 +594,13 @@ test.serial('wait election result: outcome is adhered', async t => { { follow: followByPath, marshaller, + log: console.log, + setTimeout, }, { errorMessage: 'Oops, election did not turn out as expected', maxRetries: 3, - retryIntervalMs: 500, - log: console.log, + retryIntervalMs, }, ); @@ -609,12 +613,13 @@ test.serial('wait election result: outcome is adhered', async t => { { follow: followByPath, marshaller, + log: console.log, + setTimeout, }, { errorMessage: 'Oops, election did not turn out as expected', maxRetries: 5, - retryIntervalMs: 1000, - log: console.log, + retryIntervalMs, }, ); @@ -623,7 +628,7 @@ test.serial('wait election result: outcome is adhered', async t => { ...initState, latestOutcome: { outcome: 'win', question: questionHandle }, }); - setTimeout(() => setValue(updatedState), 2000); + setTimeout(() => setValue(updatedState), DEFAULT_TIMEOUT); await t.notThrowsAsync(waitHappyP); });