diff --git a/packages/inter-protocol/test/smartWallet/boot-psm.js b/packages/inter-protocol/test/smartWallet/boot-psm.js index c50966ed4a9..ba8898cb351 100644 --- a/packages/inter-protocol/test/smartWallet/boot-psm.js +++ b/packages/inter-protocol/test/smartWallet/boot-psm.js @@ -24,7 +24,6 @@ import { makeChainStorage, noProvisioner, produceHighPrioritySendersManager, - publishAgoricNames, startTimerService, } from '@agoric/vats/src/core/chain-behaviors.js'; import { makePromiseSpace } from '@agoric/vats/src/core/promise-space.js'; @@ -35,6 +34,8 @@ import { import * as utils from '@agoric/vats/src/core/utils.js'; import { makeHeapZone } from '@agoric/zone'; import { Stable, Stake } from '@agoric/internal/src/tokens.js'; +import { makeScalarBigMapStore } from '@agoric/vat-data'; +import { prepareRecorderKit } from '@agoric/zoe/src/contractSupport/recorder.js'; import { ECON_COMMITTEE_MANIFEST, startEconomicCommittee, @@ -177,6 +178,49 @@ export const ParametersShape = M.splitRecord( }, ); +/** + * @deprecated use publishAgoricNamesToChainStorage + * @param {BootstrapPowers} powers + * @param {{ + * options?: { + * agoricNamesOptions?: { + * topLevel?: string[]; + * }; + * }; + * }} config + */ +export const legacyPublishAgoricNames = async ( + { consume: { agoricNamesAdmin, board, chainStorage: rootP } }, + { options: { agoricNamesOptions } = {} } = {}, +) => { + const root = await rootP; + assert(root, 'legacyPublishAgoricNames requires chainStorage'); + const nameStorage = E(root).makeChildNode('agoricNames'); + const marshaller = E(board).getPublishingMarshaller(); + + // XXX will fail upon restart, but so would the makeStoredPublishKit this is replacing + // Since we expect the bootstrap vat to be replaced instead of upgraded this should be + // fine. See {@link ./README.md bootstrap documentation} for details. + const fakeBaggage = makeScalarBigMapStore( + 'fake baggage for AgoricNames kinds', + ); + const makeRecorderKit = prepareRecorderKit(fakeBaggage, marshaller); + + // brand, issuer, ... + const { topLevel = Object.keys(agoricNamesReserved) } = + agoricNamesOptions || {}; + await Promise.all( + topLevel.map(async kind => { + const kindAdmin = await E(agoricNamesAdmin).lookupAdmin(kind); + + const kindNode = await E(nameStorage).makeChildNode(kind); + const { recorder } = makeRecorderKit(kindNode); + kindAdmin.onUpdate(recorder); + return recorder.write([]); + }), + ); +}; + /** * Build root object of the PSM-only bootstrap vat. * @@ -267,7 +311,7 @@ export const buildRootObject = async (vatPowers, vatParameters) => { bridgeProvisioner(powersFor('bridgeProvisioner')), makeChainStorage(powersFor('makeChainStorage')), makeAddressNameHubs(allPowers), - publishAgoricNames(allPowers, { + legacyPublishAgoricNames(allPowers, { options: { agoricNamesOptions: { topLevel: Object.keys(agoricNamesReserved) }, }, diff --git a/packages/orchestration/src/proposals/orchestration-proposal.js b/packages/orchestration/src/proposals/orchestration-proposal.js index 46846cd17f6..bc4de72e88a 100644 --- a/packages/orchestration/src/proposals/orchestration-proposal.js +++ b/packages/orchestration/src/proposals/orchestration-proposal.js @@ -79,10 +79,7 @@ const publishChainInfoToChainStorage = async ( chainStorageP, ) => { const chainStorage = await chainStorageP; - if (!chainStorage) { - console.warn('no chain storage, not registering chain info'); - return; - } + assert(chainStorage, 'publishChainInfoToChainStorage requires chainStorage'); const agoricNamesNode = await E(chainStorage).makeChildNode('agoricNames'); diff --git a/packages/vats/src/core/chain-behaviors.js b/packages/vats/src/core/chain-behaviors.js index d40e0e48fd5..a6ccdcb0042 100644 --- a/packages/vats/src/core/chain-behaviors.js +++ b/packages/vats/src/core/chain-behaviors.js @@ -7,12 +7,11 @@ import { makeSubscriptionKit, observeIteration, } from '@agoric/notifier'; -import { makeScalarBigMapStore } from '@agoric/vat-data'; -import { prepareRecorderKit } from '@agoric/zoe/src/contractSupport/recorder.js'; import * as farExports from '@endo/far'; import { E, Far } from '@endo/far'; import { importBundle } from '@endo/import-bundle'; import { makePromiseKit } from '@endo/promise-kit'; +import { makeMockChainStorageRoot } from '@agoric/internal/src/storage-test-utils.js'; import { PowerFlags } from '../walletFlags.js'; import { BASIC_BOOTSTRAP_PERMITS } from './basic-behaviors.js'; import { agoricNamesReserved, callProperties, extractPowers } from './utils.js'; @@ -357,8 +356,8 @@ export const makeChainStorage = async ({ }) => { const bridgeManager = await bridgeManagerP; if (!bridgeManager) { - console.warn('Cannot support chainStorage without an actual chain.'); - chainStorageP.resolve(null); + console.warn('no bridge so chainStorage will not write.'); + chainStorageP.resolve(makeMockChainStorageRoot()); // @ts-expect-error expects value or undefined storageBridgeManagerP.resolve(null); return; @@ -428,10 +427,8 @@ export const publishAgoricNamesToChainStorage = async ({ }, }) => { const root = await rootP; - if (!root) { - console.warn('no chainStorage: not publishing agoricNames'); - return; - } + assert(root, 'publishAgoricNamesToChainStorage requires chainStorage'); + const nameStorage = E(root).makeChildNode('agoricNames'); await E(agoricNames).publishNameHubs( nameStorage, @@ -440,51 +437,6 @@ export const publishAgoricNamesToChainStorage = async ({ ); }; -/** - * @deprecated use publishAgoricNamesToChainStorage - * @param {BootstrapPowers} powers - * @param {{ - * options?: { - * agoricNamesOptions?: { - * topLevel?: string[]; - * }; - * }; - * }} config - */ -export const publishAgoricNames = async ( - { consume: { agoricNamesAdmin, board, chainStorage: rootP } }, - { options: { agoricNamesOptions } = {} } = {}, -) => { - const root = await rootP; - if (!root) { - console.warn('cannot publish agoricNames without chainStorage'); - return; - } - const nameStorage = E(root).makeChildNode('agoricNames'); - const marshaller = E(board).getPublishingMarshaller(); - - // XXX will fail upon restart, but so would the makeStoredPublishKit this is replacing - // Since we expect the bootstrap vat to be replaced instead of upgraded this should be - // fine. See {@link ./README.md bootstrap documentation} for details. - const fakeBaggage = makeScalarBigMapStore( - 'fake baggage for AgoricNames kinds', - ); - const makeRecorderKit = prepareRecorderKit(fakeBaggage, marshaller); - - // brand, issuer, ... - const { topLevel = keys(agoricNamesReserved) } = agoricNamesOptions || {}; - await Promise.all( - topLevel.map(async kind => { - const kindAdmin = await E(agoricNamesAdmin).lookupAdmin(kind); - - const kindNode = await E(nameStorage).makeChildNode(kind); - const { recorder } = makeRecorderKit(kindNode); - kindAdmin.onUpdate(recorder); - return recorder.write([]); - }), - ); -}; - /** * no free lunch on chain * diff --git a/packages/vats/src/proposals/localchain-test.js b/packages/vats/src/proposals/localchain-test.js index 7cdb756a656..d1c6b2d95ef 100644 --- a/packages/vats/src/proposals/localchain-test.js +++ b/packages/vats/src/proposals/localchain-test.js @@ -18,10 +18,7 @@ export const testLocalChain = async ( console.warn('=== localchain test started (result in', testResultPath, ')!'); /** @type {null | ERef} */ let node = await chainStorage; - if (!node) { - console.error('testLocalChain no chainStorage'); - throw new Error('no chainStorage'); - } + assert(node, 'testLocalChain requires chainStorage'); let result; try { diff --git a/packages/vats/test/name-hub-published.test.js b/packages/vats/test/name-hub-published.test.js index f33ba8cc1d6..180650dc234 100644 --- a/packages/vats/test/name-hub-published.test.js +++ b/packages/vats/test/name-hub-published.test.js @@ -1,51 +1,12 @@ import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js'; -import { makeMockChainStorageRoot } from '@agoric/internal/src/storage-test-utils.js'; -import { makeHandle } from '@agoric/zoe/src/makeHandle.js'; -import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js'; -import { - makeAgoricNamesAccess, - makePromiseSpaceForNameHub, -} from '../src/core/utils.js'; -import { makePromiseSpace } from '../src/core/promise-space.js'; -import { - publishAgoricNames, - setupClientManager, -} from '../src/core/chain-behaviors.js'; -import { makeFakeBoard } from '../tools/board-utils.js'; -import { makeAddressNameHubs } from '../src/core/basic-behaviors.js'; +import { makePromiseSpaceForNameHub } from '../src/core/utils.js'; import { makeNameHubKit } from '../src/nameHub.js'; -test('publishAgoricNames publishes AMM instance', async t => { - const space = makePromiseSpace(); - const storageRoot = makeMockChainStorageRoot(); - const { agoricNames, agoricNamesAdmin } = await makeAgoricNamesAccess(); - const board = makeFakeBoard(); - const marshaller = board.getPublishingMarshaller(); - space.produce.agoricNames.resolve(agoricNames); - space.produce.agoricNamesAdmin.resolve(agoricNamesAdmin); - space.produce.chainStorage.resolve(storageRoot); - space.produce.board.resolve(board); - - await Promise.all([ - setupClientManager(/** @type {any} */ (space)), - makeAddressNameHubs(/** @type {any} */ (space)), - publishAgoricNames(/** @type {any} */ (space)), - ]); - const ammInstance = makeHandle('instance'); - const instanceAdmin = await agoricNamesAdmin.lookupAdmin('instance'); - instanceAdmin.update('amm', ammInstance); - - await eventLoopIteration(); // wait for publication to settle - - t.deepEqual( - storageRoot.getBody( - 'mockChainStorageRoot.agoricNames.instance', - marshaller, - ), - [['amm', ammInstance]], - ); -}); +// This suite used to also test publishAgoricNames but that code wasn't used +// anywhere so the test was removed. Its replacement, +// publishAgoricNamesToChainStorage, requires more more context so it's tested +// through integration instead of as a unit test. test('promise space reserves non-well-known names', async t => { const { nameHub, nameAdmin } = makeNameHubKit();