diff --git a/a3p-integration/proposals/z:acceptance/auction.test.js b/a3p-integration/proposals/z:acceptance/auction.test.js index 91c633a9ba2..02b6c8df86f 100644 --- a/a3p-integration/proposals/z:acceptance/auction.test.js +++ b/a3p-integration/proposals/z:acceptance/auction.test.js @@ -17,7 +17,6 @@ * - Make sure all actors receive the correct payouts */ -// Typo will be fixed with https://github.com/Agoric/agoric-sdk/pull/10171 /** @typedef {import('./test-lib/sync-tools.js').RetryOptions} RetryOptions */ import { @@ -36,10 +35,9 @@ import { calculateRetryUntilNextStartTime, checkBidsOutcome, checkDepositOutcome, - checkPrice, + checkPriceCaptured, depositCollateral, fundAccts, - getCapturedPrice, placeBids, pushPricesForAuction, scale6, @@ -143,11 +141,12 @@ test('run auction', async t => { await pushPricesForAuction(t, config.price); // Wait until next round starts. Retry error message is useful for debugging - const retryOptions = await calculateRetryUntilNextStartTime(); + const { retryOptions, nextStartTime } = + await calculateRetryUntilNextStartTime(); await retryUntilCondition( - () => getCapturedPrice('book0'), - res => checkPrice(res, scale6(config.price).toString()), // scale price to uist - 'price not captured yet [AUCTION TEST]', + () => Promise.resolve(Date.now()), + res => res >= nextStartTime * 1000, + 'next auction round not started yet [AUCTION TEST]', { log: t.log, ...ambientAuthority, @@ -160,6 +159,11 @@ test('run auction', async t => { const bidsP = placeBids(t, config.currentBidsSetup); const proceedsP = depositCollateral(t, config.depositor); + // Make sure price captured + // We have to check this after bids are placed and collateral deposited + // because of https://github.com/Agoric/BytePitchPartnerEng/issues/31 + await checkPriceCaptured('book0', scale6(config.price).toString()); + // Resolves when auction finalizes and depositor gets payouts const [longLivingBidderAddr] = await Promise.all([ getUser(config.longLivingBidSetup.name), diff --git a/a3p-integration/proposals/z:acceptance/test-lib/auction-lib.js b/a3p-integration/proposals/z:acceptance/test-lib/auction-lib.js index 3db752700b9..9ce1e3ddee1 100644 --- a/a3p-integration/proposals/z:acceptance/test-lib/auction-lib.js +++ b/a3p-integration/proposals/z:acceptance/test-lib/auction-lib.js @@ -1,12 +1,12 @@ /* eslint-env node */ import { - addPreexistingOracles, agd, agopsInter, agoric, ATOM_DENOM, CHAINID, executeOffer, + generateOracleMap, getPriceQuote, GOV1ADDR, pushPrices, @@ -36,6 +36,9 @@ export const scale6 = x => BigInt(x * 1_000_000); const fromBoard = makeFromBoard(); const marshaller = boardSlottingMarshaller(fromBoard.convertSlotToVal); +// From n-upgrade/verifyPushedPrice.js +const BASE_ID = 'n-upgrade'; + // Import from synthetic-chain once it is updated export const bankSend = (from, addr, wanted) => { const chain = ['--chain-id', CHAINID]; @@ -47,8 +50,7 @@ export const bankSend = (from, addr, wanted) => { }; export const pushPricesForAuction = async (t, price) => { - const oraclesByBrand = new Map(); - await addPreexistingOracles('ATOM', oraclesByBrand); + const oraclesByBrand = generateOracleMap(BASE_ID, ['ATOM']); await pushPrices(price, 'ATOM', oraclesByBrand, t.context.roundId + 1); @@ -67,20 +69,20 @@ export const pushPricesForAuction = async (t, price) => { /** * @param {any} t * @param {{ - * name: string - * offerId: string, - * depositValue: string, + * name: string + * offerId: string, + * depositValue: string, * }} depositor * @param {Record} bidders */ export const fundAccts = async (t, depositor, bidders) => { @@ -152,11 +154,11 @@ export const calculateRetryUntilNextStartTime = async () => { /** @type {RetryOptions} */ const capturePriceRetryOpts = { - maxRetries: Math.round((nextStartTime * 1000 - Date.now()) / 10000) + 2, // wait until next schedule + maxRetries: Math.ceil((nextStartTime * 1000 - Date.now()) / 10000) + 2, // wait until next schedule retryIntervalMs: 10000, // 10 seconds in ms }; - return capturePriceRetryOpts; + return { retryOptions: capturePriceRetryOpts, nextStartTime }; }; /** @@ -169,7 +171,7 @@ export const calculateRetryUntilNextStartTime = async () => { * }} depositor */ export const depositCollateral = async (t, depositor) => { - const [brandsRaw, retryOptions] = await Promise.all([ + const [brandsRaw, { retryOptions }] = await Promise.all([ agoric.follow('-lF', ':published.agoricNames.brand', '-o', 'text'), calculateRetryUntilNextStartTime(), ]); @@ -294,13 +296,16 @@ export const checkDepositOutcome = (t, depositorPayouts, config, brands) => { ); }; -export const getCapturedPrice = async bookId => { - const result = await agoric.follow('-lF', `:published.auction.${bookId}`); - return result; -}; - -export const checkPrice = (res, expected) => { - if (res.startPrice === null) return false; - else if (res.startPrice.numerator.value === expected) return true; - return false; +/** + * + * @param {string} bookId + * @param {string} expected + */ +export const checkPriceCaptured = async (bookId, expected) => { + const { + startPrice: { + numerator: { value }, + }, + } = await agoric.follow('-lF', `:published.auction.${bookId}`); + assert(value, expected); };