From acd93814cb4db95a626fcd9eb32581c9a5e3980d Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Thu, 9 Mar 2023 15:04:32 -0800 Subject: [PATCH] fix(zoe): add terms to invite details --- packages/zoe/src/typeGuards.js | 8 +++++++- packages/zoe/src/zoeService/startInstance.js | 11 +--------- packages/zoe/src/zoeService/types.js | 1 + .../zoe/src/zoeService/zoeStorageManager.js | 7 ++++--- packages/zoe/test/unitTests/zcf/test-zcf.js | 20 +++++++++++++++++++ 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/packages/zoe/src/typeGuards.js b/packages/zoe/src/typeGuards.js index a5264eb2e190..3f480ca2de53 100644 --- a/packages/zoe/src/typeGuards.js +++ b/packages/zoe/src/typeGuards.js @@ -113,11 +113,17 @@ export const isAfterDeadlineExitRule = exit => { return exitKey === 'afterDeadline'; }; +export const AnyTermsShape = M.splitRecord({ + issuers: M.recordOf(KeywordShape, IssuerShape), + brands: M.recordOf(KeywordShape, BrandShape), +}); + export const InvitationElementShape = M.splitRecord({ description: M.string(), handle: InvitationHandleShape, instance: InstanceHandleShape, installation: InstallationShape, + terms: AnyTermsShape, }); export const OfferHandlerI = M.interface('OfferHandler', { @@ -318,7 +324,7 @@ export const ZoeServiceI = M.interface('ZoeService', { install: M.call(M.any()).returns(M.promise()), installBundleID: M.call(M.string()).returns(M.promise()), startInstance: M.call(M.eref(InstallationShape)) - .optional(IssuerPKeywordRecordShape, M.any(), M.any()) + .optional(IssuerPKeywordRecordShape, M.key(), M.opt(M.record())) .returns(M.promise()), offer: M.call(M.eref(InvitationShape)) .optional(ProposalShape, PaymentPKeywordRecordShape, M.any()) diff --git a/packages/zoe/src/zoeService/startInstance.js b/packages/zoe/src/zoeService/startInstance.js index fb1eb2134137..0ee8b576b640 100644 --- a/packages/zoe/src/zoeService/startInstance.js +++ b/packages/zoe/src/zoeService/startInstance.js @@ -1,5 +1,4 @@ import { E } from '@endo/eventual-send'; -import { passStyleOf } from '@endo/marshal'; import { M, makeScalarBigMapStore, @@ -15,7 +14,7 @@ import { AdminFacetI, InstanceAdminI } from '../typeGuards.js'; /** @typedef {import('@agoric/vat-data').Baggage} Baggage */ /** @typedef { import('@agoric/swingset-vat').BundleCap} BundleCap */ -const { Fail, quote: q } = assert; +const { Fail } = assert; /** * @param {Pick} startInstanceAccess @@ -240,14 +239,6 @@ export const makeStartInstance = ( const contractBundleCap = bundle || bundleCap; assert(contractBundleCap); - if (privateArgs !== undefined) { - const passStyle = passStyleOf(privateArgs); - passStyle === 'copyRecord' || - Fail`privateArgs must be a pass-by-copy record, but instead was a ${q( - passStyle, - )}: ${privateArgs}`; - } - const instanceHandle = makeInstanceHandle(); const instanceBaggage = makeScalarBigMapStore('instanceBaggage', { diff --git a/packages/zoe/src/zoeService/types.js b/packages/zoe/src/zoeService/types.js index 34897fd32e34..1f6b774b2fae 100644 --- a/packages/zoe/src/zoeService/types.js +++ b/packages/zoe/src/zoeService/types.js @@ -305,6 +305,7 @@ * @typedef {object} InvitationDetails * @property {Installation} installation * @property {import('./utils').Instance} instance + * @property {AnyTerms} terms * @property {InvitationHandle} handle * @property {string} description * @property {Record} [customDetails] diff --git a/packages/zoe/src/zoeService/zoeStorageManager.js b/packages/zoe/src/zoeService/zoeStorageManager.js index 9f2d8d36d11f..9d7f2ec38929 100644 --- a/packages/zoe/src/zoeService/zoeStorageManager.js +++ b/packages/zoe/src/zoeService/zoeStorageManager.js @@ -275,6 +275,7 @@ export const makeZoeStorageManager = ( ownKeys(customDetails).length >= 1 ? harden({ customDetails }) : harden({}); + const instanceRecord = state.instanceState.getInstanceRecord(); const invitationAmount = AmountMath.make( invitationKit.brand, harden([ @@ -282,9 +283,9 @@ export const makeZoeStorageManager = ( ...extraProperties, description: desc, handle, - instance: state.instanceState.getInstanceRecord().instance, - installation: - state.instanceState.getInstanceRecord().installation, + instance: instanceRecord.instance, + installation: instanceRecord.installation, + terms: instanceRecord.terms, }, ]), ); diff --git a/packages/zoe/test/unitTests/zcf/test-zcf.js b/packages/zoe/test/unitTests/zcf/test-zcf.js index e4f77c559463..5ceec6ae24ca 100644 --- a/packages/zoe/test/unitTests/zcf/test-zcf.js +++ b/packages/zoe/test/unitTests/zcf/test-zcf.js @@ -309,6 +309,10 @@ test(`zcf.makeInvitation - no customDetails`, async t => { handle: details.handle, installation, instance, + terms: { + brands: {}, + issuers: {}, + }, }); }); @@ -325,6 +329,10 @@ test(`zcf.makeInvitation - customDetails`, async t => { handle: details.handle, installation, instance, + terms: { + brands: {}, + issuers: {}, + }, customDetails: { timer, whatever: 'whatever', @@ -338,6 +346,10 @@ test(`zcf.makeInvitation - customDetails stratification`, async t => { description: 'whatever', installation: 'whatever', instance: 'whatever', + terms: { + brands: {}, + issuers: {}, + }, }); const details = await E(zoe).getInvitationDetails(invitationP); t.deepEqual(details, { @@ -345,10 +357,18 @@ test(`zcf.makeInvitation - customDetails stratification`, async t => { handle: details.handle, installation, instance, + terms: { + brands: {}, + issuers: {}, + }, customDetails: { description: 'whatever', installation: 'whatever', instance: 'whatever', + terms: { + brands: {}, + issuers: {}, + }, }, }); t.falsy(typeof details.handle === 'string');