Skip to content

Commit

Permalink
chore(auction-acceptance): workaround for auctioneer vats vstorage co…
Browse files Browse the repository at this point in the history
…llision

Refs: Agoric/BytePitchPartnerEng#31

fix(auction-acceptance): formatting fixes
  • Loading branch information
anilhelvaci committed Oct 30, 2024
1 parent 5bbdde8 commit 20ca789
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
18 changes: 11 additions & 7 deletions a3p-integration/proposals/z:acceptance/auction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -36,10 +35,9 @@ import {
calculateRetryUntilNextStartTime,
checkBidsOutcome,
checkDepositOutcome,
checkPrice,
checkPriceCaptured,
depositCollateral,
fundAccts,
getCapturedPrice,
placeBids,
pushPricesForAuction,
scale6,
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand Down
35 changes: 20 additions & 15 deletions a3p-integration/proposals/z:acceptance/test-lib/auction-lib.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-env node */
import {
addPreexistingOracles,
agd,
agopsInter,
agoric,
ATOM_DENOM,
CHAINID,
executeOffer,
generateOracleMap,
getPriceQuote,
GOV1ADDR,
pushPrices,
Expand Down Expand Up @@ -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];
Expand All @@ -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);

Expand Down Expand Up @@ -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 };
};

/**
Expand All @@ -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(),
]);
Expand Down Expand Up @@ -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);
};

0 comments on commit 20ca789

Please sign in to comment.