Skip to content

Commit

Permalink
chore(vat-upgrade): improve code quality, switch using t.like
Browse files Browse the repository at this point in the history
Refs: #10408
  • Loading branch information
anilhelvaci committed Dec 4, 2024
1 parent 0cbed4b commit 0ec42bd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 44 deletions.
68 changes: 37 additions & 31 deletions a3p-integration/proposals/p:upgrade-19/agoricNames.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env node */

/**
* @file
* @file
* Ideas:
* - write something new to agoricNames and check vstorage
* - can you add a new chain for orc?
Expand All @@ -17,10 +17,7 @@ import {
agoric,
getDetailsMatchingVats,
} from '@agoric/synthetic-chain';
import {
makeVstorageKit,
makeAgoricNames,
} from '@agoric/client-utils';
import { makeVstorageKit } from '@agoric/client-utils';

const AGORIC_NAMES_UPGRADE_DIR = 'upgradeAgoricNames';
const WRITE_AGORIC_NAMES = 'writeToAgoricNames';
Expand All @@ -43,7 +40,7 @@ test.before(async t => {
};
});

test.serial('upgrade agoricNames', async t => {
test.serial.only('upgrade agoricNames', async t => {
await evalBundles(AGORIC_NAMES_UPGRADE_DIR);

const vatDetailsAfter = await getDetailsMatchingVats('agoricNames');
Expand All @@ -57,40 +54,49 @@ test.serial('upgrade agoricNames', async t => {
});

test.serial.only('check all existing values are preserved', async t => {
// @ts-expect-error
// @ts-expect-error
const { vstorageKit } = t.context;

const getAgoricNames = () => Promise.all([
vstorageKit.readLatestHead('published.agoricNames.issuer').then(issuer => Object.fromEntries(issuer)),
vstorageKit.readLatestHead('published.agoricNames.installation').then(installation => Object.fromEntries(installation)),
vstorageKit.readLatestHead('published.agoricNames.oracleBrand').then(oracleBrand => Object.fromEntries(oracleBrand)),
vstorageKit.readLatestHead('published.agoricNames.brand').then(brand => Object.fromEntries(brand)),
vstorageKit.readLatestHead('published.agoricNames.instance').then(instance => Object.fromEntries(instance)),
vstorageKit.readLatestHead('published.agoricNames.vbankAsset').then(vbankAsset => Object.fromEntries(vbankAsset)),
]).then(([issuer, installation, oracleBrand, brand, instance, vbankAsset]) => ({ issuer, installation, oracleBrand, brand, instance, vbankAsset }));
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);
await evalBundles(WRITE_AGORIC_NAMES);

const agoricNamesAfter = await getAgoricNames();
t.deepEqual(agoricNamesAfter, {
issuer: { ...agoricNamesBefore.issuer, testIssuer: 'testIssuer'},
installation: { ...agoricNamesBefore.installation, testInstallation: 'testInstallation'},
oracleBrand: { ...agoricNamesBefore.oracleBrand, testOracleBrand: 'testOracleBrand'},
brand: { ...agoricNamesBefore.brand, testBrand: 'testBrand'},
instance: { ...agoricNamesBefore.instance, testInstance: 'testInstance'},
vbankAsset: { ...agoricNamesBefore.vbankAsset, testAsset: 'testAsset'},
});
t.like(agoricNamesAfter, agoricNamesBefore);

t.pass();
agoricNamesChildren.forEach(child =>

Check warning on line 86 in a3p-integration/proposals/p:upgrade-19/agoricNames.test.js

View workflow job for this annotation

GitHub Actions / lint-rest

Prefer for...of instead of Array.forEach
assert(
agoricNamesAfter[child][`test${child}`],
'we should be able to add new value',
),
);
});

test.serial.skip('check we can add new chains', async t => {

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 => {

});
test.serial.skip(
'check contracts depend on agoricNames are not broken',
async t => {},
);
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
// @ts-nocheck
/* eslint-disable no-undef */
const writeToAgoricNames = async powers => {
const {
consume: {
agoricNamesAdmin,
}
consume: { agoricNamesAdmin },
} = powers;

console.log('writing to agoricNames...');
await Promise.all([
E(E(agoricNamesAdmin).lookupAdmin('issuer')).update('testIssuer', 'testIssuer'),
E(E(agoricNamesAdmin).lookupAdmin('brand')).update('testBrand', 'testBrand'),
E(E(agoricNamesAdmin).lookupAdmin('installation')).update('testInstallation', 'testInstallation'),
E(E(agoricNamesAdmin).lookupAdmin('vbankAsset')).update('testAsset', 'testAsset'),
E(E(agoricNamesAdmin).lookupAdmin('instance')).update('testInstance', 'testInstance'),
E(E(agoricNamesAdmin).lookupAdmin('oracleBrand')).update('testOracleBrand', 'testOracleBrand'),
]);
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;
writeToAgoricNames;
4 changes: 3 additions & 1 deletion packages/builders/scripts/vats/upgrade-agoricNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export const defaultProposalBuilder = async ({ publishRef, install }) =>
getManifestCall: [
'getManifestForUpgradingAgoricNames',
{
agoricNamesRef: publishRef(install('@agoric/vats/src/vat-agoricNames.js')),
agoricNamesRef: publishRef(
install('@agoric/vats/src/vat-agoricNames.js'),
),
},
],
});
Expand Down

0 comments on commit 0ec42bd

Please sign in to comment.