From 0fd1c0696acb29f1bb4280c5d3a26e9b14b6132c Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Sat, 13 Jan 2024 15:12:55 -0800 Subject: [PATCH] fix: review suggestions --- packages/vat-data/test/test-prepare-revocable.js | 4 ++-- packages/zoe/src/contractFacet/types-ambient.d.ts | 15 +++++++++------ .../zoe/src/contractSupport/prepare-ownable.js | 15 ++++++++++++--- .../unitTests}/contracts/ownable-counter.js | 10 +++++----- .../unitTests/contracts/test-ownable-counter.js | 14 +++++++------- 5 files changed, 35 insertions(+), 23 deletions(-) rename packages/zoe/{src => test/unitTests}/contracts/ownable-counter.js (86%) diff --git a/packages/vat-data/test/test-prepare-revocable.js b/packages/vat-data/test/test-prepare-revocable.js index de22c14f467d..e56bc8a2ee4e 100644 --- a/packages/vat-data/test/test-prepare-revocable.js +++ b/packages/vat-data/test/test-prepare-revocable.js @@ -29,7 +29,7 @@ test('test revoke defineVirtualExoClass', t => { baggage, 'UpCounter', UpCounterI, - /** @param {number} x */ + /** @param {number} [x] */ (x = 0) => ({ x }), { incr(y = 1) { @@ -65,7 +65,7 @@ test('test revoke defineVirtualExoClassKit', t => { baggage, 'Counter', { up: UpCounterI, down: DownCounterI }, - /** @param {number} x */ + /** @param {number} [x] */ (x = 0) => ({ x }), { up: { diff --git a/packages/zoe/src/contractFacet/types-ambient.d.ts b/packages/zoe/src/contractFacet/types-ambient.d.ts index d6610121400d..6ee5f3f87d30 100644 --- a/packages/zoe/src/contractFacet/types-ambient.d.ts +++ b/packages/zoe/src/contractFacet/types-ambient.d.ts @@ -7,6 +7,14 @@ type IssuerOptionsRecord = import('@agoric/ertp').IssuerOptionsRecord; */ type Completion = any; type ZCFMakeEmptySeatKit = (exit?: ExitRule | undefined) => ZcfSeatKit; + +type MakeInvitation = ( + offerHandler: OfferHandler, + description: string, + customDetails?: object, + proposalShape?: Pattern, +) => Promise>; + /** * Zoe Contract Facet * @@ -54,12 +62,7 @@ type ZCF> = { * getting in the `customDetails`. `customDetails` will be * placed in the details of the invitation. */ - makeInvitation: ( - offerHandler: OfferHandler, - description: string, - customDetails?: object, - proposalShape?: Pattern, - ) => Promise>; + makeInvitation: MakeInvitation; shutdown: (completion: Completion) => void; shutdownWithFailure: ShutdownWithFailure; getZoeService: () => ERef; diff --git a/packages/zoe/src/contractSupport/prepare-ownable.js b/packages/zoe/src/contractSupport/prepare-ownable.js index 92670ec450a6..6eaafcbe6692 100644 --- a/packages/zoe/src/contractSupport/prepare-ownable.js +++ b/packages/zoe/src/contractSupport/prepare-ownable.js @@ -10,9 +10,18 @@ const TransferProposalShape = M.splitRecord({ }, }); +/** + * @template {any} [U=any] + * @param {import('@agoric/vat-data').Baggage} baggage + * @param {MakeInvitation} makeInvitation + * @param {string} uKindName + * @param {string} uInterfaceName + * @param {(string|symbol)[]} uMethodNames + * @returns {(underlying: U) => U} + */ export const prepareOwnable = ( - zcf, baggage, + makeInvitation, uKindName, uInterfaceName, uMethodNames, @@ -37,11 +46,11 @@ export const prepareOwnable = ( revoker, }, } = this; - const customDetails = underlying.getCustomDetails(); + const customDetails = underlying.getInvitationCustomDetails(); // eslint-disable-next-line no-use-before-define const transferHandler = makeTransferHandler(underlying); - const invitation = zcf.makeInvitation( + const invitation = makeInvitation( transferHandler, 'transfer', customDetails, diff --git a/packages/zoe/src/contracts/ownable-counter.js b/packages/zoe/test/unitTests/contracts/ownable-counter.js similarity index 86% rename from packages/zoe/src/contracts/ownable-counter.js rename to packages/zoe/test/unitTests/contracts/ownable-counter.js index ac08b66c56d7..2ca304c548af 100644 --- a/packages/zoe/src/contracts/ownable-counter.js +++ b/packages/zoe/test/unitTests/contracts/ownable-counter.js @@ -1,6 +1,6 @@ import { M } from '@endo/patterns'; import { prepareExoClassKit } from '@agoric/vat-data'; -import { prepareOwnable } from '../contractSupport/prepare-ownable.js'; +import { prepareOwnable } from '../../../src/contractSupport/prepare-ownable.js'; /** @typedef {import('@agoric/vat-data').Baggage} Baggage */ @@ -20,7 +20,7 @@ export const start = async (zcf, privateArgs, baggage) => { counter: M.interface('Counter', { incr: M.call().returns(M.bigint()), // required by makePrepareOwnableClass - getCustomDetails: M.call().returns( + getInvitationCustomDetails: M.call().returns( harden({ count: M.bigint(), }), @@ -40,7 +40,7 @@ export const start = async (zcf, privateArgs, baggage) => { state.count += 1n; return state.count; }, - getCustomDetails() { + getInvitationCustomDetails() { const { state: { count }, } = this; @@ -61,11 +61,11 @@ export const start = async (zcf, privateArgs, baggage) => { ); const makeOwnableCounter = prepareOwnable( - zcf, baggage, + (...args) => zcf.makeInvitation(...args), 'Counter', 'OwnableCounter', - ['incr', 'getCustomDetails'], + ['incr', 'getInvitationCustomDetails'], ); const { counter: underlyingCounter, viewer } = diff --git a/packages/zoe/test/unitTests/contracts/test-ownable-counter.js b/packages/zoe/test/unitTests/contracts/test-ownable-counter.js index 7484e8a60f49..f737793c5624 100644 --- a/packages/zoe/test/unitTests/contracts/test-ownable-counter.js +++ b/packages/zoe/test/unitTests/contracts/test-ownable-counter.js @@ -12,7 +12,7 @@ import { makeFakeVatAdmin } from '../../../tools/fakeVatAdmin.js'; const filename = new URL(import.meta.url).pathname; const dirname = path.dirname(filename); -const root = `${dirname}/../../../src/contracts/ownable-counter.js`; +const root = `${dirname}/ownable-counter.js`; test('zoe - ownable-counter contract', async t => { const { admin: fakeVatAdmin, vatAdminState } = makeFakeVatAdmin(); @@ -44,7 +44,7 @@ test('zoe - ownable-counter contract', async t => { t.deepEqual(await E(firstCounter)[GET_METHOD_NAMES](), [ '__getInterfaceGuard__', '__getMethodNames__', - 'getCustomDetails', + 'getInvitationCustomDetails', 'incr', 'makeTransferInvitation', ]); @@ -52,7 +52,7 @@ test('zoe - ownable-counter contract', async t => { t.is(await E(firstCounter).incr(), 4n); t.is(await E(viewCounter).view(), 4n); - t.deepEqual(await E(firstCounter).getCustomDetails(), { + t.deepEqual(await E(firstCounter).getInvitationCustomDetails(), { count: 4n, }); @@ -61,12 +61,12 @@ test('zoe - ownable-counter contract', async t => { t.deepEqual(await E(firstCounter)[GET_METHOD_NAMES](), [ '__getInterfaceGuard__', '__getMethodNames__', - 'getCustomDetails', + 'getInvitationCustomDetails', 'incr', 'makeTransferInvitation', ]); - await t.throwsAsync(() => E(firstCounter).getCustomDetails(), { + await t.throwsAsync(() => E(firstCounter).getInvitationCustomDetails(), { message: '"Counter_caretaker" revoked', }); await t.throwsAsync(() => E(firstCounter).incr(), { @@ -97,14 +97,14 @@ test('zoe - ownable-counter contract', async t => { t.is(await E(reviveCounterSeat).hasExited(), true); t.is(await E(viewCounter).view(), 4n); - t.deepEqual(await E(counter2).getCustomDetails(), { + t.deepEqual(await E(counter2).getInvitationCustomDetails(), { count: 4n, }); t.is(await E(counter2).incr(), 5n); t.is(await E(viewCounter).view(), 5n); - t.deepEqual(await E(counter2).getCustomDetails(), { + t.deepEqual(await E(counter2).getInvitationCustomDetails(), { count: 5n, }); });