Skip to content

Commit

Permalink
chore(vat-upgrade): upgrade agoricNames, test old values are preserved
Browse files Browse the repository at this point in the history
Refs: #10408

chore(vat-upgrade): improve code quality, switch using t.like

Refs: #10408
  • Loading branch information
anilhelvaci committed Dec 6, 2024
1 parent 3653dc7 commit 326faee
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 2 deletions.
2 changes: 2 additions & 0 deletions a3p-integration/proposals/p:upgrade-19/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ replaceFeeDistributor/
testUpgradedBoard/
addUsdLemons/
upgradeProvisionPool/
upgradeAgoricNames/

102 changes: 102 additions & 0 deletions a3p-integration/proposals/p:upgrade-19/agoricNames.test.js
Original file line number Diff line number Diff line change
@@ -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 => {},
);
3 changes: 2 additions & 1 deletion a3p-integration/proposals/p:upgrade-19/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"consume": {
"agoricNamesAdmin": true
}
}
Original file line number Diff line number Diff line change
@@ -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;
1 change: 0 additions & 1 deletion a3p-integration/proposals/z:acceptance/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions packages/builders/scripts/vats/upgrade-agoricNames.js
Original file line number Diff line number Diff line change
@@ -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);
};
42 changes: 42 additions & 0 deletions packages/vats/src/proposals/upgrade-agoricNames-proposal.js
Original file line number Diff line number Diff line change
@@ -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 },
});

0 comments on commit 326faee

Please sign in to comment.