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

feat(zoe): error on unexpected properties from start() #7421

Merged
merged 1 commit into from
Apr 15, 2023
Merged
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
7 changes: 7 additions & 0 deletions packages/zoe/src/contractFacet/zcfZygote.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,14 @@ export const makeZCFZygote = async (
creatorFacet = undefined,
publicFacet = undefined,
creatorInvitation = undefined,
...unexpected
}) => {
const unexpectedKeys = Object.keys(unexpected);
unexpectedKeys.length === 0 ||
Fail`contract ${
prepare ? 'prepare' : 'start'
} returned unrecognized properties ${unexpectedKeys}`;

const areDurable = objectMap(
{ creatorFacet, publicFacet, creatorInvitation },
canBeDurable,
Expand Down
13 changes: 13 additions & 0 deletions packages/zoe/test/unitTests/test-zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ test(`E(zoe).startInstance - bad issuer, makeEmptyPurse throws`, async t => {
);
});

test(`E(zoe).startInstance - unexpected properties`, async t => {
const { zoe } = setup();

const contractPath = `${dirname}/unexpectedPropertiesContract.js`;
const bundle = await bundleSource(contractPath);
const installation = await E(zoe).install(bundle);

await t.throwsAsync(() => E(zoe).startInstance(installation), {
message:
'contract "start" returned unrecognized properties ["unexpectedProperty"]',
});
});

test(`E(zoe).offer`, async t => {
const { zoe, zcf } = await setupZCFTest();
const invitation = zcf.makeInvitation(() => 'result', 'invitation');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const start = () => ({ unexpectedProperty: {} });