-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes: #8606 closes: #8597 ## Description #8597 suggested adding a test proposal guards in Zoe. This adds that test, and also cleans up a redundant check in coveredCall. The added test exposed a mistake in the Zoe doc, so [1258](Agoric/documentation#1258) fixes that as well. ### Security Considerations None ### Scaling Considerations None. ### Documentation Considerations Improved documentation. ### Testing Considerations Added tests. ### Upgrade Considerations These changes do not impact code on-chain. There's a correction to an example contract, an improvement in a TypeGuard, and a documentation update which will be separately release.
- Loading branch information
Showing
6 changed files
with
197 additions
and
17 deletions.
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, {}); | ||
}); |