From 807d175632bda863653fd2aef7169136be8b1a85 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Fri, 14 Apr 2023 11:19:53 -0700 Subject: [PATCH] feat(zoe): error on unexpected properties from start() --- packages/zoe/src/contractFacet/zcfZygote.js | 7 +++++++ packages/zoe/test/unitTests/test-zoe.js | 13 +++++++++++++ .../test/unitTests/unexpectedPropertiesContract.js | 1 + 3 files changed, 21 insertions(+) create mode 100644 packages/zoe/test/unitTests/unexpectedPropertiesContract.js diff --git a/packages/zoe/src/contractFacet/zcfZygote.js b/packages/zoe/src/contractFacet/zcfZygote.js index 1dff30ea476..1c037f690c4 100644 --- a/packages/zoe/src/contractFacet/zcfZygote.js +++ b/packages/zoe/src/contractFacet/zcfZygote.js @@ -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, diff --git a/packages/zoe/test/unitTests/test-zoe.js b/packages/zoe/test/unitTests/test-zoe.js index d47ff565f0d..dd65b04fdcf 100644 --- a/packages/zoe/test/unitTests/test-zoe.js +++ b/packages/zoe/test/unitTests/test-zoe.js @@ -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'); diff --git a/packages/zoe/test/unitTests/unexpectedPropertiesContract.js b/packages/zoe/test/unitTests/unexpectedPropertiesContract.js new file mode 100644 index 00000000000..02300d2f0f0 --- /dev/null +++ b/packages/zoe/test/unitTests/unexpectedPropertiesContract.js @@ -0,0 +1 @@ +export const start = () => ({ unexpectedProperty: {} });