-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(vat-upgrade): upgrade agoricNames, test old values are preserved
- Loading branch information
1 parent
e596a01
commit 5d7c678
Showing
8 changed files
with
204 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ replaceFeeDistributor/ | |
testUpgradedBoard/ | ||
addUsdLemons/ | ||
upgradeProvisionPool/ | ||
upgradeAgoricNames/ | ||
|
102 changes: 102 additions & 0 deletions
102
a3p-integration/proposals/p:upgrade-19/agoricNames.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => {}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
a3p-integration/proposals/p:upgrade-19/writeToAgoricNames/write-to-agoricNames-permit.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"consume": { | ||
"agoricNamesAdmin": true | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
a3p-integration/proposals/p:upgrade-19/writeToAgoricNames/write-to-agoricNames.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
42
packages/vats/src/proposals/upgrade-agoricNames-proposal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
}); |