Skip to content

Commit

Permalink
fix(zoe): add terms to invite details
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Aug 9, 2023
1 parent cbec0c6 commit acd9381
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
8 changes: 7 additions & 1 deletion packages/zoe/src/typeGuards.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down Expand Up @@ -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())
Expand Down
11 changes: 1 addition & 10 deletions packages/zoe/src/zoeService/startInstance.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { E } from '@endo/eventual-send';
import { passStyleOf } from '@endo/marshal';
import {
M,
makeScalarBigMapStore,
Expand All @@ -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<ZoeStorageManager, 'makeZoeInstanceStorageManager' | 'unwrapInstallation'>} startInstanceAccess
Expand Down Expand Up @@ -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', {
Expand Down
1 change: 1 addition & 0 deletions packages/zoe/src/zoeService/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@
* @typedef {object} InvitationDetails
* @property {Installation} installation
* @property {import('./utils').Instance<any>} instance
* @property {AnyTerms} terms
* @property {InvitationHandle} handle
* @property {string} description
* @property {Record<string, any>} [customDetails]
Expand Down
7 changes: 4 additions & 3 deletions packages/zoe/src/zoeService/zoeStorageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,17 @@ export const makeZoeStorageManager = (
ownKeys(customDetails).length >= 1
? harden({ customDetails })
: harden({});
const instanceRecord = state.instanceState.getInstanceRecord();
const invitationAmount = AmountMath.make(
invitationKit.brand,
harden([
{
...extraProperties,
description: desc,
handle,
instance: state.instanceState.getInstanceRecord().instance,
installation:
state.instanceState.getInstanceRecord().installation,
instance: instanceRecord.instance,
installation: instanceRecord.installation,
terms: instanceRecord.terms,
},
]),
);
Expand Down
20 changes: 20 additions & 0 deletions packages/zoe/test/unitTests/zcf/test-zcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ test(`zcf.makeInvitation - no customDetails`, async t => {
handle: details.handle,
installation,
instance,
terms: {
brands: {},
issuers: {},
},
});
});

Expand All @@ -325,6 +329,10 @@ test(`zcf.makeInvitation - customDetails`, async t => {
handle: details.handle,
installation,
instance,
terms: {
brands: {},
issuers: {},
},
customDetails: {
timer,
whatever: 'whatever',
Expand All @@ -338,17 +346,29 @@ 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, {
description: 'myInvitation',
handle: details.handle,
installation,
instance,
terms: {
brands: {},
issuers: {},
},
customDetails: {
description: 'whatever',
installation: 'whatever',
instance: 'whatever',
terms: {
brands: {},
issuers: {},
},
},
});
t.falsy(typeof details.handle === 'string');
Expand Down

0 comments on commit acd9381

Please sign in to comment.