Skip to content

Commit

Permalink
chore(sync-tools): move to @agoric/client-utils, adhere to testing …
Browse files Browse the repository at this point in the history
…speed and new type rules

Refs: #10378
  • Loading branch information
anilhelvaci committed Nov 15, 2024
1 parent abc48dc commit a5baf9c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
13 changes: 9 additions & 4 deletions packages/client-utils/src/sync-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,23 @@ const checkCommitteeElectionResult = (electionResult, expectedResult) => {
* outcome: string;
* deadline: bigint;
* }} expectedResult
* @param {{follow: (...params: string[]) => Promise<object>; marshaller: import("@endo/marshal").Marshal<any>}} ambientAuthority
* @param {{
* follow: (...params: string[]) => Promise<object>;
* marshaller: import("@endo/marshal").Marshal<any>,
* 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(
Expand Down
2 changes: 2 additions & 0 deletions packages/client-utils/test/snapshots/exports.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Generated by [AVA](https://avajs.dev).
[
'boardSlottingMarshaller',
'fetchLatestEcQuestion',
'makeAgoricNames',
'makeFromBoard',
'makeStargateClient',
Expand All @@ -23,6 +24,7 @@ Generated by [AVA](https://avajs.dev).
'storageHelper',
'waitUntilAccountFunded',
'waitUntilContractDeployed',
'waitUntilElectionResult',
'waitUntilInvitationReceived',
'waitUntilOfferExited',
'waitUntilOfferResult',
Expand Down
41 changes: 23 additions & 18 deletions packages/client-utils/test/sync-tools.test.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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,
},
);

Expand All @@ -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,
},
);

Expand All @@ -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);
});
Expand All @@ -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,
},
);

Expand All @@ -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,
},
);

Expand All @@ -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);
});
Expand All @@ -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,
},
);

Expand All @@ -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,
},
);

Expand All @@ -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);
});

0 comments on commit a5baf9c

Please sign in to comment.