diff --git a/a3p-integration/proposals/p:upgrade-19/.gitignore b/a3p-integration/proposals/p:upgrade-19/.gitignore index 80f57c98cb2..59e3519121b 100644 --- a/a3p-integration/proposals/p:upgrade-19/.gitignore +++ b/a3p-integration/proposals/p:upgrade-19/.gitignore @@ -2,3 +2,5 @@ replaceFeeDistributor/ testUpgradedBoard/ addUsdLemons/ upgradeProvisionPool/ +upgradeAgoricNames/ + diff --git a/a3p-integration/proposals/p:upgrade-19/agoricNames.test.js b/a3p-integration/proposals/p:upgrade-19/agoricNames.test.js new file mode 100644 index 00000000000..d15a8c3beaa --- /dev/null +++ b/a3p-integration/proposals/p:upgrade-19/agoricNames.test.js @@ -0,0 +1,102 @@ +/* eslint-env node */ + +/** + * @file + * Ideas: + * - write something new to agoricNames and check vstorage + * - can you add a new chain for orc? + * - can you add a new psm? + * - can you open a vault? + */ + +import '@endo/init'; +import test from 'ava'; +import { + evalBundles, + agd as agdAmbient, + agoric, + getDetailsMatchingVats, +} from '@agoric/synthetic-chain'; +import { makeVstorageKit } from '@agoric/client-utils'; + +const AGORIC_NAMES_UPGRADE_DIR = 'upgradeAgoricNames'; +const WRITE_AGORIC_NAMES = 'writeToAgoricNames'; + +const ambientAuthority = { + query: agdAmbient.query, + follow: agoric.follow, + setTimeout, + log: console.log, +}; + +test.before(async t => { + const vstorageKit = await makeVstorageKit( + { fetch }, + { rpcAddrs: ['http://localhost:26657'], chainName: 'agoriclocal' }, + ); + + t.context = { + vstorageKit, + }; +}); + +test.serial.only('upgrade agoricNames', async t => { + await evalBundles(AGORIC_NAMES_UPGRADE_DIR); + + const vatDetailsAfter = await getDetailsMatchingVats('agoricNames'); + const { incarnation } = vatDetailsAfter.find(vat => + vat.vatName.endsWith('agoricNames'), + ); + + t.log(vatDetailsAfter); + t.is(incarnation, 1, 'incorrect incarnation'); + t.pass(); +}); + +test.serial.only('check all existing values are preserved', async t => { + // @ts-expect-error + const { vstorageKit } = t.context; + const agoricNamesChildren = [ + 'brand', + 'installation', + 'instance', + 'issuer', + 'oracleBrand', + 'vbankAsset', + ]; + + const getAgoricNames = () => + Promise.all( + agoricNamesChildren.map(async child => { + const content = await vstorageKit.readLatestHead( + `published.agoricNames.${child}`, + ); + return [child, Object.fromEntries(content)]; + }), + ).then(rawAgoricNames => Object.fromEntries(rawAgoricNames)); + + const agoricNamesBefore = await getAgoricNames(); + console.log('AGORIC_NAMES_BEFORE', agoricNamesBefore); + + await evalBundles(WRITE_AGORIC_NAMES); + + const agoricNamesAfter = await getAgoricNames(); + t.like(agoricNamesAfter, agoricNamesBefore); + + agoricNamesChildren.forEach(child => + assert( + agoricNamesAfter[child][`test${child}`], + 'we should be able to add new value', + ), + ); +}); + +test.serial.only('check we can add new chains', async t => { + await evalBundles('chainInfoTest'); + t.pass(); +}); + +test.serial.skip( + 'check contracts depend on agoricNames are not broken', + async t => {}, +); diff --git a/a3p-integration/proposals/p:upgrade-19/package.json b/a3p-integration/proposals/p:upgrade-19/package.json index 6848af6d060..5b120f2b804 100644 --- a/a3p-integration/proposals/p:upgrade-19/package.json +++ b/a3p-integration/proposals/p:upgrade-19/package.json @@ -7,7 +7,8 @@ "vats/upgrade-provisionPool.js upgradeProvisionPool", "vats/upgrade-paRegistry.js", "vats/upgrade-board.js", - "testing/test-upgraded-board.js testUpgradedBoard" + "testing/test-upgraded-board.js testUpgradedBoard", + "vats/upgrade-agoricNames.js upgradeAgoricNames" ] }, "type": "module", diff --git a/a3p-integration/proposals/p:upgrade-19/writeToAgoricNames/write-to-agoricNames-permit.json b/a3p-integration/proposals/p:upgrade-19/writeToAgoricNames/write-to-agoricNames-permit.json new file mode 100644 index 00000000000..0099d415358 --- /dev/null +++ b/a3p-integration/proposals/p:upgrade-19/writeToAgoricNames/write-to-agoricNames-permit.json @@ -0,0 +1,5 @@ +{ + "consume": { + "agoricNamesAdmin": true + } +} \ No newline at end of file diff --git a/a3p-integration/proposals/p:upgrade-19/writeToAgoricNames/write-to-agoricNames.js b/a3p-integration/proposals/p:upgrade-19/writeToAgoricNames/write-to-agoricNames.js new file mode 100644 index 00000000000..89b37f95cca --- /dev/null +++ b/a3p-integration/proposals/p:upgrade-19/writeToAgoricNames/write-to-agoricNames.js @@ -0,0 +1,30 @@ +// @ts-nocheck +/* eslint-disable no-undef */ +const writeToAgoricNames = async powers => { + const { + consume: { agoricNamesAdmin }, + } = powers; + + console.log('writing to agoricNames...'); + const agoricNamesChildren = [ + 'brand', + 'installation', + 'instance', + 'issuer', + 'oracleBrand', + 'vbankAsset', + ]; + + await Promise.all( + agoricNamesChildren.map(async (child, index) => + E(E(agoricNamesAdmin).lookupAdmin(child)).update( + `test${child}`, + Far(`test${child}`, { getBoardId: () => `board${index}` }), + ), + ), + ); + + console.log('DONE'); +}; + +writeToAgoricNames; diff --git a/a3p-integration/proposals/z:acceptance/yarn.lock b/a3p-integration/proposals/z:acceptance/yarn.lock index c4f420e2cde..5b018e852c7 100644 --- a/a3p-integration/proposals/z:acceptance/yarn.lock +++ b/a3p-integration/proposals/z:acceptance/yarn.lock @@ -156,7 +156,6 @@ __metadata: "@agoric/vat-data": "npm:^0.5.2" "@agoric/vats": "npm:^0.15.1" "@agoric/zoe": "npm:^0.26.2" - "@agoric/zone": "npm:^0.2.2" "@endo/captp": "npm:^4.4.3" "@endo/errors": "npm:^1.2.8" "@endo/eventual-send": "npm:^1.2.8" diff --git a/packages/builders/scripts/vats/upgrade-agoricNames.js b/packages/builders/scripts/vats/upgrade-agoricNames.js new file mode 100644 index 00000000000..80716903a06 --- /dev/null +++ b/packages/builders/scripts/vats/upgrade-agoricNames.js @@ -0,0 +1,21 @@ +import { makeHelpers } from '@agoric/deploy-script-support'; + +/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder} */ +export const defaultProposalBuilder = async ({ publishRef, install }) => + harden({ + sourceSpec: '@agoric/vats/src/proposals/upgrade-agoricNames-proposal.js', + getManifestCall: [ + 'getManifestForUpgradingAgoricNames', + { + agoricNamesRef: publishRef( + install('@agoric/vats/src/vat-agoricNames.js'), + ), + }, + ], + }); + +/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */ +export default async (homeP, endowments) => { + const { writeCoreProposal } = await makeHelpers(homeP, endowments); + await writeCoreProposal('upgrade-agoricNames', defaultProposalBuilder); +}; diff --git a/packages/vats/src/proposals/upgrade-agoricNames-proposal.js b/packages/vats/src/proposals/upgrade-agoricNames-proposal.js new file mode 100644 index 00000000000..ea169eb640d --- /dev/null +++ b/packages/vats/src/proposals/upgrade-agoricNames-proposal.js @@ -0,0 +1,42 @@ +import { E } from '@endo/far'; + +/** + * @param {BootstrapPowers & { + * consume: { + * vatAdminSvc: VatAdminSvc; + * vatStore: MapStore< + * string, + * import('@agoric/swingset-vat').CreateVatResults + * >; + * }; + * }} powers + * @param {object} options + * @param {{ agoricNamesRef: VatSourceRef }} options.options + */ +export const upgradeAgoricNames = async ( + { consume: { vatAdminSvc, vatStore } }, + options, +) => { + const { agoricNamesRef } = options.options; + + assert(agoricNamesRef.bundleID); + const agoricNamesBundleCap = await E(vatAdminSvc).getBundleCap(agoricNamesRef.bundleID); + console.log(`BANK BUNDLE ID: `, agoricNamesRef.bundleID); + + const { adminNode } = await E(vatStore).get('agoricNames'); + + await E(adminNode).upgrade(agoricNamesBundleCap, {}); +}; + +export const getManifestForUpgradingAgoricNames = (_powers, { agoricNamesRef }) => ({ + manifest: { + [upgradeAgoricNames.name]: { + consume: { + vatAdminSvc: 'vatAdminSvc', + vatStore: 'vatStore', + }, + produce: {}, + }, + }, + options: { agoricNamesRef }, + });