diff --git a/packages/zoe/src/zoeService/escrowStorage.js b/packages/zoe/src/zoeService/escrowStorage.js index 3f69ce46744..67b112245c8 100644 --- a/packages/zoe/src/zoeService/escrowStorage.js +++ b/packages/zoe/src/zoeService/escrowStorage.js @@ -2,9 +2,8 @@ import { AmountMath } from '@agoric/ertp'; import { E } from '@endo/eventual-send'; -import { makeWeakStore } from '@agoric/store'; import { assert, details as X, q } from '@agoric/assert'; -import { objectMap } from '@agoric/vat-data'; +import { objectMap, provideDurableWeakMapStore } from '@agoric/vat-data'; import './types.js'; import './internal-types.js'; @@ -15,10 +14,12 @@ import { arrayToObj } from '../objArrayConversion.js'; /** * Store the pool purses whose purpose is to escrow assets, with one * purse per brand. + * + * @param {import('@agoric/vat-data').Baggage} baggage */ -export const makeEscrowStorage = () => { +export const makeEscrowStorage = baggage => { /** @type {WeakStore>} */ - const brandToPurse = makeWeakStore('brand'); + const brandToPurse = provideDurableWeakMapStore(baggage, 'brandToPurse'); /** @type {CreatePurse} */ const createPurse = (issuer, brand) => { diff --git a/packages/zoe/src/zoeService/installationStorage.js b/packages/zoe/src/zoeService/installationStorage.js index ca45e740e9c..71edac7595b 100644 --- a/packages/zoe/src/zoeService/installationStorage.js +++ b/packages/zoe/src/zoeService/installationStorage.js @@ -2,11 +2,10 @@ import { assert, details as X } from '@agoric/assert'; import { E } from '@endo/eventual-send'; -import { makeWeakStore } from '@agoric/store'; import { - defineDurableKind, makeScalarBigMapStore, - provideKindHandle, + provideDurableWeakMapStore, + vivifyKind, } from '@agoric/vat-data'; /** @typedef { import('@agoric/swingset-vat').BundleID} BundleID */ @@ -21,28 +20,26 @@ export const makeInstallationStorage = ( zoeBaggage = makeScalarBigMapStore('zoe baggage', { durable: true }), ) => { /** @type {WeakStore} */ - const installationsBundleCap = makeWeakStore('installationsBundleCap'); - /** @type {WeakStore} */ - const installationsBundle = makeWeakStore('installationsBundle'); - - const bundleIDInstallationKindHandle = provideKindHandle( + const installationsBundleCap = provideDurableWeakMapStore( zoeBaggage, - 'BundleIDInstallation', + 'installationsBundleCap', ); - - const bundleInstallationKindHandle = provideKindHandle( + /** @type {WeakStore} */ + const installationsBundle = provideDurableWeakMapStore( zoeBaggage, - 'BundleInstallation', + 'installationsBundle', ); - const makeBundleIDInstallation = defineDurableKind( - bundleIDInstallationKindHandle, + const makeBundleIDInstallation = vivifyKind( + zoeBaggage, + 'BundleIDInstallation', () => ({}), { getBundle: _context => assert.fail('bundleID-based Installation') }, ); - const makeBundleInstallation = defineDurableKind( - bundleInstallationKindHandle, + const makeBundleInstallation = vivifyKind( + zoeBaggage, + 'BundleInstallation', bundle => ({ bundle }), { getBundle: ({ state: { bundle } }) => bundle }, ); @@ -68,7 +65,7 @@ export const makeInstallationStorage = ( /** @type {Installation} */ // @ts-expect-error cast const installation = makeBundleIDInstallation(); - installationsBundleCap.init(installation, { bundleCap, bundleID }); + installationsBundleCap.init(installation, harden({ bundleCap, bundleID })); return installation; }; diff --git a/packages/zoe/src/zoeService/makeInvitation.js b/packages/zoe/src/zoeService/makeInvitation.js index b109561709e..ecb2a77b336 100644 --- a/packages/zoe/src/zoeService/makeInvitation.js +++ b/packages/zoe/src/zoeService/makeInvitation.js @@ -1,13 +1,15 @@ // @ts-check import { assert, details as X } from '@agoric/assert'; -import { AmountMath, makeIssuerKit, AssetKind } from '@agoric/ertp'; +import { AmountMath, makeDurableIssuerKit, AssetKind } from '@agoric/ertp'; import { InvitationElementShape } from '../typeGuards.js'; /** + * @param {import('@agoric/vat-data').Baggage} baggage * @param {ShutdownWithFailure | undefined} shutdownZoeVat */ -export const createInvitationKit = (shutdownZoeVat = undefined) => { - const invitationKit = makeIssuerKit( +export const vivifyInvitationKit = (baggage, shutdownZoeVat = undefined) => { + const invitationKit = makeDurableIssuerKit( + baggage, 'Zoe Invitation', AssetKind.SET, undefined, diff --git a/packages/zoe/src/zoeService/zoeStorageManager.js b/packages/zoe/src/zoeService/zoeStorageManager.js index 48609d7ddeb..a7585e967b7 100644 --- a/packages/zoe/src/zoeService/zoeStorageManager.js +++ b/packages/zoe/src/zoeService/zoeStorageManager.js @@ -4,14 +4,14 @@ import { AssetKind, makeIssuerKit } from '@agoric/ertp'; import { Far } from '@endo/marshal'; import { makeScalarBigMapStore, - makeScalarBigWeakMapStore, + provideDurableWeakMapStore, } from '@agoric/vat-data'; import { provideIssuerStorage } from '../issuerStorage.js'; import { makeAndStoreInstanceRecord } from '../instanceRecordStorage.js'; import { makeIssuerRecord } from '../issuerRecord.js'; import { makeEscrowStorage } from './escrowStorage.js'; -import { createInvitationKit } from './makeInvitation.js'; +import { vivifyInvitationKit } from './makeInvitation.js'; import { makeInstanceAdminStorage } from './instanceAdminStorage.js'; import { makeInstallationStorage } from './installationStorage.js'; @@ -58,7 +58,7 @@ export const makeZoeStorageManager = ( // EscrowStorage holds the purses that Zoe uses for escrow. This // object should be closely held and tracked: all of the digital // assets that users escrow are contained within these purses. - const escrowStorage = makeEscrowStorage(); + const escrowStorage = makeEscrowStorage(zoeBaggage); // Add a purse for escrowing user funds (not for fees). Create the // local, non-remote escrow purse for the fee mint immediately. @@ -71,8 +71,10 @@ export const makeZoeStorageManager = ( // In order to participate in a contract, users must have // invitations, which are ERTP payments made by Zoe. This code // contains the mint capability for invitations. - const { setupMakeInvitation, invitationIssuer } = - createInvitationKit(shutdownZoeVat); + const { setupMakeInvitation, invitationIssuer } = vivifyInvitationKit( + zoeBaggage, + shutdownZoeVat, + ); // Every new instance of a contract creates a corresponding // "zoeInstanceAdmin" - an admin facet within the Zoe Service for @@ -99,7 +101,10 @@ export const makeZoeStorageManager = ( getBundleIDFromInstallation, } = makeInstallationStorage(getBundleCapForID, zoeBaggage); - const proposalSchemas = makeScalarBigWeakMapStore('proposal schemas'); + const proposalSchemas = provideDurableWeakMapStore( + zoeBaggage, + 'proposal schemas', + ); const getProposalSchemaForInvitation = invitationHandle => { if (proposalSchemas.has(invitationHandle)) { diff --git a/packages/zoe/test/unitTests/zoe/test-escrowStorage.js b/packages/zoe/test/unitTests/zoe/test-escrowStorage.js index 7b323c2b0b5..b88eed44792 100644 --- a/packages/zoe/test/unitTests/zoe/test-escrowStorage.js +++ b/packages/zoe/test/unitTests/zoe/test-escrowStorage.js @@ -5,6 +5,7 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import { AmountMath, makeIssuerKit, AssetKind } from '@agoric/ertp'; import { E } from '@endo/eventual-send'; +import { makeScalarBigMapStore } from '@agoric/vat-data'; import { makeEscrowStorage } from '../../../src/zoeService/escrowStorage.js'; import { assertAmountsEqual, @@ -13,7 +14,7 @@ import { test('makeEscrowStorage', async t => { const { createPurse, makeLocalPurse, withdrawPayments, depositPayments } = - makeEscrowStorage(); + makeEscrowStorage(makeScalarBigMapStore('zoe baggage', { durable: true })); const currencyKit = makeIssuerKit( 'currency', @@ -132,7 +133,9 @@ const setupPurses = async createPurse => { }; test('payments without matching give keywords', async t => { - const { createPurse, depositPayments } = makeEscrowStorage(); + const { createPurse, depositPayments } = makeEscrowStorage( + makeScalarBigMapStore('zoe baggage', { durable: true }), + ); const { ticketKit, currencyKit } = await setupPurses(createPurse); @@ -167,7 +170,9 @@ test('payments without matching give keywords', async t => { }); test(`give keywords without matching payments`, async t => { - const { createPurse, depositPayments } = makeEscrowStorage(); + const { createPurse, depositPayments } = makeEscrowStorage( + makeScalarBigMapStore('zoe baggage', { durable: true }), + ); const { ticketKit, currencyKit } = await setupPurses(createPurse); diff --git a/packages/zoe/test/unitTests/zoe/test-installationStorage.js b/packages/zoe/test/unitTests/zoe/test-installationStorage.js index c97ee392c6b..a9001b84bbb 100644 --- a/packages/zoe/test/unitTests/zoe/test-installationStorage.js +++ b/packages/zoe/test/unitTests/zoe/test-installationStorage.js @@ -13,7 +13,7 @@ test('install, unwrap installations', async t => { const installation = await installBundle(fakeBundle); const unwrapped = await unwrapInstallation(installation); t.is(unwrapped.installation, installation); - t.is(unwrapped.bundle, fakeBundle); + t.deepEqual(unwrapped.bundle, fakeBundle); }); test('install, unwrap installation of bundlecap', async t => { @@ -37,7 +37,7 @@ test('unwrap promise for installation', async t => { const installation = await installBundle(fakeBundle); const unwrapped = await unwrapInstallation(Promise.resolve(installation)); t.is(unwrapped.installation, installation); - t.is(unwrapped.bundle, fakeBundle); + t.deepEqual(unwrapped.bundle, fakeBundle); }); test('install several', async t => { @@ -48,12 +48,12 @@ test('install several', async t => { const installation1 = await installBundle(fakeBundle1); const unwrapped1 = await unwrapInstallation(installation1); t.is(unwrapped1.installation, installation1); - t.is(unwrapped1.bundle, fakeBundle1); + t.deepEqual(unwrapped1.bundle, fakeBundle1); const installation2 = await installBundle(fakeBundle2); const unwrapped2 = await unwrapInstallation(installation2); t.is(unwrapped2.installation, installation2); - t.is(unwrapped2.bundle, fakeBundle2); + t.deepEqual(unwrapped2.bundle, fakeBundle2); }); test('install same twice', async t => { @@ -66,7 +66,7 @@ test('install same twice', async t => { const installation1 = await installBundle(fakeBundle1); const unwrapped1 = await unwrapInstallation(installation1); t.is(unwrapped1.installation, installation1); - t.is(unwrapped1.bundle, fakeBundle1); + t.deepEqual(unwrapped1.bundle, fakeBundle1); // If the same bundle is installed twice, the bundle is the same, // but the installation is different. Zoe does not currently care about @@ -75,7 +75,7 @@ test('install same twice', async t => { const unwrapped2 = await unwrapInstallation(installation2); t.is(unwrapped2.installation, installation2); t.not(installation2, installation1); - t.is(unwrapped2.bundle, fakeBundle1); + t.deepEqual(unwrapped2.bundle, fakeBundle1); // same for bundleIDs const installation3 = await installBundleID('id'); diff --git a/packages/zoe/test/unitTests/zoe/test-makeInvitation.js b/packages/zoe/test/unitTests/zoe/test-makeInvitation.js index aa57f0cf397..388107e028e 100644 --- a/packages/zoe/test/unitTests/zoe/test-makeInvitation.js +++ b/packages/zoe/test/unitTests/zoe/test-makeInvitation.js @@ -5,14 +5,19 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; import { AmountMath } from '@agoric/ertp'; import { E } from '@endo/eventual-send'; import { Far } from '@endo/marshal'; -import { makeScalarBigWeakMapStore } from '@agoric/vat-data'; +import { + makeScalarBigWeakMapStore, + makeScalarBigMapStore, +} from '@agoric/vat-data'; -import { createInvitationKit } from '../../../src/zoeService/makeInvitation.js'; +import { vivifyInvitationKit } from '../../../src/zoeService/makeInvitation.js'; const proposalSchemas = makeScalarBigWeakMapStore('proposal schemas'); -test('createInvitationKit', async t => { - const { setupMakeInvitation, invitationIssuer } = createInvitationKit(); +test('vivifyInvitationKit', async t => { + const { setupMakeInvitation, invitationIssuer } = vivifyInvitationKit( + makeScalarBigMapStore('zoe baggage', { durable: true }), + ); const mockInstance = Far('mockInstance', {}); const mockInstallation = Far('mockInstallation', {}); @@ -58,7 +63,9 @@ test('createInvitationKit', async t => { }); test('description is omitted, wrongly', async t => { - const { setupMakeInvitation } = createInvitationKit(); + const { setupMakeInvitation } = vivifyInvitationKit( + makeScalarBigMapStore('zoe baggage', { durable: true }), + ); const mockInstance = Far('mockInstance', {}); const mockInstallation = Far('mockInstallation', {}); @@ -89,7 +96,9 @@ test('description is omitted, wrongly', async t => { }); test('customProperties ok to omit', async t => { - const { setupMakeInvitation, invitationIssuer } = createInvitationKit(); + const { setupMakeInvitation, invitationIssuer } = vivifyInvitationKit( + makeScalarBigMapStore('zoe baggage', { durable: true }), + ); const mockInstance = Far('mockInstance', {}); const mockInstallation = Far('mockInstallation', {});