-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Check that makeInstance() returns an actual invite
Includes a test. closes #820
- Loading branch information
1 parent
b48efb1
commit 79a52c4
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
packages/zoe/test/unitTests/contracts/test-brokenContract.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
); | ||
}); |