From 84875d42bd807f7ddfb6ff830c471ae8945a6171 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 10 Jun 2024 14:12:49 -0700 Subject: [PATCH] chore: remove unused publishAgoricNames --- .../test/smartWallet/boot-psm.js | 48 +++++++++++++++++- packages/vats/src/core/chain-behaviors.js | 44 ----------------- packages/vats/test/name-hub-published.test.js | 49 ++----------------- 3 files changed, 51 insertions(+), 90 deletions(-) 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/vats/src/core/chain-behaviors.js b/packages/vats/src/core/chain-behaviors.js index 3c7f85f02fa..8877c1fb98b 100644 --- a/packages/vats/src/core/chain-behaviors.js +++ b/packages/vats/src/core/chain-behaviors.js @@ -7,8 +7,6 @@ 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'; @@ -438,48 +436,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; - assert(root, 'publishAgoricNames 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 = 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/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();