From cd810ec122d486ce77dd83a39756d3e0c7a7b165 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Tue, 17 Dec 2024 13:19:48 -0800 Subject: [PATCH] refactor: removed redundant check in coveredCall --- packages/zoe/src/contracts/coveredCall.js | 7 +-- .../unitTests/contracts/coveredCall.test.js | 48 ++++++++++++++++++- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/packages/zoe/src/contracts/coveredCall.js b/packages/zoe/src/contracts/coveredCall.js index 1f441aebb57..f70f4c7a27a 100644 --- a/packages/zoe/src/contracts/coveredCall.js +++ b/packages/zoe/src/contracts/coveredCall.js @@ -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'; @@ -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( diff --git a/packages/zoe/test/unitTests/contracts/coveredCall.test.js b/packages/zoe/test/unitTests/contracts/coveredCall.test.js index 6a6d6f788bc..f60aefdae7f 100644 --- a/packages/zoe/test/unitTests/contracts/coveredCall.test.js +++ b/packages/zoe/test/unitTests/contracts/coveredCall.test.js @@ -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'; @@ -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 => { + 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), + ); +});