Skip to content

Commit

Permalink
fix: review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 15, 2024
1 parent 471156c commit 0fd1c06
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages/vat-data/test/test-prepare-revocable.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('test revoke defineVirtualExoClass', t => {
baggage,
'UpCounter',
UpCounterI,
/** @param {number} x */
/** @param {number} [x] */
(x = 0) => ({ x }),
{
incr(y = 1) {
Expand Down Expand Up @@ -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: {
Expand Down
15 changes: 9 additions & 6 deletions packages/zoe/src/contractFacet/types-ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ type IssuerOptionsRecord = import('@agoric/ertp').IssuerOptionsRecord;
*/
type Completion = any;
type ZCFMakeEmptySeatKit = (exit?: ExitRule | undefined) => ZcfSeatKit;

type MakeInvitation = <Result>(
offerHandler: OfferHandler<Result>,
description: string,
customDetails?: object,
proposalShape?: Pattern,
) => Promise<Invitation<R, A>>;

/**
* Zoe Contract Facet
*
Expand Down Expand Up @@ -54,12 +62,7 @@ type ZCF<CT extends unknown = Record<string, unknown>> = {
* getting in the `customDetails`. `customDetails` will be
* placed in the details of the invitation.
*/
makeInvitation: <Result>(
offerHandler: OfferHandler<Result>,
description: string,
customDetails?: object,
proposalShape?: Pattern,
) => Promise<Invitation<R, A>>;
makeInvitation: MakeInvitation;
shutdown: (completion: Completion) => void;
shutdownWithFailure: ShutdownWithFailure;
getZoeService: () => ERef<ZoeService>;
Expand Down
15 changes: 12 additions & 3 deletions packages/zoe/src/contractSupport/prepare-ownable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 */

Expand All @@ -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(),
}),
Expand All @@ -40,7 +40,7 @@ export const start = async (zcf, privateArgs, baggage) => {
state.count += 1n;
return state.count;
},
getCustomDetails() {
getInvitationCustomDetails() {
const {
state: { count },
} = this;
Expand All @@ -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 } =
Expand Down
14 changes: 7 additions & 7 deletions packages/zoe/test/unitTests/contracts/test-ownable-counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -44,15 +44,15 @@ test('zoe - ownable-counter contract', async t => {
t.deepEqual(await E(firstCounter)[GET_METHOD_NAMES](), [
'__getInterfaceGuard__',
'__getMethodNames__',
'getCustomDetails',
'getInvitationCustomDetails',
'incr',
'makeTransferInvitation',
]);

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,
});

Expand All @@ -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(), {
Expand Down Expand Up @@ -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,
});
});

0 comments on commit 0fd1c06

Please sign in to comment.