Skip to content

Commit

Permalink
test: update tests to understand that executeOffer doesn't throw
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Nov 10, 2023
1 parent 227f5ec commit 65d8aef
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 49 deletions.
4 changes: 2 additions & 2 deletions packages/agoric-cli/test/test-inter-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const makeProcess = (t, keyring, out) => {
};

/**
* @type {import('@agoric/smart-wallet/src/smartWallet.js').OfferStatus &
* @type {import('@agoric/smart-wallet/src/offerWatcher.js').OfferStatus &
* { offerArgs: import('@agoric/inter-protocol/src/auction/auctionBook.js').OfferSpec}}
*/
const offerStatus2 = harden({
Expand Down Expand Up @@ -253,7 +253,7 @@ test('amount parsing', t => {
test.todo('want as max collateral wanted');

/**
* @type {import('@agoric/smart-wallet/src/smartWallet.js').OfferStatus &
* @type {import('@agoric/smart-wallet/src/offerWatcher.js').OfferStatus &
* { offerArgs: import('@agoric/inter-protocol/src/auction/auctionBook.js').OfferSpec}}
*/
const offerStatus1 = harden({
Expand Down
50 changes: 25 additions & 25 deletions packages/boot/test/bootstrapTests/test-vaults-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import { SECONDS_PER_DAY } from '@agoric/inter-protocol/src/proposals/econ-behav
import { unmarshalFromVstorage } from '@agoric/internal/src/marshal.js';
import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js';
import { makeMarshal } from '@endo/marshal';
import {
makeAgoricNamesRemotesFromFakeStorage,
slotToBoardRemote,
} from '@agoric/vats/tools/board-utils.js';
import { makeAgoricNamesRemotesFromFakeStorage, slotToBoardRemote } from '@agoric/vats/tools/board-utils.js';
import type { TestFn } from 'ava';
import { ParamChangesOfferArgs } from '@agoric/inter-protocol/src/econCommitteeCharter.js';

import { makeWalletFactoryDriver } from './drivers.ts';
import { makeSwingsetTestKit } from './supports.ts';

Expand Down Expand Up @@ -136,6 +134,8 @@ test('adjust balances', async t => {
});
});

// This test isn't marked .serial, but it depends on previous tests.

test('close vault', async t => {
const { walletFactoryDriver } = t.context;

Expand All @@ -151,7 +151,8 @@ test('close vault', async t => {
});
t.like(wd.getLatestUpdateRecord(), {
updated: 'offerStatus',
status: { id: 'open-vault', numWantsSatisfied: 1 },
status: { id: 'open-vault', result: 'UNPUBLISHED', numWantsSatisfied: 1 },
error: undefined,
});
t.log('try giving more than is available in the purse/vbank');
await t.throwsAsync(
Expand All @@ -171,20 +172,18 @@ test('close vault', async t => {

const message =
'Offer {"brand":"[Alleged: IST brand]","value":"[1n]"} is not sufficient to pay off debt {"brand":"[Alleged: IST brand]","value":"[5025000n]"}';
await t.throwsAsync(
wd.executeOfferMaker(
Offers.vaults.CloseVault,
{
offerId: 'close-insufficient',
collateralBrandKey,
giveMinted: 0.000_001,
},
'open-vault',
),

// does not throw, because it's in the result, but it will show up in errors
await wd.executeOfferMaker(
Offers.vaults.CloseVault,
{
message,
offerId: 'close-insufficient',
collateralBrandKey,
giveMinted: 0.000_001,
},
'open-vault',
);

t.like(wd.getLatestUpdateRecord(), {
updated: 'offerStatus',
status: {
Expand All @@ -204,10 +203,13 @@ test('close vault', async t => {
},
'open-vault',
);

t.like(wd.getLatestUpdateRecord(), {
updated: 'offerStatus',
status: {
id: 'close-well',
error: undefined,
numWantsSatisfied: 1,
result: 'your vault is closed, thank you for your business',
// funds are returned
payouts: likePayouts(giveCollateral, 0),
Expand All @@ -226,15 +228,13 @@ test('open vault with insufficient funds gives helpful error', async t => {
const wantMinted = giveCollateral * 100;
const message =
'Proposed debt {"brand":"[Alleged: IST brand]","value":"[904500000n]"} exceeds max {"brand":"[Alleged: IST brand]","value":"[63462857n]"} for {"brand":"[Alleged: ATOM brand]","value":"[9000000n]"} collateral';
await t.throwsAsync(
wd.executeOfferMaker(Offers.vaults.OpenVault, {
offerId: 'open-vault',
collateralBrandKey,
giveCollateral,
wantMinted,
}),
{ message },
);

await wd.executeOfferMaker(Offers.vaults.OpenVault, {
offerId: 'open-vault',
collateralBrandKey,
giveCollateral,
wantMinted,
});

t.like(wd.getLatestUpdateRecord(), {
updated: 'offerStatus',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ const checkFlow = async (
await EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);
};

const metricsPath = `published.vaultFactory.managers.manager${managerIndex}.metrics`;
await setupVaults(collateralBrandKey, managerIndex, setup);

// restart Zoe
Expand All @@ -107,9 +106,6 @@ const checkFlow = async (
};
await buildAndExecuteProposal(zoeUpgradeSpec);

// const zoe = await EV.vat('bootstrap').consumeItem('zoe');
// const invitationIssuer = await EV(zoe).getInvitationIssuer();
// const invitationBrand = await EV(invitationIssuer).getBrand()
t.like(await buyer.getLatestUpdateRecord(), {
currentAmount: {
// brand from EV() doesn't compare correctly
Expand Down
31 changes: 17 additions & 14 deletions packages/smart-wallet/src/offerWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const offerWatcherGuard = harden({
.optional(M.record())
.returns(),
publishResult: M.call(M.any()).returns(),
exitOpenSeats: M.call(M.any()).returns(),
exitOpenSeat: M.call(M.any()).returns(),
}),
paymentWatcher: M.interface('paymentWatcher', {
onFulfilled: M.call(PaymentPKeywordRecordShape, SeatShape).returns(
Expand Down Expand Up @@ -146,7 +146,7 @@ export const makeOfferWatcherMaker = baggage => {
}
},

exitOpenSeats(reason) {
exitOpenSeat(reason) {
const { state } = this;
void E.when(E(state.seatRef).hasExited(), hasExited => {
if (!hasExited) {
Expand All @@ -171,15 +171,16 @@ export const makeOfferWatcherMaker = baggage => {
const amounts = await deeplyFulfilledObject(amountPKeywordRecord);
facets.helper.updateStatus({ payouts: amounts });
},
onRejected(reason, seat) {
onRejected(err, seat) {
const { facets } = this;

if (isUpgradeDisconnection(reason)) {
console.log(`resetting payments watcher after upgrade`, reason);
if (isUpgradeDisconnection(err)) {
console.log(`resetting payments watcher after upgrade`, err);
// eslint-disable-next-line no-use-before-define
watchForPayout(seat);
} else {
facets.helper.exitOpenSeats(reason);
facets.helper.updateStatus({ error: err.toString() });
facets.helper.exitOpenSeat(err);
}
},
},
Expand All @@ -189,13 +190,14 @@ export const makeOfferWatcherMaker = baggage => {
const { facets } = this;
facets.helper.publishResult(result);
},
onRejected(reason, seat) {
onRejected(err, seat) {
const { facets } = this;
if (isUpgradeDisconnection(reason)) {
console.log(`resetting offerResults watcher after upgrade`, reason);
if (isUpgradeDisconnection(err)) {
console.log(`resetting offerResults watcher after upgrade`, err);
watchForOfferResult(facets, seat);
} else {
facets.helper.exitOpenSeats(reason);
facets.helper.updateStatus({ error: err.toString() });
facets.helper.exitOpenSeat(err);
}
},
},
Expand All @@ -206,13 +208,14 @@ export const makeOfferWatcherMaker = baggage => {

facets.helper.updateStatus({ numWantsSatisfied: numSatisfied });
},
onRejected(reason, seat) {
onRejected(err, seat) {
const { facets } = this;
if (isUpgradeDisconnection(reason)) {
console.log(`resetting numWants watcher after upgrade`, reason);
if (isUpgradeDisconnection(err)) {
console.log(`resetting numWants watcher after upgrade`, err);
watchForNumWants(facets, seat);
} else {
facets.helper.exitOpenSeats(reason);
facets.helper.updateStatus({ error: err.toString() });
facets.helper.exitOpenSeat(err);
}
},
},
Expand Down
12 changes: 8 additions & 4 deletions packages/smart-wallet/src/smartWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,7 @@ export const prepareSmartWallet = (baggage, shared) => {
status: offerStatus,
});

const isSeatExited = 'numWantsSatisfied' in offerStatus;
if (isSeatExited) {
if ('numWantsSatisfied' in offerStatus) {
if (state.liveOfferSeats.has(offerStatus.id)) {
state.liveOfferSeats.delete(offerStatus.id);
}
Expand All @@ -609,6 +608,8 @@ export const prepareSmartWallet = (baggage, shared) => {

if (state.liveOffers.has(offerStatus.id)) {
state.liveOffers.delete(offerStatus.id);
// This might get skipped in subsequent passes, since we .delete()
// the first time through
facets.helper.publishCurrentState();
}
}
Expand Down Expand Up @@ -833,10 +834,12 @@ export const prepareSmartWallet = (baggage, shared) => {
seatRef,
);

watchOfferOutcomes(watcher, seatRef);
state.liveOffers.init(offerSpec.id, offerSpec);
facets.helper.publishCurrentState();
state.liveOfferSeats.init(offerSpec.id, seatRef);

watchOfferOutcomes(watcher, seatRef);

facets.helper.publishCurrentState();
} catch (err) {
console.error('OFFER ERROR:', err);
// Notify the user
Expand Down Expand Up @@ -867,6 +870,7 @@ export const prepareSmartWallet = (baggage, shared) => {
}
});
}

throw err;
}
},
Expand Down

0 comments on commit 65d8aef

Please sign in to comment.