From b235bd8a53a4ac501040d9f3cb2b810d150a12e8 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Fri, 15 Dec 2023 08:08:54 -0800 Subject: [PATCH] fix(zoe): Fix guards to accurately guard args (#8642) --- packages/zoe/src/typeGuards.js | 17 ++++++++++------- .../zoe/src/zoeService/installationStorage.js | 8 ++++++-- packages/zoe/test/unitTests/test-zoe.js | 9 +++++++++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/zoe/src/typeGuards.js b/packages/zoe/src/typeGuards.js index 14af2f0a1ed..cbc330fa374 100644 --- a/packages/zoe/src/typeGuards.js +++ b/packages/zoe/src/typeGuards.js @@ -276,10 +276,12 @@ export const ZoeStorageManagerIKit = harden({ getBundleIDFromInstallation: M.call(InstallationShape).returns( M.eref(M.string()), ), - installBundle: M.call(M.or(InstanceHandleShape, BundleShape)).returns( - M.promise(), - ), - installBundleID: M.call(M.string()).returns(M.promise()), + installBundle: M.call(M.or(InstanceHandleShape, BundleShape)) + .optional(M.string()) + .returns(M.promise()), + installBundleID: M.call(M.string()) + .optional(M.string()) + .returns(M.promise()), getPublicFacet: M.call(InstanceHandleShape).returns( M.eref(M.remotable('PublicFacet')), @@ -310,6 +312,7 @@ export const ZoeStorageManagerIKit = harden({ IssuerPKeywordRecordShape, M.or(InstanceHandleShape, BundleShape), M.or(BundleCapShape, BundleShape), + M.string(), ).returns(M.promise()), unwrapInstallation: M.callWhen(M.eref(InstallationShape)).returns( UnwrappedInstallationShape, @@ -321,10 +324,10 @@ export const ZoeStorageManagerIKit = harden({ }); export const ZoeServiceI = M.interface('ZoeService', { - install: M.call(M.any()).returns(M.promise()), - installBundleID: M.call(M.string()).returns(M.promise()), + install: M.call(M.any()).optional(M.string()).returns(M.promise()), + installBundleID: M.call(M.string()).optional(M.string()).returns(M.promise()), startInstance: M.call(M.eref(InstallationShape)) - .optional(IssuerPKeywordRecordShape, M.any(), M.any()) + .optional(IssuerPKeywordRecordShape, M.record(), M.record(), M.string()) .returns(M.promise()), offer: M.call(M.eref(InvitationShape)) .optional(ProposalShape, PaymentPKeywordRecordShape, M.any()) diff --git a/packages/zoe/src/zoeService/installationStorage.js b/packages/zoe/src/zoeService/installationStorage.js index 9b12197d706..b06c5ed26cf 100644 --- a/packages/zoe/src/zoeService/installationStorage.js +++ b/packages/zoe/src/zoeService/installationStorage.js @@ -84,8 +84,12 @@ export const makeInstallationStorage = (getBundleCapForID, zoeBaggage) => { InstanceHandleShape, M.recordOf(M.string(), M.string({ stringLengthLimit: Infinity })), ), - ).returns(M.promise()), - installBundleID: M.call(M.string()).returns(M.promise()), + ) + .optional(M.string()) + .returns(M.promise()), + installBundleID: M.call(M.string()) + .optional(M.string()) + .returns(M.promise()), unwrapInstallation: M.callWhen(M.await(InstallationShape)).returns( UnwrappedInstallationShape, ), diff --git a/packages/zoe/test/unitTests/test-zoe.js b/packages/zoe/test/unitTests/test-zoe.js index 6d98ddec86c..65b31efae82 100644 --- a/packages/zoe/test/unitTests/test-zoe.js +++ b/packages/zoe/test/unitTests/test-zoe.js @@ -55,6 +55,15 @@ test(`E(zoe).installBundleID bad id`, async t => { }); }); +test(`E(zoe).installBundleID bad label`, async t => { + const { zoe } = setup(); + // @ts-expect-error deliberate invalid arguments for testing + await t.throwsAsync(() => E(zoe).installBundleID('a', harden([])), { + message: + 'In "installBundleID" method of (ZoeService): arg 1?: copyArray [] - Must be a string', + }); +}); + test(`E(zoe).installBundleID(bundleID)`, async t => { const { zoe, vatAdminState } = setup(); const contractPath = `${dirname}/../../src/contracts/atomicSwap`;