Skip to content

Commit

Permalink
test: sequential addAssets
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Sep 10, 2024
1 parent ad0df91 commit 5ad5ebc
Showing 1 changed file with 46 additions and 17 deletions.
63 changes: 46 additions & 17 deletions packages/boot/test/bootstrapTests/addAssets.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @file tests of adding an asset to the vaultFactory.
* Checks that auctions update correctly.
*/
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import type { TestFn } from 'ava';
Expand All @@ -15,6 +19,7 @@ const test = anyTest as TestFn<
name: string,
id: string,
) => Awaited<ReturnType<ReturnType<typeof makeProposalExtractor>>>;
getNumAuctionBooks: () => number;
}
>;

Expand All @@ -34,23 +39,28 @@ test.before(async t => {
.replaceAll('ibc/987C17B1', `ibc/987C17B1${id}`);
return JSON.parse(proposalMod);
};

const getNumAuctionBooks = () =>
Array.from(context.storage.data.keys()).filter(k =>
k.startsWith(`${auctioneerPath}.book`),
).length;

t.context = {
...context,
getCollateralProposal,
getNumAuctionBooks,
};
});

test.after.always(t => {
// This will fail if a subset of tests are run. It detects that three
// collaterals were added to the auction after ATOM.
t.like(t.context.readLatest(`${auctioneerPath}.book3`), {
currentPriceLevel: null,
});
return t.context.shutdown && t.context.shutdown();
});

test('addAsset to quiescent auction', async t => {
const { advanceTimeTo, evalProposal, readLatest } = t.context;
test.serial('addAsset to quiescent auction', async t => {
const { advanceTimeTo, evalProposal, getNumAuctionBooks, readLatest } =
t.context;

const booksBefore = getNumAuctionBooks();

await evalProposal(t.context.getCollateralProposal('COMETS', 'A'));

Expand All @@ -69,16 +79,31 @@ test('addAsset to quiescent auction', async t => {
const nextQuiescentTime = TimeMath.addAbsRel(nextEndTime, fiveMinutes);
await advanceTimeTo(nextQuiescentTime);

t.like(readLatest(`${auctioneerPath}.book1`), {
currentPriceLevel: null,
});
const booksAfter = getNumAuctionBooks();
t.is(booksAfter, booksBefore + 1);

t.like(
readLatest(`${auctioneerPath}.book${booksAfter - 1}`),
{
currentPriceLevel: null,
},
'quiescent',
);
});

test('addAsset to active auction', async t => {
const { advanceTimeTo, readLatest } = t.context;
test.serial('addAsset to active auction', async t => {
const { advanceTimeTo, getNumAuctionBooks, readLatest } = t.context;
const { EV } = t.context.runUtils;

t.like(readLatest(`${auctioneerPath}.book0`), { startPrice: null });
const booksBefore = getNumAuctionBooks();

t.like(
readLatest(`${auctioneerPath}.book${booksBefore - 1}`),
{
startPrice: null,
},
'active',
);

const auctioneerKit = await EV.vat('bootstrap').consumeItem('auctioneerKit');
const schedules = await EV(auctioneerKit.creatorFacet).getSchedule();
Expand Down Expand Up @@ -120,12 +145,14 @@ test('addAsset to active auction', async t => {
schedulesAfter.nextAuctionSchedule!.endTime.absValue,
);

t.like(readLatest(`${auctioneerPath}.book1`), { currentPriceLevel: null });
const booksAfter = getNumAuctionBooks();
t.is(booksAfter, booksBefore + 1);
});

test('addAsset to auction starting soon', async t => {
const { advanceTimeTo, readLatest } = t.context;
test.serial('addAsset to auction starting soon', async t => {
const { advanceTimeTo, getNumAuctionBooks } = t.context;
const { EV } = t.context.runUtils;
const booksBefore = getNumAuctionBooks();

const auctioneerKit = await EV.vat('bootstrap').consumeItem('auctioneerKit');
const schedules = await EV(auctioneerKit.creatorFacet).getSchedule();
Expand Down Expand Up @@ -165,5 +192,7 @@ test('addAsset to auction starting soon', async t => {
schedules.nextAuctionSchedule!.endTime.absValue <
schedulesAfter.nextAuctionSchedule!.endTime.absValue,
);
t.like(readLatest(`${auctioneerPath}.book1`), { currentPriceLevel: null });

const booksAfter = getNumAuctionBooks();
t.is(booksAfter, booksBefore + 1);
});

0 comments on commit 5ad5ebc

Please sign in to comment.