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

fix(zoe): fix auction makeBidInvitation #4899

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions packages/zoe/src/contracts/auction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,20 @@ const start = zcf => {
return bidSeats.map(seat => seat.getAmountAllocated('Bid', bidBrand));
};

const getSessionDetails = () => {
const getSessionDetails = async () => {
const sellerProposal = sellSeat.getProposal();
return harden({
Copy link
Member

Choose a reason for hiding this comment

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

Your use of await nested within an expression violates our await design rule. This code is a good example of why. Looking at this code, is it clear whether sellerProposal.want.Ask and getCurrentBids() are evaluated before or after the await point?

Instead, if you want to use await here, I suggest you rename the variable that might hold a promise for a time authority to something else, and then await it at function top level to obtain the non-promise time authority variable.

Suggested change
return harden({
const timeAuthority = await timeAuthorityP;
return harden({

auctionedAssets: sellerProposal.give.Asset,
minimumBid: sellerProposal.want.Ask,
winnerPriceOption,
closesAfter,
bidDuration,
timeAuthority,
timeAuthority: await timeAuthority,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
timeAuthority: await timeAuthority,
timeAuthority,

bids: getCurrentBids(),
});
};

const makeBidInvitation = () => {
const makeBidInvitation = async () => {
/** @type {OfferHandler} */
const performBid = seat => {
assert(!isClosed, X`Auction session is closed, no more bidding`);
Expand All @@ -133,7 +133,7 @@ const start = zcf => {
return defaultAcceptanceMsg;
};

const customProperties = getSessionDetails();
const customProperties = await getSessionDetails();
Copy link
Member

Choose a reason for hiding this comment

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

This one is good.

return zcf.makeInvitation(performBid, 'bid', customProperties);
};

Expand Down
22 changes: 17 additions & 5 deletions packages/zoe/test/unitTests/contracts/test-auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ test('zoe - secondPriceAuction w/ 3 bids', async t => {
Asset: moolaKit.issuer,
Ask: simoleanKit.issuer,
});
const terms = { timeAuthority: timer, bidDuration: 1n };
const terms = {
timeAuthority: Promise.resolve(timer),
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the purpose of this. Why wrap the timer in a promise? I'm equally confused by the other examples below.

bidDuration: 1n,
};
const adminP = E(zoe).startInstance(
installation,
issuerKeywordRecord,
Expand Down Expand Up @@ -274,7 +277,10 @@ test('zoe - secondPriceAuction - alice tries to exit', async t => {
Ask: simoleanR.issuer,
});
const timer = buildManualTimer(console.log);
const terms = harden({ timeAuthority: timer, bidDuration: 1n });
const terms = harden({
timeAuthority: Promise.resolve(timer),
bidDuration: 1n,
});
const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance(
installation,
issuerKeywordRecord,
Expand Down Expand Up @@ -424,7 +430,10 @@ test('zoe - secondPriceAuction - all bidders try to exit', async t => {
Ask: simoleanR.issuer,
});
const timer = buildManualTimer(console.log);
const terms = harden({ timeAuthority: timer, bidDuration: 1n });
const terms = harden({
timeAuthority: Promise.resolve(timer),
bidDuration: 1n,
});
const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance(
installation,
issuerKeywordRecord,
Expand Down Expand Up @@ -568,7 +577,10 @@ test('zoe - secondPriceAuction non-fungible asset', async t => {
Ask: moolaIssuer,
});
const timer = buildManualTimer(console.log);
const terms = harden({ timeAuthority: timer, bidDuration: 1n });
const terms = harden({
timeAuthority: Promise.resolve(timer),
bidDuration: 1n,
});
const { creatorInvitation: aliceInvitation } = await E(zoe).startInstance(
installation,
issuerKeywordRecord,
Expand Down Expand Up @@ -840,7 +852,7 @@ test('zoe - firstPriceAuction w/ 3 bids', async t => {
Ask: simoleanKit.issuer,
});
const terms = {
timeAuthority: timer,
timeAuthority: Promise.resolve(timer),
bidDuration: 1n,
winnerPriceOption: 'first-price',
};
Expand Down