Skip to content

Commit

Permalink
chore: clean-ups from review
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Dec 15, 2023
1 parent ec4cbce commit 19bfad6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { makeHelpers } from '@agoric/deploy-script-support';

/**
* @file
* `agoric run scripts/vats/upgrade-wallet-factory2.js | tee run-report.txt`
* `agoric run scripts/smart-wallet/build-wallet-factory2-upgrade.js`
* produces a proposal and permit file, as well as the necessary bundles. It
* also prints helpful instructions for copying the files and installing them.
*/
Expand Down
1 change: 0 additions & 1 deletion packages/smart-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"dependencies": {
"@agoric/assert": "^0.6.0",
"@agoric/casting": "^0.4.2",
"@agoric/deploy-script-support": "^0.10.3",
"@agoric/ertp": "^0.16.2",
"@agoric/internal": "^0.3.2",
"@agoric/notifier": "^0.6.2",
Expand Down
37 changes: 22 additions & 15 deletions packages/smart-wallet/src/smartWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export const prepareSmartWallet = (baggage, shared) => {
purseForBrand: M.call(BrandShape).returns(M.promise()),
logWalletInfo: M.call(M.any()).returns(),
logWalletError: M.call(M.any()).returns(),
// XXX is there a better guard for a bigMapStore?
// XXX is there a tighter guard for a bigMapStore than M.any()?
getLiveOfferPayments: M.call().returns(M.any()),
}),

Expand Down Expand Up @@ -561,14 +561,16 @@ export const prepareSmartWallet = (baggage, shared) => {
return purse;
},

// see https://github.com/Agoric/agoric-sdk/issues/8445 and
// https://github.com/Agoric/agoric-sdk/issues/8286. As originally
// released, the smartWallet didn't durably monitor the promises for the
// outcomes of offers, and would have dropped them on upgrade of Zoe or
// the smartWallet itself. Using watchedPromises, (see offerWatcher.js)
// we've addressed the problem for new offers. The function will
// backfill the solution for offers that were outstanding before the
// transition to incarnation 2 of the smartWallet.
/**
* see https://github.com/Agoric/agoric-sdk/issues/8445 and
* https://github.com/Agoric/agoric-sdk/issues/8286. As originally
* released, the smartWallet didn't durably monitor the promises for the
* outcomes of offers, and would have dropped them on upgrade of Zoe or
* the smartWallet itself. Using watchedPromises, (see offerWatcher.js)
* we've addressed the problem for new offers. This function will
* backfill the solution for offers that were outstanding before the
* transition to incarnation 2 of the smartWallet.
*/
async repairUnwatchedSeats() {
const { state, facets } = this;
const { address, invitationPurse } = state;
Expand Down Expand Up @@ -1009,22 +1011,27 @@ export const prepareSmartWallet = (baggage, shared) => {
},
getPublicTopics() {
const { state } = this;
const { currentRecorderKit, updateRecorderKit } = state;

return harden({
current: {
description: 'Current state of wallet',
subscriber: state.currentRecorderKit.subscriber,
storagePath: state.currentRecorderKit.recorder.getStoragePath(),
subscriber: currentRecorderKit.subscriber,
storagePath: currentRecorderKit.recorder.getStoragePath(),
},
updates: {
description: 'Changes to wallet',
subscriber: state.updateRecorderKit.subscriber,
storagePath: state.updateRecorderKit.recorder.getStoragePath(),
subscriber: updateRecorderKit.subscriber,
storagePath: updateRecorderKit.recorder.getStoragePath(),
},
});
},
// one-time use function. Remove this and repairUnwatchedSeats once the
// repair has taken place.
/**
* one-time use function. Remove this and repairUnwatchedSeats once the
* repair has taken place.
*
* @param {object} key
*/
repairWalletForIncarnation2(key) {
const { facets } = this;

Expand Down
18 changes: 13 additions & 5 deletions packages/smart-wallet/src/walletFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* @file Wallet Factory
*
* Contract to make smart wallets.
*
* Note: The upgrade test uses a slightly modified copy of this file. When the
* interface changes here, that will also need to change.
*/

import { makeTracer, WalletName } from '@agoric/internal';
Expand Down Expand Up @@ -223,11 +226,13 @@ export const prepare = async (zcf, privateArgs, baggage) => {

const registry = makeAssetRegistry(assetPublisher);

// An object known only to walletFactory and smartWallets. The WalletFactory
// only has the self facet for the pre-existing wallets that must be repaired.
// Self is too accessible, so use of the repair function requires use of a
// secret that clients won't have. This can be removed once the upgrade has
// taken place.
/**
* An object known only to walletFactory and smartWallets. The WalletFactory
* only has the self facet for the pre-existing wallets that must be repaired.
* Self is too accessible, so use of the repair function requires use of a
* secret that clients won't have. This can be removed once the upgrade has
* taken place.
*/
const upgradeToIncarnation2Key = harden({});

const shared = harden({
Expand Down Expand Up @@ -255,6 +260,9 @@ export const prepare = async (zcf, privateArgs, baggage) => {
if (!baggage.has(UPGRADE_TO_INCARNATION_TWO)) {
trace('Wallet Factory upgrading to incarnation 2');

// This could take a while, depending on how many outstanding wallets exist.
// The current plan is that it will run exactly once, and inside an upgrade
// handler, between blocks.
for (const wallet of walletsByAddress.values()) {
wallet.repairWalletForIncarnation2(upgradeToIncarnation2Key);
}
Expand Down
21 changes: 9 additions & 12 deletions packages/smart-wallet/test/test-addAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { makeDefaultTestContext } from './contexts.js';
import { ActionType, headValue, makeMockTestSpace } from './supports.js';
import { makeImportContext } from '../src/marshal-contexts.js';

const { Fail, quote: q } = assert;
const { Fail } = assert;

const importSpec = spec =>
importMetaResolve(spec, import.meta.url).then(u => new URL(u).pathname);
Expand Down Expand Up @@ -420,10 +420,8 @@ test.serial('trading in non-vbank asset: game real-estate NFTs', async t => {

/** @type {import('../src/smartWallet.js').UpdateRecord} */
const update = await headValue(updates);
assert(
update.updated === 'offerStatus',
`Should have had "updated":"offerStatus", had "${q(update)}"`,
);
assert(update.updated === 'offerStatus');
// t.log(update.status);
t.like(update, {
updated: 'offerStatus',
status: {
Expand All @@ -437,7 +435,7 @@ test.serial('trading in non-vbank asset: game real-estate NFTs', async t => {
const {
status: { id, result, payouts },
} = update;
// @ts-expect-error status includes payload.
// @ts-expect-error cast value to copyBag
const names = payouts?.Places.value.payload.map(([name, _qty]) => name);
t.log(id, 'result:', result, ', payouts:', names.join(', '));

Expand Down Expand Up @@ -497,15 +495,13 @@ test.serial('non-vbank asset: give before deposit', async t => {
proposal: { give, want },
});
t.log('goofy client: propose to give', choices.join(', '));
await t.throwsAsync(
() => E(walletBridge).proposeOffer(ctx.fromBoard.toCapData(offer1)),
{ message: /Withdrawal of .* failed because the purse only contained/ },
);
await E(walletBridge).proposeOffer(ctx.fromBoard.toCapData(offer1));
};

{
const addr2 = 'agoric1player2';
const walletUIbridge = makePromiseKit();
// await eventLoopIteration();

const { simpleProvideWallet, consume, sendToBridge } = t.context;
const wallet = simpleProvideWallet(addr2);
Expand All @@ -515,8 +511,9 @@ test.serial('non-vbank asset: give before deposit', async t => {
const mockStorage = await consume.chainStorage;
const { aPlayer } = makeScenario(t);

await aPlayer(addr2, walletUIbridge, mockStorage, sendToBridge, updates);
await goofyClient(mockStorage, walletUIbridge.promise);
aPlayer(addr2, walletUIbridge, mockStorage, sendToBridge, updates);
const c2 = goofyClient(mockStorage, walletUIbridge.promise);
await t.throwsAsync(c2, { message: /Withdrawal of {.*} failed/ });
await eventLoopIteration();

// wallet balance was also updated
Expand Down
1 change: 1 addition & 0 deletions packages/vats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"license": "Apache-2.0",
"dependencies": {
"@agoric/assert": "^0.6.0",
"@agoric/deploy-script-support": "^0.10.3",
"@agoric/ertp": "^0.16.2",
"@agoric/governance": "^0.10.3",
"@agoric/internal": "^0.3.2",
Expand Down

0 comments on commit 19bfad6

Please sign in to comment.