Skip to content

Commit

Permalink
feat: smart wallet can upgrade to use promiseWatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert authored and turadg committed Nov 30, 2023
1 parent 6c0ea11 commit cbb2dae
Show file tree
Hide file tree
Showing 13 changed files with 354 additions and 301 deletions.
10 changes: 5 additions & 5 deletions packages/boot/test/bootstrapTests/liquidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const likePayouts = ({ Bid, Collateral }) => ({

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

const { runUtils, storage } = swingsetTestKit;
Expand All @@ -82,7 +82,7 @@ export const makeWalletFactoryContext = async t => {
const refreshAgoricNamesRemotes = () => {
Object.assign(
agoricNamesRemotes,
makeAgoricNamesRemotesFromFakeStorage(swingsetTestKit.storage)
makeAgoricNamesRemotesFromFakeStorage(swingsetTestKit.storage),
);
};
agoricNamesRemotes.brand.ATOM || Fail`ATOM missing from agoricNames`;
Expand All @@ -91,7 +91,7 @@ export const makeWalletFactoryContext = async t => {
const walletFactoryDriver = await makeWalletFactoryDriver(
runUtils,
storage,
agoricNamesRemotes
agoricNamesRemotes,
);
return {
...swingsetTestKit,
Expand All @@ -112,8 +112,8 @@ export const makeLiquidationTestContext = async t => {
swingsetTestKit,
agoricNamesRemotes,
refreshAgoricNamesRemotes,
walletFactoryDriver
} = await makeWalletFactoryContext(t);
walletFactoryDriver,
} = await makeWalletFactoryContext(t);

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

Expand Down
45 changes: 24 additions & 21 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,20 +175,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 +206,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 +231,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
15 changes: 3 additions & 12 deletions packages/boot/test/bootstrapTests/test-walletSurvivesZoeRestart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';
import process from 'process';
import type { ExecutionContext, TestFn } from 'ava';

import { ERef } from '@endo/far';
import { BridgeHandler } from '@agoric/vats';
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import {
LiquidationTestContext,
makeLiquidationTestContext,
LiquidationSetup,
} from './liquidation.ts';
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';

const test = anyTest as TestFn<LiquidationTestContext>;

Expand Down Expand Up @@ -78,7 +77,7 @@ const checkFlow = async (

const buyer = await walletFactoryDriver.provideSmartWallet('agoric1buyer');

const buildAndExecuteProposal = async packageSpec => {
const buildAndExecuteProposal = async (packageSpec: string) => {
const proposal = await buildProposal(packageSpec);

for await (const bundle of proposal.bundles) {
Expand All @@ -96,21 +95,13 @@ const checkFlow = async (
await EV(coreEvalBridgeHandler).fromBridge(bridgeMessage);
};

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

// restart Zoe

// /////// Upgrading ////////////////////////////////
const zoeUpgradeSpec = {
package: 'builders',
packageScriptName: 'build:null-upgrade-zoe-proposal',
};
await buildAndExecuteProposal(zoeUpgradeSpec);
await buildAndExecuteProposal('@agoric/builders/scripts/vats/upgrade-zoe.js');

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { makeHelpers } from '@agoric/deploy-script-support';
import { getManifestForUpgrade } from '@agoric/smart-wallet/src/proposals/upgrade-walletFactory-proposal.js';
import { getManifestForUpgrade } from '@agoric/vats/src/proposals/upgrade-wallet-factory-proposal.js';

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */
export const defaultProposalBuilder = async ({ publishRef, install }) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/inter-protocol/src/price/roundsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,10 @@ export const prepareRoundsManagerKit = baggage =>
);
}

if (status.lastReportedRound >= roundId)
if (status.lastReportedRound >= roundId) {
return 'cannot report on previous rounds';
}

if (
roundId !== reportingRoundId &&
roundId !== add(reportingRoundId, 1) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const acceptInvitation = async (wallet, priceAggregator) => {

let pushPriceCounter = 0;
/**
* @param {any} wallet
* @param {import('@agoric/smart-wallet/src/smartWallet.js').SmartWallet} wallet
* @param {string} adminOfferId
* @param {import('@agoric/inter-protocol/src/price/roundsManager.js').PriceRound} priceRound
* @returns {Promise<string>} offer id
Expand Down Expand Up @@ -329,6 +329,7 @@ test.serial('errors', async t => {
'In "pushPrice" method of (OracleKit oracle): arg 0: unitPrice: number 1 - Must be a bigint',
},
);

await eventLoopIteration();

// Success, round starts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ test('want stable (insufficient funds)', async t => {
'Withdrawal of {"brand":"[Alleged: AUSD brand]","value":"[20000n]"} failed because the purse only contained {"brand":"[Alleged: AUSD brand]","value":"[10000n]"}';
const status = computedState.offerStatuses.get('insufficientFunds');
t.is(status?.error, `Error: ${msg}`);
/** @type {[PromiseRejectedResult]} */
// @ts-expect-error cast
const result = status.result;
t.is(result[0].status, 'rejected');
t.is(result[0].reason.message, msg);
});

test('govern offerFilter', async t => {
Expand Down Expand Up @@ -384,6 +379,8 @@ test('deposit multiple payments to unknown brand', async t => {
}
});

// related to recovering dropped Payments

// XXX belongs in smart-wallet package, but needs lots of set-up that's handy here.
test('recover when some withdrawals succeed and others fail', async t => {
const { fromEntries } = Object;
Expand Down
Loading

0 comments on commit cbb2dae

Please sign in to comment.