Skip to content

Commit

Permalink
feat: smart wallet can upgrade to use promiseWatcher
Browse files Browse the repository at this point in the history
upgrade-wallet-factory-proposal upgrades to the new walletFactory in
agoric-3-proposals.
  • Loading branch information
Chris-Hibbert committed Nov 29, 2023
1 parent c378c3e commit 9c8ec51
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 149 deletions.
5 changes: 4 additions & 1 deletion packages/boot/test/bootstrapTests/test-vaults-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +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';

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/smart-wallet/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
47 changes: 28 additions & 19 deletions packages/inter-protocol/test/smartWallet/test-oracle-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,15 @@ test.serial('errors', async t => {
await eventLoopIteration();

// Invalid priceRound argument
await t.throwsAsync(
walletPushPrice({
roundId: 1,
unitPrice: 1,
}),
{
message:
'In "pushPrice" method of (OracleKit oracle): arg 0: unitPrice: number 1 - Must be a bigint',
},
);
const pushPriceNotBigint = await walletPushPrice({
roundId: 1,
unitPrice: 1,
});
t.like(pushPriceNotBigint, {
error:
'Error: In "pushPrice" method of (OracleKit oracle): arg 0: unitPrice: number 1 - Must be a bigint',
});

await eventLoopIteration();

// Success, round starts
Expand All @@ -345,15 +344,11 @@ test.serial('errors', async t => {
await eventLoopIteration();

// Invalid attempt to push again to the same round
await t.throwsAsync(
walletPushPrice({
roundId: 1,
unitPrice: 1n,
}),
{
message: 'cannot report on previous rounds',
},
);
const pushPriceAgain = await walletPushPrice({
roundId: 1,
unitPrice: 1n,
});
t.like(pushPriceAgain, { error: 'Error: cannot report on previous rounds' });
});

// test both addOracles and removeOracles in same test to reuse the lengthy EC setup
Expand Down Expand Up @@ -575,4 +570,18 @@ test.serial('govern oracles list', async t => {
}),
{ message: 'pushPrice for disabled oracle' },
);

// XXX It looks like the error is being thrown, but it's not getting back here

// const offerId = await pushPrice(oracleWallet, oracleOfferId, {
// roundId: 1,
// unitPrice: 123n,
// });
//
// const computedState2 = coalesceUpdates(E(wallet).getUpdatesSubscriber());
//
// const pushPriceDisabled = computedState2.offerStatuses.get(offerId);
// console.log(`PPD `, pushPriceDisabled);
//
// t.like(pushPriceDisabled, { error: 'pushPrice for disabled oracle' });
});
128 changes: 0 additions & 128 deletions packages/smart-wallet/src/proposals/upgrade-walletFactory-proposal.js

This file was deleted.

63 changes: 63 additions & 0 deletions packages/vats/src/proposals/upgrade-wallet-factory-proposal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { E } from '@endo/far';
import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';

/**
* @param {BootstrapPowers & {
* consume: {
* walletFactoryStartResult: WalletFactoryStartResult;
* provisionPoolStartResult: any; // startPSM has a TODO for this
* chainStorage: ChainStorage;
* walletBridgeManager: WalletBridgeManager;
* };
* }} powers
* @param {object} options
* @param {{ zoeRef: VatSourceRef; zcfRef: VatSourceRef }} options.options
*/
export const upgradeWalletFactory = async (
{
consume: {
walletFactoryStartResult,
provisionPoolStartResult,
chainStorage,
walletBridgeManager: walletBridgeManagerP,
},
},
options,
) => {
const WALLET_STORAGE_PATH_SEGMENT = 'wallet';

const { walletRef } = options.options;

const [walletBridgeManager, walletStorageNode, ppFacets] = await Promise.all([
walletBridgeManagerP,
makeStorageNodeChild(chainStorage, WALLET_STORAGE_PATH_SEGMENT),
provisionPoolStartResult,
]);

const privateArgs = {
storageNode: walletStorageNode,
walletBridgeManager,
walletReviver: E(ppFacets.creatorFacet).getWalletReviver(),
};

const { adminFacet } = await walletFactoryStartResult;

await E(adminFacet).upgradeContract(walletRef.bundleID, privateArgs);

// XXX this console.log doesn't print. Any added above will. Seems strange.
// console.log(`upgrade WF AFTER`);
};

export const getManifestForUpgradeWallet = (_powers, { walletRef }) => ({
manifest: {
[upgradeWalletFactory.name]: {
consume: {
walletFactoryStartResult: 'walletFactoryStartResult',
provisionPoolStartResult: 'provisionPoolStartResult',
chainStorage: 'chainStorage',
walletBridgeManager: 'walletBridgeManager',
},
},
},
options: { walletRef },
});

0 comments on commit 9c8ec51

Please sign in to comment.