Skip to content

Commit

Permalink
refactor: removed redundant check in coveredCall
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Dec 17, 2024
1 parent 0f7b7b8 commit cd810ec
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
7 changes: 1 addition & 6 deletions packages/zoe/src/contracts/coveredCall.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Fail, q } from '@endo/errors';
import { M, mustMatch } from '@agoric/store';

// Eventually will be importable from '@agoric/zoe-contract-support'
import { swapExact } from '../contractSupport/index.js';
import { isAfterDeadlineExitRule } from '../typeGuards.js';
Expand Down Expand Up @@ -69,11 +69,6 @@ const start = zcf => {

/** @type {OfferHandler} */
const makeOption = sellSeat => {
mustMatch(
sellSeat.getProposal(),
M.splitRecord({ exit: { afterDeadline: M.any() } }),
'exit afterDeadline',
);
const sellSeatExitRule = sellSeat.getProposal().exit;
if (!isAfterDeadlineExitRule(sellSeatExitRule)) {
throw Fail`the seller must have an afterDeadline exitRule, but instead had ${q(
Expand Down
48 changes: 47 additions & 1 deletion packages/zoe/test/unitTests/contracts/coveredCall.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';

import bundleSource from '@endo/bundle-source';
import { E } from '@endo/eventual-send';
import { Far } from '@endo/marshal';
import { deeplyFulfilled, Far } from '@endo/marshal';
import { AmountMath, AssetKind } from '@agoric/ertp';
import { claim } from '@agoric/ertp/src/legacy-payment-helpers.js';
import { keyEQ } from '@agoric/store';
Expand Down Expand Up @@ -1072,3 +1072,49 @@ test('zoe - coveredCall non-fungible', async t => {
t.deepEqual(bobCcPurse.getCurrentAmount().value, ['GrowlTiger']);
t.deepEqual(bobRpgPurse.getCurrentAmount().value, []);
});

test.only('zoe - coveredCall - bad proposal shape', async t => {

Check failure on line 1076 in packages/zoe/test/unitTests/contracts/coveredCall.test.js

View workflow job for this annotation

GitHub Actions / lint-primary

'test.only' is restricted from being used. Do not commit .only tests - they prevent other tests from running
const { moolaKit, simoleanKit, moola, zoe, vatAdminState } = setup();

// Bundle and install the contract.
const bundle = await bundleSource(coveredCallRoot);
vatAdminState.installBundle('b1-coveredcall', bundle);
const coveredCallInstallation =
await E(zoe).installBundleID('b1-coveredcall');

// Start an instance.
const issuerKeywordRecord = harden({
UnderlyingAsset: moolaKit.issuer,
StrikePrice: simoleanKit.issuer,
});
const { creatorInvitation } = await E(zoe).startInstance(
coveredCallInstallation,
issuerKeywordRecord,
);

// Make an unacceptable proposal.
const badProposal = harden({
give: { UnderlyingAsset: moola(3n) },
exit: { waived: null },
});
const payments = harden({
UnderlyingAsset: moolaKit.mint.mintPayment(moola(3n)),
});
const badSeat = await E(zoe).offer(creatorInvitation, badProposal, payments);
await t.throwsAsync(
() => E(badSeat).getOfferResult(),
{
message:
/the seller must have an afterDeadline exitRule, but instead had {"waived":null}/,
},
'A bad proposal shape must be rejected',
);

// The payment must be returned.
const payouts = await deeplyFulfilled(E(badSeat).getPayouts());
t.deepEqual(payouts, payments);
t.deepEqual(
await moolaKit.issuer.getAmountOf(payouts.UnderlyingAsset),
moola(3n),
);
});

0 comments on commit cd810ec

Please sign in to comment.