Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate/improve auction functionality tests in z:acceptance #10229

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions a3p-integration/proposals/n:upgrade-next/submitBid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env node

import {
GOV1ADDR,
CHAINID,
agd,
agopsInter,
addUser,
waitForBlock,
provisionSmartWallet,
ATOM_DENOM,
} from '@agoric/synthetic-chain';

export const bankSend = (from, addr, wanted) => {
anilhelvaci marked this conversation as resolved.
Show resolved Hide resolved
const chain = ['--chain-id', CHAINID];
const fromArg = ['--from', from];
const testKeyring = ['--keyring-backend', 'test'];
const noise = [...fromArg, ...chain, ...testKeyring, '--yes'];

return agd.tx('bank', 'send', from, addr, wanted, ...noise);
};

const bidder = await addUser('long-living-bidder');
console.log('BIDDDER', bidder);
anilhelvaci marked this conversation as resolved.
Show resolved Hide resolved
await bankSend(GOV1ADDR, bidder, `80000000uist`);
console.log('IST sent');
await provisionSmartWallet(bidder, `20000000ubld,100000000${ATOM_DENOM}`);
console.log('Provision sent');
await waitForBlock(3);
console.log('Wait For Block done. Sending bid offer');
agopsInter(
'bid',
'by-price',
`--price 49.0`,
`--give 80IST`,
'--from',
bidder,
'--keyring-backend test',
`--offer-id long-living-bid-for-acceptance`,
);
3 changes: 2 additions & 1 deletion a3p-integration/proposals/n:upgrade-next/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"allowJs": true,
"checkJs": true,
"strict": false,
Expand Down
1 change: 1 addition & 0 deletions a3p-integration/proposals/n:upgrade-next/use.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node ./addGov4

./verifyPushedPrice.js 'ATOM' 12.01
./verifyPushedPrice.js 'stATOM' 12.01
./submitBid.js
220 changes: 220 additions & 0 deletions a3p-integration/proposals/z:acceptance/auction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
/* eslint-env node */
/**
* @file In this file we aim to test auctioneer in an isolated manner. Here's the scenario to test;
*
* - Prerequisites: In one of the earlier proposal(n:upgrade-next), a user called "long-living-bidder"
* has placed a bid where { give: 80IST, price: 49.0 }
* - Push price so that 1 ATOM is 50 ISTs
* - Wait until the auctioneer captures the price we just pushed
* - Fund actors
* - gov1 gets 100 ATOMs
* - user1 gets 90 ISTs
* - gov3 gets 150 ISTs
* - Place bids for user1 and gov3 following the values in "config"
* - Deposit 100 ATOMs into book0, gov1 is the depositor
* - Wait until placed bids get their payouts
* - Wait until proceeds are distributed to the depositor
* - Make sure all actors receive the correct payouts
*/

/** @typedef {import('./test-lib/sync-tools.js').RetryOptions} RetryOptions */

import {
agd,
agoric,
getUser,
GOV1ADDR,
GOV3ADDR,
USER1ADDR,
} from '@agoric/synthetic-chain';
import '@endo/init';
import test from 'ava';
import { boardSlottingMarshaller, makeFromBoard } from './test-lib/rpc.js';
import { retryUntilCondition } from './test-lib/sync-tools.js';
import {
calculateRetryUntilNextStartTime,
checkBidsOutcome,
checkDepositOutcome,
checkPriceCaptured,
depositCollateral,
fundAccts,
placeBids,
pushPricesForAuction,
scale6,
} from './test-lib/auction-lib.js';

const ambientAuthority = {
query: agd.query,
follow: agoric.follow,
setTimeout,
};

const fromBoard = makeFromBoard();
const marshaller = boardSlottingMarshaller(fromBoard.convertSlotToVal);

const config = {
Chris-Hibbert marked this conversation as resolved.
Show resolved Hide resolved
depositor: {
name: 'gov1',
addr: GOV1ADDR,
depositValue: '100000000',
offerId: `gov1-deposit-${Date.now()}`,
},
price: 50.0,
longLivingBidSetup: {
name: 'long-living-bidder',
// This bid is placed in an earlier proposal
give: '80IST',
},
currentBidsSetup: {
user1: {
bidder: USER1ADDR,
bidderFund: {
value: 90000000,
denom: 'uist',
},
offerId: `user1-bid-${Date.now()}`,
give: '90IST',
price: 46,
},
gov3: {
bidder: GOV3ADDR,
bidderFund: {
value: 150000000,
denom: 'uist',
},
offerId: `gov3-bid-${Date.now()}`,
give: '150IST',
discount: '13',
},
},
bidsOutcome: {
longLivingBidder: {
payouts: {
Bid: 0,
Collateral: 1.68421,
},
},
user1: {
payouts: {
Bid: 0,
Collateral: 2.0,
},
},
gov3: {
payouts: {
Bid: 0,
Collateral: 3.448275,
},
},
},
};

test.before(async t => {
/** @type {RetryOptions} */
const pushPriceRetryOpts = {
maxRetries: 5, // arbitrary
retryIntervalMs: 5000, // in ms
};

/** @type {RetryOptions} */
const bankSendRetryOpts = {
maxRetries: 3, // arbitrary
retryIntervalMs: 3000, // in ms
};

// Get current round id
anilhelvaci marked this conversation as resolved.
Show resolved Hide resolved
const round = await agoric.follow(
'-lF',
':published.priceFeed.ATOM-USD_price_feed.latestRound',
);
t.context = {
roundId: parseInt(round.roundId, 10),
retryOpts: {
anilhelvaci marked this conversation as resolved.
Show resolved Hide resolved
bankSendRetryOpts,
pushPriceRetryOpts,
},
};
});

test('run auction', async t => {
// Push the price to a point where only our bids can settle
await pushPricesForAuction(t, config.price);

// Wait until next round starts. Retry error message is useful for debugging
const { retryOptions, nextStartTime } =
await calculateRetryUntilNextStartTime();
await retryUntilCondition(
() => Promise.resolve(Date.now()),
res => res >= nextStartTime * 1000,
'next auction round not started yet [AUCTION TEST]',
{
log: t.log,
...ambientAuthority,
...retryOptions,
},
);

// Make sure depositor and bidders have enough balance
await fundAccts(t, config.depositor, config.currentBidsSetup);
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),
...bidsP,
proceedsP,
]);

// Query wallets of the actors involved for assertions
const [gov1Results, longLivingBidResults, user1Results, gov3Results, brands] =
await Promise.all([
agoric
.follow(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lament that we still have to go out through the CLI to get this functionality that is in JS:

Agoric/agoric-3-proposals#98 is related.

Filed #10369

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely agree

'-lF',
`:published.wallet.${config.depositor.addr}`,
'-o',
'text',
)
.then(res => marshaller.fromCapData(JSON.parse(res))),
agoric
.follow(
'-lF',
`:published.wallet.${longLivingBidderAddr}`,
'-o',
'text',
)
.then(res => marshaller.fromCapData(JSON.parse(res))),
agoric
.follow('-lF', `:published.wallet.${USER1ADDR}`, '-o', 'text')
.then(res => marshaller.fromCapData(JSON.parse(res))),
agoric
.follow('-lF', `:published.wallet.${GOV3ADDR}`, '-o', 'text')
.then(res => marshaller.fromCapData(JSON.parse(res))),
agoric
.follow('-lF', ':published.agoricNames.brand', '-o', 'text')
.then(res =>
Object.fromEntries(marshaller.fromCapData(JSON.parse(res))),
),
]);

// Assert depositor paid correctly
checkDepositOutcome(t, gov1Results.status.payouts, config, brands);

// Assert bidders paid correctly
checkBidsOutcome(
t,
{
'longLivingBidder.results': longLivingBidResults,
'user1.results': user1Results,
'gov3.results': gov3Results,
},
config.bidsOutcome,
brands,
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ISTunit,
provisionWallet,
setDebtLimit,
} from '../lib/vaults.mjs';
} from '../test-lib/vaults.mjs';

const START_FREQUENCY = 600; // StartFrequency: 600s (auction runs every 10m)
const CLOCK_STEP = 20; // ClockStep: 20s (ensures auction completes in time)
Expand Down
Loading
Loading