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 30, 2023
1 parent 1289bc4 commit 65a9619
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 @@ -119,11 +119,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 @@ -324,7 +330,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,6 +1,5 @@
/* eslint @typescript-eslint/no-floating-promises: "warn" */
import { E } from '@endo/eventual-send';
import { passStyleOf } from '@endo/marshal';
import {
M,
makeScalarBigMapStore,
Expand All @@ -16,7 +15,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 @@ -241,14 +240,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 @@ -310,6 +310,10 @@ test(`zcf.makeInvitation - no customDetails`, async t => {
handle: details.handle,
installation,
instance,
terms: {
brands: {},
issuers: {},
},
});
});

Expand All @@ -326,6 +330,10 @@ test(`zcf.makeInvitation - customDetails`, async t => {
handle: details.handle,
installation,
instance,
terms: {
brands: {},
issuers: {},
},
customDetails: {
timer,
whatever: 'whatever',
Expand All @@ -339,17 +347,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 65a9619

Please sign in to comment.