Skip to content

Commit

Permalink
chore(types): PromiseWatcher
Browse files Browse the repository at this point in the history
refactor: refactor smartWallet to use watchedPromises

pulled offers.js and payments.js into smartWallet.js as they shared
plenty of state that needs to be durable in order to be callable from
the watchedPromise.

build an upgrade proposal; tested in
Agoric/agoric-3-proposals#34
  • Loading branch information
turadg authored and Chris-Hibbert committed Dec 6, 2023
1 parent 7153535 commit 2fd24cd
Show file tree
Hide file tree
Showing 18 changed files with 818 additions and 689 deletions.
41 changes: 7 additions & 34 deletions packages/boot/test/bootstrapTests/liquidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ import {
SECONDS_PER_HOUR,
SECONDS_PER_MINUTE,
} from '@agoric/inter-protocol/src/proposals/econ-behaviors.js';
import {
AgoricNamesRemotes,
makeAgoricNamesRemotesFromFakeStorage,
} from '@agoric/vats/tools/board-utils.js';
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import type { ExecutionContext } from 'ava';
import { makeSwingsetTestKit } from '../../tools/supports.ts';
import {
makeGovernanceDriver,
makePriceFeedDriver,
makeWalletFactoryDriver,
} from '../../tools/drivers.ts';
import { makeWalletFactoryContext } from './walletFactory.ts';

export type LiquidationSetup = {
vaults: {
Expand Down Expand Up @@ -65,35 +60,13 @@ export const likePayouts = ({ Bid, Collateral }) => ({

export const makeLiquidationTestContext = async t => {
console.time('DefaultTestContext');
const swingsetTestKit = await makeSwingsetTestKit(t.log, 'bundles/vaults', {
configSpecifier: '@agoric/vm-config/decentral-main-vaults-config.json',
});

const { runUtils, storage } = swingsetTestKit;
console.timeLog('DefaultTestContext', 'swingsetTestKit');
const { EV } = runUtils;

// Wait for ATOM to make it into agoricNames
await EV.vat('bootstrap').consumeItem('vaultFactoryKit');
console.timeLog('DefaultTestContext', 'vaultFactoryKit');

// has to be late enough for agoricNames data to have been published
const agoricNamesRemotes: AgoricNamesRemotes =
makeAgoricNamesRemotesFromFakeStorage(swingsetTestKit.storage);
const refreshAgoricNamesRemotes = () => {
Object.assign(
agoricNamesRemotes,
makeAgoricNamesRemotesFromFakeStorage(swingsetTestKit.storage),
);
};
agoricNamesRemotes.brand.ATOM || Fail`ATOM missing from agoricNames`;
console.timeLog('DefaultTestContext', 'agoricNamesRemotes');

const walletFactoryDriver = await makeWalletFactoryDriver(
runUtils,
storage,
const {
swingsetTestKit,
agoricNamesRemotes,
);
refreshAgoricNamesRemotes,
walletFactoryDriver,
} = await makeWalletFactoryContext(t);

console.timeLog('DefaultTestContext', 'walletFactoryDriver');

const governanceDriver = await makeGovernanceDriver(
Expand Down
16 changes: 12 additions & 4 deletions packages/boot/test/bootstrapTests/test-vaults-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@agoric/vats/tools/board-utils.js';
import type { TestFn } from 'ava';
import { ParamChangesOfferArgs } from '@agoric/inter-protocol/src/econCommitteeCharter.js';

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

Expand Down Expand Up @@ -136,6 +137,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 +154,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,6 +175,7 @@ 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,
Expand All @@ -181,10 +186,9 @@ test('close vault', async t => {
},
'open-vault',
),
{
message,
},
{ message },
);

t.like(wd.getLatestUpdateRecord(), {
updated: 'offerStatus',
status: {
Expand All @@ -204,10 +208,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,6 +233,7 @@ 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',
Expand Down
Loading

0 comments on commit 2fd24cd

Please sign in to comment.