-
Notifications
You must be signed in to change notification settings - Fork 215
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
8606 invite proposals #10719
Merged
Merged
8606 invite proposals #10719
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
packages/zoe/test/unitTests/zcf/offer-proposalShape.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js'; | ||
|
||
import path from 'path'; | ||
|
||
import { E } from '@endo/eventual-send'; | ||
import bundleSource from '@endo/bundle-source'; | ||
|
||
import { M } from '@endo/patterns'; | ||
import { AmountShape } from '@agoric/ertp'; | ||
import { makeZoeForTest } from '../../../tools/setup-zoe.js'; | ||
import { setup } from '../setupBasicMints.js'; | ||
import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; | ||
|
||
const dirname = path.dirname(new URL(import.meta.url).pathname); | ||
|
||
const contractRoot = `${dirname}/zcfTesterContract.js`; | ||
|
||
test(`ProposalShapes mismatch`, async t => { | ||
const { moolaIssuer, simoleanIssuer, moola, moolaMint } = setup(); | ||
let testJig; | ||
const setJig = jig => { | ||
testJig = jig; | ||
}; | ||
const { admin: fakeVatAdminSvc, vatAdminState } = makeFakeVatAdmin(setJig); | ||
/** @type {ZoeService} */ | ||
const zoe = makeZoeForTest(fakeVatAdminSvc); | ||
|
||
// pack the contract | ||
const bundle = await bundleSource(contractRoot); | ||
// install the contract | ||
vatAdminState.installBundle('b1-zcftester', bundle); | ||
const installation = await E(zoe).installBundleID('b1-zcftester'); | ||
|
||
// Alice creates an instance | ||
const issuerKeywordRecord = harden({ | ||
Pixels: moolaIssuer, | ||
Money: simoleanIssuer, | ||
}); | ||
|
||
await E(zoe).startInstance(installation, issuerKeywordRecord); | ||
|
||
// The contract uses the testJig so the contractFacet | ||
// is available here for testing purposes | ||
/** @type {ZCF} */ | ||
// @ts-expect-error cast | ||
const zcf = testJig.zcf; | ||
|
||
const boring = () => { | ||
return 'ok'; | ||
}; | ||
|
||
const proposalShape = M.splitRecord({ | ||
give: { B: AmountShape }, | ||
exit: { deadline: M.any() }, | ||
}); | ||
const invitation = await zcf.makeInvitation( | ||
boring, | ||
'seat1', | ||
{}, | ||
proposalShape, | ||
); | ||
const { handle } = await E(zoe).getInvitationDetails(invitation); | ||
const shape = await E(zoe).getProposalShapeForInvitation(handle); | ||
t.deepEqual(shape, proposalShape); | ||
|
||
const proposal = harden({ | ||
give: { B: moola(5n) }, | ||
exit: { onDemand: null }, | ||
}); | ||
|
||
const fiveMoola = moolaMint.mintPayment(moola(5n)); | ||
await t.throwsAsync( | ||
() => | ||
E(zoe).offer(invitation, proposal, { | ||
B: fiveMoola, | ||
}), | ||
{ | ||
message: | ||
'"seat1" proposal: exit: {"onDemand":null} - Must have missing properties ["deadline"]', | ||
}, | ||
); | ||
t.falsy(vatAdminState.getHasExited()); | ||
// The moola was not deposited. | ||
t.true(await E(moolaIssuer).isLive(fiveMoola)); | ||
}); | ||
|
||
test(`ProposalShapes matched`, async t => { | ||
const { moolaIssuer, simoleanIssuer } = setup(); | ||
let testJig; | ||
const setJig = jig => { | ||
testJig = jig; | ||
}; | ||
const { admin: fakeVatAdminSvc, vatAdminState } = makeFakeVatAdmin(setJig); | ||
/** @type {ZoeService} */ | ||
const zoe = makeZoeForTest(fakeVatAdminSvc); | ||
|
||
// pack the contract | ||
const bundle = await bundleSource(contractRoot); | ||
// install the contract | ||
vatAdminState.installBundle('b1-zcftester', bundle); | ||
const installation = await E(zoe).installBundleID('b1-zcftester'); | ||
|
||
// Alice creates an instance | ||
const issuerKeywordRecord = harden({ | ||
Pixels: moolaIssuer, | ||
Money: simoleanIssuer, | ||
}); | ||
|
||
await E(zoe).startInstance(installation, issuerKeywordRecord); | ||
|
||
// The contract uses the testJig so the contractFacet | ||
// is available here for testing purposes | ||
/** @type {ZCF} */ | ||
// @ts-expect-error cast | ||
const zcf = testJig.zcf; | ||
|
||
const boring = () => { | ||
return 'ok'; | ||
}; | ||
|
||
const proposalShape = M.splitRecord({ exit: { onDemand: null } }); | ||
const invitation = await zcf.makeInvitation( | ||
boring, | ||
'seat', | ||
{}, | ||
proposalShape, | ||
); | ||
const { handle } = await E(zoe).getInvitationDetails(invitation); | ||
const shape = await E(zoe).getProposalShapeForInvitation(handle); | ||
t.deepEqual(shape, proposalShape); | ||
|
||
// onDemand is the default | ||
const seat = await E(zoe).offer(invitation); | ||
|
||
const result = await E(seat).getOfferResult(); | ||
t.is(result, 'ok', `userSeat1 offer result`); | ||
|
||
t.falsy(await E(seat).hasExited()); | ||
await E(seat).tryExit(); | ||
t.true(await E(seat).hasExited()); | ||
const payouts = await E(seat).getPayouts(); | ||
t.deepEqual(payouts, {}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does
getProposalShapeForInvitation
return values other than a ProposalShape?Is
ProposalShape
wrong?I notice that
getProposalShapeForInvitation
typedef returnsPattern | undefined
but some places then require that it be narrower than Pattern:agoric-sdk/packages/zoe/src/zoeService/offer/offer.js
Lines 45 to 50 in 322023f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different meta-levels:
proposalShape
is the type for something that is shaped like a proposal.E(zoe).offer(invitation, proposal)
takes a proposal, and its guard requires that it matchproposalShape
.The object returned by
getProposalShapeForInvitation(invitationHandle)
describes a proposal. It's apattern
.It's arguable whether
getProposalShapeForInvitation
should return aProposalShapePattern
, but I don't think it's possible to customizeM.pattern()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining. I agree
Pattern
is the right type but I request thatgetProposalShapeForInvitation
get a jsdoc explaining its return type. A good time also to inlineGetProposalShapeForInvitation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done