diff --git a/a3p-integration/proposals/z:acceptance/test-lib/sync-tools.js b/a3p-integration/proposals/z:acceptance/test-lib/sync-tools.js index 77683a04d8f7..2d59deccba5f 100644 --- a/a3p-integration/proposals/z:acceptance/test-lib/sync-tools.js +++ b/a3p-integration/proposals/z:acceptance/test-lib/sync-tools.js @@ -1,30 +1,27 @@ /** - * @file The purpose of this file is to bring together a set of tool that + * @file The purpose of this file is to bring together a set of tools that * developers can use to synchronize operations they carry out in their tests. - * + * * These operations include; - * - Making sure a core-eval resulted succesfully deploying a contract - * - Making sure a core-eval succesfully sent zoe invitations to committee members for governance + * - Making sure a core-eval resulted in successfully deploying a contract + * - Making sure a core-eval successfully sent zoe invitations to committee members for governance * - Making sure an account is successfully funded with vbank assets like IST, BLD etc. * - operation: query dest account's balance * - condition: dest account has a balance >= sent token - * - Making sure an offer is in a specific state, such as; - * - seated - * - successfuly resulted - * - error - * + * - Making sure an offer resulted successfully + * */ /** - * @typedef {object} RetyrOptions + * @typedef {object} RetryOptions * @property {number} maxRetries * @property {number} retryIntervalMs * @property {(...arg0: string[]) => void} log * @property {(object) => void} [setTimeout] * @property {string} [errorMessage=Error] - * - * - * @typedef {object} CosmosBalanceThresold + * + * + * @typedef {object} CosmosBalanceThreshold * @property {string} denom * @property {number} value */ @@ -32,252 +29,243 @@ const ambientSetTimeout = globalThis.setTimeout; /** - * - * @param {number} ms - * @param {*} sleepOptions - * @returns + * From https://github.com/Agoric/agoric-sdk/blob/442f07c8f0af03281b52b90e90c27131eef6f331/multichain-testing/tools/sleep.ts#L10 + * + * @param {number} ms + * @param {*} sleepOptions */ -export const sleep = ( - ms, - { log = () => { }, setTimeout = ambientSetTimeout } -) => - new Promise(resolve => { - // @ts-ignore - log(`Sleeping for ${ms}ms...`); - setTimeout(resolve, ms); - }); +const sleep = (ms, { log = () => {}, setTimeout = ambientSetTimeout }) => + new Promise(resolve => { + // @ts-ignore + log(`Sleeping for ${ms}ms...`); + setTimeout(resolve, ms); + }); /** - * - * @param {() => Promise} operation - * @param {(result) => boolean} condition - * @param {string} message - * @param {RetyrOptions} options - * @returns + * From https://github.com/Agoric/agoric-sdk/blob/442f07c8f0af03281b52b90e90c27131eef6f331/multichain-testing/tools/sleep.ts#L24 + * + * @param {() => Promise} operation + * @param {(result: any) => boolean} condition + * @param {string} message + * @param {RetryOptions} options */ const retryUntilCondition = async ( - operation, - condition, - message, - { - maxRetries = 6, - retryIntervalMs = 3500, - log, - setTimeout, - } + operation, + condition, + message, + { maxRetries = 6, retryIntervalMs = 3500, log, setTimeout }, ) => { - console.log({ maxRetries, retryIntervalMs, message }); - let retries = 0; - - while (retries < maxRetries) { - try { - const result = await operation(); - console.log('RESULT', result) - if (condition(result)) { - return result; - } - } catch (error) { - if (error instanceof Error) { - log(`Error: ${error.message}`); - } else { - log(`Unknown error: ${String(error)}`); - } - } - - retries++; - console.log( - `Retry ${retries}/${maxRetries} - Waiting for ${retryIntervalMs}ms for ${message}...`, - ); - await sleep(retryIntervalMs, { log, setTimeout }); + console.log({ maxRetries, retryIntervalMs, message }); + let retries = 0; + + while (retries < maxRetries) { + try { + const result = await operation(); + log('RESULT', result); + if (condition(result)) { + return result; + } + } catch (error) { + if (error instanceof Error) { + log(`Error: ${error.message}`); + } else { + log(`Unknown error: ${String(error)}`); + } } - throw Error(`${message} condition failed after ${maxRetries} retries.`); -}; + retries++; + console.log( + `Retry ${retries}/${maxRetries} - Waiting for ${retryIntervalMs}ms for ${message}...`, + ); + await sleep(retryIntervalMs, { log, setTimeout }); + } -export const makeRetryUntilCondition = (defaultOptions) => { - /** - * Retry an asynchronous operation until a condition is met. - * Defaults to maxRetries = 6, retryIntervalMs = 3500 - */ - return ( - operation, - condition, - message, - options, - ) => - retryUntilCondition(operation, condition, message, { - ...defaultOptions, - ...options, - }); + throw Error(`${message} condition failed after ${maxRetries} retries.`); }; /** - * Making sure a core-eval resulted succesfully deploying a contract + * @param {RetryOptions} options */ +const overrideDefaultOptions = options => { + const defaultValues = { + maxRetries: 6, + retryIntervalMs: 3500, + log: console.log, + errorMessage: 'Error', + }; + + return { ...defaultValues, ...options }; +}; + +///////////// Making sure a core-eval resulted successfully deploying a contract ///////////// + const makeGetInstances = follow => async () => { - const instanceEntries = await follow( - '-lF', - `:published.agoricNames.instance`, - ); + const instanceEntries = await follow( + '-lF', + `:published.agoricNames.instance`, + ); - return Object.fromEntries(instanceEntries); + return Object.fromEntries(instanceEntries); }; /** - * - * @param {string} contractName - * @param {{follow: () => object, setTimeout: (object) => void}} ambientAuthroity - * @param {RetyrOptions} options - * @returns + * + * @param {string} contractName + * @param {{follow: () => object, setTimeout: (object) => void}} ambientAuthority + * @param {RetryOptions} options */ -export const waitUntilContractDeplyed = (contractName, ambientAuthroity, options) => { - const { follow, setTimeout } = ambientAuthroity; - const getInstances = makeGetInstances(follow); - const { maxRetries = 6, retryIntervalMs = 3500, log = console.log, errorMessage = "Error" } = options; - - return retryUntilCondition( - getInstances, - instanceObject => Object.keys(instanceObject).includes(contractName), - errorMessage, - // @ts-ignore - { maxRetries, retryIntervalMs, log, setTimeout } - ) +export const waitUntilContractDeployed = ( + contractName, + ambientAuthority, + options, +) => { + const { follow, setTimeout } = ambientAuthority; + const getInstances = makeGetInstances(follow); + const { maxRetries, retryIntervalMs, errorMessage, log } = + overrideDefaultOptions(options); + + return retryUntilCondition( + getInstances, + instanceObject => Object.keys(instanceObject).includes(contractName), + errorMessage, + { maxRetries, retryIntervalMs, log, setTimeout }, + ); }; -/** - * Making sure an account is successfully funded with vbank assets like IST, BLD etc. - * - operation: query dest account's balance - * - condition: dest account has a balance >= sent token - */ +///////////// Making sure an account is successfully funded with vbank assets like IST, BLD etc. /////////////// -const makeQueryCosmosBalace = queryCb => async dest => { - const conins = await queryCb('bank', 'balances', dest); - return conins.balances; +const makeQueryCosmosBalance = queryCb => async dest => { + const coins = await queryCb('bank', 'balances', dest); + return coins.balances; }; /** - * - * @param {Array} balances - * @param {CosmosBalanceThresold} thresold + * + * @param {Array} balances + * @param {CosmosBalanceThreshold} threshold * @returns {boolean} */ -const checkCosmosBalance = (balances, thresold) => { - const balance = [...balances].find(({ denom }) => denom === thresold.denom); - return Number(balance.amount) >= thresold.value; -} +const checkCosmosBalance = (balances, threshold) => { + const balance = [...balances].find(({ denom }) => denom === threshold.denom); + return Number(balance.amount) >= threshold.value; +}; /** - * @param {string} destAcct - * @param {{query: () => Promise, setTimeout: (object) => void}} ambientAuthroity + * @param {string} destAcct + * @param {{query: () => Promise, setTimeout: (object) => void}} ambientAuthority * @param {{denom: string, value: number}} threshold - * @param {RetyrOptions} options - * @returns + * @param {RetryOptions} options */ -export const waitUntilAccountFunded = (destAcct, ambientAuthroity, threshold, options) => { - const { query, setTimeout } = ambientAuthroity; - const queryCosmosBalance = makeQueryCosmosBalace(query); - const { maxRetries = 6, retryIntervalMs = 3500, log = console.log, errorMessage = "Error" } = options; - - return retryUntilCondition( - async () => queryCosmosBalance(destAcct), - balances => checkCosmosBalance(balances, threshold), - errorMessage, - // @ts-ignore - { maxRetries, retryIntervalMs, log, setTimeout } - ) +export const waitUntilAccountFunded = ( + destAcct, + ambientAuthority, + threshold, + options, +) => { + const { query, setTimeout } = ambientAuthority; + const queryCosmosBalance = makeQueryCosmosBalance(query); + const { maxRetries, retryIntervalMs, errorMessage, log } = + overrideDefaultOptions(options); + + return retryUntilCondition( + async () => queryCosmosBalance(destAcct), + balances => checkCosmosBalance(balances, threshold), + errorMessage, + { maxRetries, retryIntervalMs, log, setTimeout }, + ); }; -/** - * - Making sure an offer is resulted; - */ +///////////// Making sure an offers get results ///////////// const makeQueryWallet = follow => async (/** @type {String} */ addr) => { - const update = await follow( - '-lF', - `:published.wallet.${addr}`, - ); + const update = await follow('-lF', `:published.wallet.${addr}`); - return update; + return update; }; /** - * - * @param {object} offerStatus - * @param {boolean} waitForPayouts - * @param {string} offerId - * @returns + * + * @param {object} offerStatus + * @param {boolean} waitForPayouts + * @param {string} offerId */ const checkOfferState = (offerStatus, waitForPayouts, offerId) => { - const { updated, status } = offerStatus; + const { updated, status } = offerStatus; - if (updated !== "offerStatus") return false; - if (!status) return false; - if (status.id !== offerId) return false; - if (!status.numWantsSatisfied || status.numWantsSatisfied !== 1) return false; - if (waitForPayouts && status.result && status.payouts) return true; - if (!waitForPayouts && status.result) return true; + if (updated !== 'offerStatus') return false; + if (!status) return false; + if (status.id !== offerId) return false; + if (!status.numWantsSatisfied || status.numWantsSatisfied !== 1) return false; + if (waitForPayouts && status.result && status.payouts) return true; + if (!waitForPayouts && status.result) return true; - return false; + return false; }; /** - * - * @param {string} addr - * @param {string} offerId - * @param {boolean} waitForPayouts - * @param {{follow: () => object, setTimeout: (object) => void}} ambientAuthroity - * @param {RetyrOptions} options - * @returns + * + * @param {string} addr + * @param {string} offerId + * @param {boolean} waitForPayouts + * @param {{follow: () => object, setTimeout: (object) => void}} ambientAuthority + * @param {RetryOptions} options */ -export const waitUntilOfferResult = (addr, offerId, waitForPayouts, ambientAuthroity, options) => { - const { follow, setTimeout } = ambientAuthroity; - const queryWallet = makeQueryWallet(follow); - const { maxRetries = 6, retryIntervalMs = 3500, log = console.log, errorMessage = "Error" } = options; - - return retryUntilCondition( - async () => queryWallet(addr), - status => checkOfferState(status, waitForPayouts, offerId), - errorMessage, - // @ts-ignore - { maxRetries, retryIntervalMs, log, setTimeout } - ) +export const waitUntilOfferResult = ( + addr, + offerId, + waitForPayouts, + ambientAuthority, + options, +) => { + const { follow, setTimeout } = ambientAuthority; + const queryWallet = makeQueryWallet(follow); + const { maxRetries, retryIntervalMs, errorMessage, log } = + overrideDefaultOptions(options); + + return retryUntilCondition( + async () => queryWallet(addr), + status => checkOfferState(status, waitForPayouts, offerId), + errorMessage, + { maxRetries, retryIntervalMs, log, setTimeout }, + ); }; -/** - * Making sure a core-eval succesfully sent zoe invitations to committee members for governance - */ +///////////// Making sure a core-eval successfully sent zoe invitations to committee members for governance ///////////// /** - * - * @param {{ updated: string, currentAmount: any }} update + * + * @param {{ updated: string, currentAmount: any }} update * @returns {boolean} */ const checkForInvitation = update => { - const { updated, currentAmount } = update; + const { updated, currentAmount } = update; + + if (updated !== 'balance') return false; + if (!currentAmount || !currentAmount.brand) return false; - if (updated !== 'balance') return false; - if (!currentAmount || !currentAmount.brand) return false; - - return currentAmount.brand.includes('Invitation'); + return currentAmount.brand.includes('Invitation'); }; /** - * - * @param {string} addr - * @param {{follow: () => object, setTimeout: (object) => void}} ambientAuthroity - * @param {RetyrOptions} options - * @returns + * + * @param {string} addr + * @param {{follow: () => object, setTimeout: (object) => void}} ambientAuthority + * @param {RetryOptions} options */ -export const waitUntilInvitationReceived = (addr, ambientAuthroity, options) => { - const { follow, setTimeout } = ambientAuthroity; - const queryWallet = makeQueryWallet(follow); - const { maxRetries = 6, retryIntervalMs = 3500, log = console.log, errorMessage = "Error" } = options; - - return retryUntilCondition( - async () => queryWallet(addr), - checkForInvitation, - errorMessage, - // @ts-ignore - { maxRetries, retryIntervalMs, log, setTimeout } - ) -}; \ No newline at end of file +export const waitUntilInvitationReceived = ( + addr, + ambientAuthority, + options, +) => { + const { follow, setTimeout } = ambientAuthority; + const queryWallet = makeQueryWallet(follow); + const { maxRetries, retryIntervalMs, errorMessage, log } = + overrideDefaultOptions(options); + + return retryUntilCondition( + async () => queryWallet(addr), + checkForInvitation, + errorMessage, + { maxRetries, retryIntervalMs, log, setTimeout }, + ); +}; diff --git a/a3p-integration/proposals/z:acceptance/test-lib/sync-tools.test.js b/a3p-integration/proposals/z:acceptance/test-lib/sync-tools.test.js index 922f4a485e11..c79b090a4134 100644 --- a/a3p-integration/proposals/z:acceptance/test-lib/sync-tools.test.js +++ b/a3p-integration/proposals/z:acceptance/test-lib/sync-tools.test.js @@ -1,525 +1,412 @@ // @ts-check import test from 'ava'; import '@endo/init/debug.js'; -import { waitUntilAccountFunded, waitUntilContractDeplyed, waitUntilInvitationReceived, waitUntilOfferResult } from './sync-tools.js'; - -const sampleOfferStatus = { - "status": { - "id": 1726389716785, - "invitationSpec": { - "invitationMakerName": "CloseVault", - "previousOffer": "1711355582081", - "source": "continuing" - }, - "numWantsSatisfied": 1, - "payouts": { - "Collateral": { - "brand": "[Alleged: SEVERED: stTIA brand {}]", - "value": "10347167" - }, - "Minted": { - "brand": "[Alleged: SEVERED: IST brand {}]", - "value": "0" - } - }, - "proposal": { - "give": { - "Minted": { - "brand": "[Alleged: SEVERED: IST brand {}]", - "value": "0" - } - }, - "want": { - "Collateral": { - "brand": "[Alleged: SEVERED: stTIA brand {}]", - "value": "10347167" - } - } - }, - "result": "your vault is closed, thank you for your business" - }, - "updated": "offerStatus" -}; - -const sampleBalanceUpdate = { - "currentAmount": { - "brand": "[Alleged: SEVERED: Zoe Invitation brand {}]", - "value": [] - }, - "updated": "balance" -} - -const sampleInstance = [ - [ - "ATOM-USD price feed", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "Crabble", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "CrabbleCommittee", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "CrabbleGovernor", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "VaultFactory", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "VaultFactoryGovernor", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "econCommitteeCharter", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "economicCommittee", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "feeDistributor", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "kread", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "kreadCommittee", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "kreadCommitteeCharter", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "provisionPool", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "psm-IST-DAI_axl", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "psm-IST-DAI_grv", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "psm-IST-USDC", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "psm-IST-USDC_axl", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "psm-IST-USDC_grv", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "psm-IST-USDT", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "psm-IST-USDT_axl", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "psm-IST-USDT_grv", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "reserve", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "reserveGovernor", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "scaledPriceAuthority-stATOM", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "scaledPriceAuthority-stOSMO", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "scaledPriceAuthority-stTIA", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "scaledPriceAuthority-stkATOM", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "stATOM-USD price feed", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "stOSMO-USD price feed", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "stTIA-USD price feed", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "stkATOM-USD price feed", - "[Alleged: SEVERED: InstanceHandle {}]" - ], - [ - "walletFactory", - "[Alleged: SEVERED: InstanceHandle {}]" - ] -] - -const cosmosBalanceSample = { - "balances": [ - { - "denom": "ubld", - "amount": "364095061" - }, - { - "denom": "uist", - "amount": "2257215" - } - ], - "pagination": { - "next_key": null, - "total": "0" - } -} +import { + waitUntilAccountFunded, + waitUntilContractDeployed, + waitUntilInvitationReceived, + waitUntilOfferResult, +} from './sync-tools.js'; const makeFakeFollow = () => { - let value = [[]]; + let value = [[]]; - const setValue = newValue => value = newValue; - const follow = () => Promise.resolve(value); + const setValue = newValue => (value = newValue); + const follow = () => Promise.resolve(value); - return { setValue, follow }; -} + return { setValue, follow }; +}; const makeFakeBalanceQuery = () => { - let result = { - "balances": [ - { - "denom": "ubld", - "amount": "364095061" - }, - { - "denom": "uist", - "amount": "2257215" - } - ], - "pagination": { - "next_key": null, - "total": "0" - } - } - - const setResult = newValue => result = newValue; - const query = () => Promise.resolve(result); - - return { setResult, query }; + let result = { + balances: [ + { + denom: 'ubld', + amount: '364095061', + }, + { + denom: 'uist', + amount: '2257215', + }, + ], + pagination: { + next_key: null, + total: '0', + }, + }; + + const setResult = newValue => (result = newValue); + const query = () => Promise.resolve(result); + + return { setResult, query }; }; test.serial('wait until contract is deployed', async t => { - const { setValue, follow } = makeFakeFollow(); - const waitP = waitUntilContractDeplyed('name', { - follow, - setTimeout: globalThis.setTimeout - }, { maxRetries: 5, retryIntervalMs: 1000, log: t.log, errorMessage: "Contact not deplyed yet" }); + const { setValue, follow } = makeFakeFollow(); + const waitP = waitUntilContractDeployed( + 'name', + { + follow, + setTimeout: globalThis.setTimeout, + }, + { + maxRetries: 5, + retryIntervalMs: 1000, + log: t.log, + errorMessage: 'Contract not deployed yet', + }, + ); - setTimeout(() => setValue([["name", true]]), 3000); // set desired value after third retry + setTimeout(() => setValue([['name', true]]), 3000); // set desired value after third retry - await t.notThrowsAsync(waitP); + await t.notThrowsAsync(waitP); }); test.serial('wait until account funded', async t => { - const { setResult, query } = makeFakeBalanceQuery(); - - const waitP = waitUntilAccountFunded( - 'agoric12345', - { query, setTimeout: globalThis.setTimeout }, - { denom: 'ufake', value: 100_000 }, - { maxRetries: 5, retryIntervalMs: 1000, log: t.log, errorMessage: "Account not funded yet" } - ) - - - const desiredResult = { - "balances": [ - { - "denom": "ubld", - "amount": "364095061" - }, - { - "denom": "uist", - "amount": "2257215" - }, - { - "denom": "ufake", - "amount": "100001" - }, - ], - "pagination": { - "next_key": null, - "total": "0" - } - } - setTimeout(() => setResult(desiredResult), 3000); // set desired value after third retry - await t.notThrowsAsync(waitP); -}) + const { setResult, query } = makeFakeBalanceQuery(); + + const waitP = waitUntilAccountFunded( + 'agoric12345', + { query, setTimeout: globalThis.setTimeout }, + { denom: 'ufake', value: 100_000 }, + { + maxRetries: 5, + retryIntervalMs: 1000, + log: t.log, + errorMessage: 'Account not funded yet', + }, + ); + + const desiredResult = { + balances: [ + { + denom: 'ubld', + amount: '364095061', + }, + { + denom: 'uist', + amount: '2257215', + }, + { + denom: 'ufake', + amount: '100001', + }, + ], + pagination: { + next_key: null, + total: '0', + }, + }; + setTimeout(() => setResult(desiredResult), 3000); // set desired value after third retry + await t.notThrowsAsync(waitP); +}); test.serial('wait until account funded, insufficient balance', async t => { - const { setResult, query } = makeFakeBalanceQuery(); - - const waitP = waitUntilAccountFunded( - 'agoric12345', - { query, setTimeout: globalThis.setTimeout }, - { denom: 'ufake', value: 100_000 }, - { maxRetries: 5, retryIntervalMs: 1000, log: t.log, errorMessage: "Account not funded yet" } - ) - - - const desiredResult = { - "balances": [ - { - "denom": "ubld", - "amount": "364095061" - }, - { - "denom": "uist", - "amount": "2257215" - }, - { - "denom": "ufake", - "amount": "90000" - }, - ], - "pagination": { - "next_key": null, - "total": "0" - } - } - setTimeout(() => setResult(desiredResult), 3000); // set desired value after third retry - await t.throwsAsync(waitP); + const { setResult, query } = makeFakeBalanceQuery(); + + const waitP = waitUntilAccountFunded( + 'agoric12345', + { query, setTimeout: globalThis.setTimeout }, + { denom: 'ufake', value: 100_000 }, + { + maxRetries: 5, + retryIntervalMs: 1000, + log: t.log, + errorMessage: 'Account not funded yet', + }, + ); + + const desiredResult = { + balances: [ + { + denom: 'ubld', + amount: '364095061', + }, + { + denom: 'uist', + amount: '2257215', + }, + { + denom: 'ufake', + amount: '90000', + }, + ], + pagination: { + next_key: null, + total: '0', + }, + }; + setTimeout(() => setResult(desiredResult), 3000); // set desired value after third retry + await t.throwsAsync(waitP, { message: /Account not funded yet/ }); }); -test.serial('wait until offer result, balance update - should throw', async t => { +test.serial( + 'wait until offer result, balance update - should throw', + async t => { const { setValue, follow } = makeFakeFollow(); - setValue({ status: {}, updated: "balance" }); + setValue({ status: {}, updated: 'balance' }); const waitP = waitUntilOfferResult( - 'agoric12345', - 'my-offer', - false, - { follow, setTimeout: globalThis.setTimeout }, - { - maxRetries: 5, - retryIntervalMs: 1000, - log: t.log, - errorMessage: "Wrong update type" - } + 'agoric12345', + 'my-offer', + false, + { follow, setTimeout: globalThis.setTimeout }, + { + maxRetries: 5, + retryIntervalMs: 1000, + log: t.log, + errorMessage: 'Wrong update type', + }, ); - await t.throwsAsync(waitP); -}); + await t.throwsAsync(waitP, { message: /Wrong update type/ }); + }, +); test.serial('wait until offer result, wrong id - should throw', async t => { - const { setValue, follow } = makeFakeFollow(); - setValue({ status: { id: 'your-offer' }, updated: "offerStatus" }); - - const waitP = waitUntilOfferResult( - 'agoric12345', - 'my-offer', - false, - { follow, setTimeout: globalThis.setTimeout }, - { - maxRetries: 5, - retryIntervalMs: 1000, - log: t.log, - errorMessage: "Wrong offer id" - } - ); + const { setValue, follow } = makeFakeFollow(); + setValue({ status: { id: 'your-offer' }, updated: 'offerStatus' }); + + const waitP = waitUntilOfferResult( + 'agoric12345', + 'my-offer', + false, + { follow, setTimeout: globalThis.setTimeout }, + { + maxRetries: 5, + retryIntervalMs: 1000, + log: t.log, + errorMessage: 'Wrong offer id', + }, + ); - await t.throwsAsync(waitP); + await t.throwsAsync(waitP, { message: /Wrong offer id/ }); }); test.serial('wait until offer result, no "status" - should throw', async t => { - const { setValue, follow } = makeFakeFollow(); - setValue({ updated: "offerStatus" }); - - const waitP = waitUntilOfferResult( - 'agoric12345', - 'my-offer', - false, - { follow, setTimeout: globalThis.setTimeout }, - { - maxRetries: 5, - retryIntervalMs: 1000, - log: t.log, - errorMessage: 'No "status" object' - } - ); + const { setValue, follow } = makeFakeFollow(); + setValue({ updated: 'offerStatus' }); + + const waitP = waitUntilOfferResult( + 'agoric12345', + 'my-offer', + false, + { follow, setTimeout: globalThis.setTimeout }, + { + maxRetries: 5, + retryIntervalMs: 1000, + log: t.log, + errorMessage: 'No "status" object', + }, + ); - await t.throwsAsync(waitP); + await t.throwsAsync(waitP, { message: /No "status" object/ }); }); -test.serial('wait until offer result, numWantsSatisfied not equals to 1 - should throw', async t => { +test.serial( + 'wait until offer result, numWantsSatisfied not equals to 1 - should throw', + async t => { const { setValue, follow } = makeFakeFollow(); - setValue({ status: { id: 'my-offer', numWantsSatisfied: 0 }, updated: "offerStatus" }); + setValue({ + status: { id: 'my-offer', numWantsSatisfied: 0 }, + updated: 'offerStatus', + }); const waitP = waitUntilOfferResult( - 'agoric12345', - 'my-offer', - false, - { follow, setTimeout: globalThis.setTimeout }, - { - maxRetries: 5, - retryIntervalMs: 1000, - log: t.log, - errorMessage: '"numWantsSatisfied" is not 1' - } + 'agoric12345', + 'my-offer', + false, + { follow, setTimeout: globalThis.setTimeout }, + { + maxRetries: 5, + retryIntervalMs: 1000, + log: t.log, + errorMessage: '"numWantsSatisfied" is not 1', + }, ); - await t.throwsAsync(waitP); -}); + await t.throwsAsync(waitP, { message: /"numWantsSatisfied" is not 1/ }); + }, +); test.serial('wait until offer result, do not wait for "payouts"', async t => { - const { setValue, follow } = makeFakeFollow(); - setValue({ status: { id: 'my-offer' }, updated: "offerStatus" }); - - const waitP = waitUntilOfferResult( - 'agoric12345', - 'my-offer', - false, - { follow, setTimeout: globalThis.setTimeout }, - { - maxRetries: 7, - retryIntervalMs: 1000, - log: t.log, - errorMessage: 'offer not resulted on time' - } - ); - - setTimeout(() => setValue({ status: { id: 'my-offer', numWantsSatisfied: 1 }, updated: "offerStatus" }), 1000); // First, offer is seated - setTimeout(() => setValue({ status: { id: 'my-offer', numWantsSatisfied: 1, result: 'thank you' }, updated: "offerStatus" }), 3000); // First, offer is resulted - - await t.notThrowsAsync(waitP); + const { setValue, follow } = makeFakeFollow(); + setValue({ status: { id: 'my-offer' }, updated: 'offerStatus' }); + + const waitP = waitUntilOfferResult( + 'agoric12345', + 'my-offer', + false, + { follow, setTimeout: globalThis.setTimeout }, + { + maxRetries: 7, + retryIntervalMs: 1000, + log: t.log, + errorMessage: 'offer not resulted on time', + }, + ); + + setTimeout( + () => + setValue({ + status: { id: 'my-offer', numWantsSatisfied: 1 }, + updated: 'offerStatus', + }), + 1000, + ); // First, offer is seated + setTimeout( + () => + setValue({ + status: { id: 'my-offer', numWantsSatisfied: 1, result: 'thank you' }, + updated: 'offerStatus', + }), + 3000, + ); // Then offer got results + + await t.notThrowsAsync(waitP); }); test.serial('wait until offer result, wait for "payouts"', async t => { - const { setValue, follow } = makeFakeFollow(); - setValue({ status: { id: 'my-offer' }, updated: "offerStatus" }); - - const waitP = waitUntilOfferResult( - 'agoric12345', - 'my-offer', - true, - { follow, setTimeout: globalThis.setTimeout }, - { - maxRetries: 7, - retryIntervalMs: 1000, - log: t.log, - errorMessage: 'payouts not received on time' - } - ); - - setTimeout( - () => setValue({ status: { id: 'my-offer', numWantsSatisfied: 1 }, updated: "offerStatus" }), - 1000 - ); // First, offer is seated - setTimeout( - () => setValue({ status: { id: 'my-offer', numWantsSatisfied: 1, result: 'thank you' }, updated: "offerStatus" }), - 3000 - ); // Now, offer is resulted - setTimeout( - () => setValue({ status: { id: 'my-offer', numWantsSatisfied: 1, result: 'thank you', payouts: {} }, updated: "offerStatus" }), - 4000 - ); // Payouts are received + const { setValue, follow } = makeFakeFollow(); + setValue({ status: { id: 'my-offer' }, updated: 'offerStatus' }); + + const waitP = waitUntilOfferResult( + 'agoric12345', + 'my-offer', + true, + { follow, setTimeout: globalThis.setTimeout }, + { + maxRetries: 7, + retryIntervalMs: 1000, + log: t.log, + errorMessage: 'payouts not received on time', + }, + ); + + setTimeout( + () => + setValue({ + status: { id: 'my-offer', numWantsSatisfied: 1 }, + updated: 'offerStatus', + }), + 1000, + ); // First, offer is seated + setTimeout( + () => + setValue({ + status: { id: 'my-offer', numWantsSatisfied: 1, result: 'thank you' }, + updated: 'offerStatus', + }), + 3000, + ); // Now offer got results + setTimeout( + () => + setValue({ + status: { + id: 'my-offer', + numWantsSatisfied: 1, + result: 'thank you', + payouts: {}, + }, + updated: 'offerStatus', + }), + 4000, + ); // Payouts are received - await t.notThrowsAsync(waitP); + await t.notThrowsAsync(waitP); }); -test.serial('wait until invitation recevied, wrong "updated" value', async t => { +test.serial( + 'wait until invitation recevied, wrong "updated" value', + async t => { const { setValue, follow } = makeFakeFollow(); - setValue({ updated: "offerStatus" }); + setValue({ updated: 'offerStatus' }); const waitP = waitUntilInvitationReceived( - 'agoric12345', - { follow, setTimeout: globalThis.setTimeout }, - { - maxRetries: 3, - retryIntervalMs: 1000, - log: t.log, - errorMessage: 'wrong "updated" value' - } + 'agoric12345', + { follow, setTimeout: globalThis.setTimeout }, + { + maxRetries: 3, + retryIntervalMs: 1000, + log: t.log, + errorMessage: 'wrong "updated" value', + }, ); - await t.throwsAsync(waitP); -}); + await t.throwsAsync(waitP, { message: /wrong "updated" value/ }); + }, +); -test.serial('wait until invitation recevied, falty "currentAmount" object', async t => { +test.serial( + 'wait until invitation recevied, falty "currentAmount" object', + async t => { const { setValue, follow } = makeFakeFollow(); - setValue({ updated: "balance" }); + setValue({ updated: 'balance' }); const waitP = waitUntilInvitationReceived( - 'agoric12345', - { follow, setTimeout: globalThis.setTimeout }, - { - maxRetries: 5, - retryIntervalMs: 1000, - log: t.log, - errorMessage: 'falty "currentAmount" object' - } + 'agoric12345', + { follow, setTimeout: globalThis.setTimeout }, + { + maxRetries: 5, + retryIntervalMs: 1000, + log: t.log, + errorMessage: 'faulty "currentAmount" object', + }, ); - setTimeout(() => setValue({ updated: "balance", currentAmount: { foo: true } }), 2000); - - await t.throwsAsync(waitP); -}); - -test.serial('wait until invitation recevied, brand string do not match', async t => { - const { setValue, follow } = makeFakeFollow(); - setValue({ updated: "balance", currentAmount: { brand: 'foo bar foo' } }); - - const waitP = waitUntilInvitationReceived( - 'agoric12345', - { follow, setTimeout: globalThis.setTimeout }, - { - maxRetries: 3, - retryIntervalMs: 1000, - log: t.log, - errorMessage: 'brand string do not match' - } + setTimeout( + () => setValue({ updated: 'balance', currentAmount: { foo: true } }), + 2000, ); - await t.throwsAsync(waitP); -}); + await t.throwsAsync(waitP, { message: /faulty "currentAmount" object/ }); + }, +); -test.only('wait until invitation recevied', async t => { +test.serial( + 'wait until invitation recevied, brand string do not match', + async t => { const { setValue, follow } = makeFakeFollow(); - setValue({}); + setValue({ updated: 'balance', currentAmount: { brand: 'foo bar foo' } }); const waitP = waitUntilInvitationReceived( - 'agoric12345', - { follow, setTimeout: globalThis.setTimeout }, - { - maxRetries: 5, - retryIntervalMs: 1000, - log: t.log, - errorMessage: 'brand string do not match' - } + 'agoric12345', + { follow, setTimeout: globalThis.setTimeout }, + { + maxRetries: 3, + retryIntervalMs: 1000, + log: t.log, + errorMessage: 'brand string do not match', + }, ); - setTimeout(() => setValue({ updated: 'balance', currentAmount: { brand: '[Alleged: SEVERED: Zoe Invitation brand {}]'}}), 2000); - - await t.notThrowsAsync(waitP); -}); \ No newline at end of file + await t.throwsAsync(waitP, { message: /brand string do not match/ }); + }, +); + +test.serial('wait until invitation recevied', async t => { + const { setValue, follow } = makeFakeFollow(); + setValue({}); + + const waitP = waitUntilInvitationReceived( + 'agoric12345', + { follow, setTimeout: globalThis.setTimeout }, + { + maxRetries: 5, + retryIntervalMs: 1000, + log: t.log, + errorMessage: 'brand string do not match', + }, + ); + + setTimeout( + () => + setValue({ + updated: 'balance', + currentAmount: { brand: '[Alleged: SEVERED: Zoe Invitation brand {}]' }, + }), + 2000, + ); + + await t.notThrowsAsync(waitP); +}); diff --git a/a3p-integration/proposals/z:acceptance/tsconfig.json b/a3p-integration/proposals/z:acceptance/tsconfig.json index 795ebdd04fc0..bd1c45190fe2 100644 --- a/a3p-integration/proposals/z:acceptance/tsconfig.json +++ b/a3p-integration/proposals/z:acceptance/tsconfig.json @@ -10,6 +10,6 @@ "strictNullChecks": true, "noImplicitThis": true, // XXX synthetic-chain has some errors - "skipLibCheck": true, + "skipLibCheck": true } }