Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
test: Prevent manual timers from racing code under test (merge #73)
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 authored Feb 3, 2024
2 parents 0ea86fa + 38d0edd commit b414f9e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions contract/test/test-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { E } from '@endo/eventual-send';
import { makeFakeVatAdmin } from '@agoric/zoe/tools/fakeVatAdmin.js';
import { makeZoeKit } from '@agoric/zoe';
import { makeIssuerKit, AmountMath } from '@agoric/ertp';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';

const contractPath = new URL('../src/contract.js', import.meta.url).pathname;
Expand Down Expand Up @@ -41,7 +42,7 @@ const setupCardsContract = async () => {
const auctionBundle = await bundleSource(auctionBundlePath);
const auctionInstallation = await E(zoe).install(auctionBundle);

const timer = buildManualTimer(console.log);
const timer = buildManualTimer(console.log, 0n, { eventLoopIteration });
const contractTerms = harden({
bidDuration: 1n,
winnerPriceOption: 'first-price',
Expand Down Expand Up @@ -70,7 +71,7 @@ test('zoe - sell baseball cards, normal case', async (t) => {
const { zoe, installation, auctionInstallation, auctionItemsInstallation } =
await setupCardsContract();

const timer = buildManualTimer(console.log);
const timer = buildManualTimer(console.log, 0n, { eventLoopIteration });
const contractTerms = harden({
bidDuration: 1n,
winnerPriceOption: 'first-price',
Expand Down Expand Up @@ -127,7 +128,7 @@ test('zoe - sell baseball cards, normal case', async (t) => {
});

// timer ticks before offering, nothing happens
timer.tick();
await timer.tick();

const bobSeat = await E(zoe).offer(
bobInvitation,
Expand Down Expand Up @@ -155,7 +156,7 @@ test('zoe - sell baseball cards, normal case', async (t) => {
carolPaymentKeywordRecord,
);

timer.tick();
await timer.tick();

const bobCardPayout = await E(bobSeat).getPayout('Asset');

Expand Down Expand Up @@ -204,7 +205,7 @@ test('zoe - after a failed auction session, key should be available for new one'
const { zoe, installation, auctionInstallation, auctionItemsInstallation } =
await setupCardsContract();

const timer = buildManualTimer(console.log);
const timer = buildManualTimer(console.log, 0n, { eventLoopIteration });
const contractTerms = harden({
bidDuration: 1n,
winnerPriceOption: 'first-price',
Expand Down Expand Up @@ -261,7 +262,7 @@ test('zoe - after a failed auction session, key should be available for new one'
});

// timer ticks before offering, nothing happens
timer.tick();
await timer.tick();

const bobSeat = await E(zoe).offer(
bobInvitation,
Expand All @@ -275,7 +276,7 @@ test('zoe - after a failed auction session, key should be available for new one'
await E(bobSeat).tryExit();

// auction closed?
timer.tick();
await timer.tick();

const bobCardPayout = await E(bobSeat).getPayout('Asset');

Expand Down Expand Up @@ -322,7 +323,7 @@ test('zoe - after a failed auction session, key should be available for new one'
await E(carolSeat).getOfferResult();

// next tick, session will be completed
timer.tick();
await timer.tick();

const carolCardPayout = await E(carolSeat).getPayout('Asset');
const carolObtained = await E(cardIssuer).getAmountOf(carolCardPayout);
Expand Down

0 comments on commit b414f9e

Please sign in to comment.