Skip to content

Commit

Permalink
feat: Check that makeInstance() returns an actual invite
Browse files Browse the repository at this point in the history
Includes a test.

closes #820
  • Loading branch information
Chris-Hibbert committed Apr 10, 2020
1 parent b48efb1 commit 79a52c4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/zoe/src/zoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,13 @@ const makeZoe = (additionalEndowments = {}) => {
// Once the contract is made, we add the publicAPI to the
// contractRecord
instanceTable.update(instanceHandle, { publicAPI });
return invite;
return inviteIssuer.isLive(invite).then(success => {
assert(
success,
details`invites must be issued by the inviteIssuer.`,
);
return invite;
});
});
};

Expand Down
27 changes: 27 additions & 0 deletions packages/zoe/test/unitTests/contracts/brokenAutoRefund.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @ts-check
import harden from '@agoric/harden';

/**
* This is a a broken contact to test zoe's error handling
* @type {import('@agoric/zoe').MakeContract} zoe - the contract facet of zoe
*/
export const makeContract = harden(zoe => {
const makeSeatInvite = () => {
const seat = harden({
makeOffer: () => {
// eslint-disable-next-line no-use-before-define
zoe.complete(harden([inviteHandle]));
return `The offer was accepted`;
},
});
const { invite, inviteHandle } = zoe.makeInvite(seat, {
seatDesc: 'getRefund',
});
return invite;
};
return harden({
// should be makeSeatInvite(). Intentionally wrong to provoke an error.
invite: makeSeatInvite,
publicAPI: {},
});
});
31 changes: 31 additions & 0 deletions packages/zoe/test/unitTests/contracts/test-brokenContract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { test } from 'tape-promise/tape';
// eslint-disable-next-line import/no-extraneous-dependencies
import bundleSource from '@agoric/bundle-source';

import harden from '@agoric/harden';

import { makeZoe } from '../../../src/zoe';
// TODO: Remove setupBasicMints and rename setupBasicMints2
import { setup } from '../setupBasicMints2';

const automaticRefundRoot = `${__dirname}/brokenAutoRefund`;

test.only('zoe - brokenAutomaticRefund', async t => {
t.plan(1);
// Setup zoe and mints
const { moolaR } = setup();
const zoe = makeZoe({ require });
// Pack the contract.
const { source, moduleFormat } = await bundleSource(automaticRefundRoot);
const installationHandle = zoe.install(source, moduleFormat);

const issuerKeywordRecord = harden({ Contribution: moolaR.issuer });

// 1: Alice tries to create an instance, but the contract is badly written.
t.rejects(
() => zoe.makeInstance(installationHandle, issuerKeywordRecord),
new Error('invites must be issued by InviteIssuer'),
'makeInstance should have thrown',
);
});

0 comments on commit 79a52c4

Please sign in to comment.