-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AssetReserve to Upgrade 19 with A3P test coverage #10541
Changes from 14 commits
c267011
c0fd937
ebbfa73
3d92f6b
1672768
09c9747
f39d6f7
5c38c28
d6b63b0
59d2615
1b785b4
a9436f2
4bd67a3
262a901
391d6bf
f66de07
bd7fa60
f391365
b17f601
a62afad
6e125cf
95f6cf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ upgradeProvisionPool/ | |
upgradeAgoricNames/ | ||
publishTestInfo/ | ||
upgrade-mintHolder/ | ||
upgradeAssetReserve/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* eslint-env node */ | ||
/** | ||
* @file The goal of this file is to make sure v36-reserve upgraded. | ||
* | ||
* The test scenario is as follows; | ||
* 1. Add asset USD_LEMONS | ||
* 2. Add collateral to the reserve | ||
* 3. Upgrade reserve | ||
* 4. Ensure that the collateral is still in the reserve | ||
*/ | ||
|
||
import '@endo/init'; | ||
import test from 'ava'; | ||
import { | ||
evalBundles, | ||
agd as agdAmbient, | ||
agoric, | ||
getDetailsMatchingVats, | ||
} from '@agoric/synthetic-chain'; | ||
import { | ||
makeVstorageKit, | ||
waitUntilContractDeployed, | ||
} from '@agoric/client-utils'; | ||
|
||
const ADD_PSM_DIR = 'addUsdLemons'; | ||
const UPGRADE_AR_DIR = 'upgradeAssetReserve'; | ||
const ADD_COLLATERAL = 'addCollateral'; | ||
|
||
const ambientAuthority = { | ||
query: agdAmbient.query, | ||
follow: agoric.follow, | ||
setTimeout, | ||
log: console.log, | ||
}; | ||
|
||
/** | ||
* @typedef {import('@agoric/ertp').NatAmount} NatAmount | ||
* @typedef {{ | ||
* allocations: { Fee: NatAmount, USD_LEMONS: NatAmount }, | ||
* }} ReserveAllocations | ||
*/ | ||
|
||
test.before(async t => { | ||
const vstorageKit = await makeVstorageKit( | ||
{ fetch }, | ||
{ rpcAddrs: ['http://localhost:26657'], chainName: 'agoriclocal' }, | ||
); | ||
|
||
t.context = { | ||
vstorageKit, | ||
}; | ||
}); | ||
|
||
test.serial('add collatoral to reserve', async t => { | ||
// @ts-expect-error casting | ||
const { vstorageKit } = t.context; | ||
|
||
// Introduce USD_LEMONS | ||
await evalBundles(ADD_PSM_DIR); | ||
await waitUntilContractDeployed('psm-IST-USD_LEMONS', ambientAuthority, { | ||
errorMessage: 'psm-IST-USD_LEMONS instance not observed.', | ||
}); | ||
|
||
await evalBundles(ADD_COLLATERAL); | ||
|
||
const metrics = /** @type {ReserveAllocations} */ ( | ||
await vstorageKit.readLatestHead('published.reserve.metrics') | ||
); | ||
|
||
t.truthy(Object.keys(metrics.allocations).includes('USD_LEMONS')); | ||
t.is(metrics.allocations.USD_LEMONS.value, 500000n); | ||
}); | ||
|
||
test.serial('upgrade', async t => { | ||
// @ts-expect-error casting | ||
const { vstorageKit } = t.context; | ||
|
||
await evalBundles(UPGRADE_AR_DIR); | ||
|
||
const vatDetailsAfter = await getDetailsMatchingVats('reserve'); | ||
const { incarnation } = vatDetailsAfter.find(vat => vat.vatID === 'v36'); // assetReserve is v36 | ||
|
||
t.log(vatDetailsAfter); | ||
t.is(incarnation, 1, 'incorrect incarnation'); | ||
t.pass(); | ||
|
||
const metrics = /** @type {ReserveAllocations} */ ( | ||
await vstorageKit.readLatestHead('published.reserve.metrics') | ||
); | ||
|
||
t.truthy(Object.keys(metrics.allocations).includes('USD_LEMONS')); | ||
t.is(metrics.allocations.USD_LEMONS.value, 500000n); | ||
}); |
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-asset-reserve-proposal.js', | ||
getManifestCall: [ | ||
'getManifestForUpgradingAssetReserve', | ||
{ | ||
assetReserveRef: publishRef( | ||
install('@agoric/inter-protocol/src/reserve/assetReserve.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-asset-reserve', defaultProposalBuilder); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,22 +57,13 @@ export const start = async (zcf, privateArgs, baggage) => { | |
privateArgs.marshaller, | ||
); | ||
|
||
/** @type {() => Promise<ZCFMint<'nat'>>} */ | ||
const takeFeeMint = async () => { | ||
if (baggage.has('feeMint')) { | ||
return baggage.get('feeMint'); | ||
} | ||
|
||
const feeMintTemp = await zcf.registerFeeMint( | ||
'Fee', | ||
privateArgs.feeMintAccess, | ||
); | ||
baggage.init('feeMint', feeMintTemp); | ||
return feeMintTemp; | ||
}; | ||
trace('awaiting takeFeeMint'); | ||
const feeMint = await takeFeeMint(); | ||
const storageNode = await privateArgs.storageNode; | ||
|
||
trace('awaiting feeMint'); | ||
const { feeMint } = await provideAll(baggage, { | ||
feeMint: () => zcf.registerFeeMint('Fee', privateArgs.feeMintAccess), | ||
}); | ||
|
||
Comment on lines
+63
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const makeAssetReserveKit = await prepareAssetReserveKit(baggage, { | ||
feeMint, | ||
makeRecorderKit, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { E } from '@endo/far'; | ||
import { deeplyFulfilled } from '@endo/marshal'; | ||
import { makeTracer } from '@agoric/internal'; | ||
|
||
const tracer = makeTracer('UpgradeAssetReserve'); | ||
|
||
/** | ||
* @param {BootstrapPowers & { | ||
* consume: { | ||
* economicCommitteeCreatorFacet: any; | ||
* reserveKit: any; | ||
* }; | ||
* produce: { | ||
* reserveKit: any; | ||
* }; | ||
* }} powers | ||
* @param {object} options | ||
* @param {{ assetReserveRef: VatSourceRef }} options.options | ||
*/ | ||
export const upgradeAssetReserve = async ( | ||
{ | ||
consume: { | ||
economicCommitteeCreatorFacet: electorateCreatorFacet, | ||
reserveKit: reserveKitP, | ||
instancePrivateArgs: instancePrivateArgsP, | ||
}, | ||
produce: { reserveKit: reserveKitWriter }, | ||
}, | ||
options, | ||
) => { | ||
const { assetReserveRef } = options.options; | ||
|
||
assert(assetReserveRef.bundleID); | ||
tracer(`ASSET RESERVE BUNDLE ID: `, assetReserveRef); | ||
|
||
const [reserveKit, instancePrivateArgs] = await Promise.all([ | ||
reserveKitP, | ||
instancePrivateArgsP, | ||
]); | ||
const { governorCreatorFacet, instance } = reserveKit; | ||
|
||
const [originalPrivateArgs, poserInvitation] = await Promise.all([ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore Local tsc sees this as an error but typedoc does not | ||
deeplyFulfilled(instancePrivateArgs.get(instance)), | ||
E(electorateCreatorFacet).getPoserInvitation(), | ||
]); | ||
|
||
const newPrivateArgs = harden({ | ||
...originalPrivateArgs, | ||
initialPoserInvitation: poserInvitation, | ||
}); | ||
|
||
const adminFacet = await E(governorCreatorFacet).getAdminFacet(); | ||
|
||
// We need to reset the kit and produce a new adminFacet because the | ||
// original contract is producing an admin facet that is for the | ||
// governor, not the reserve. | ||
reserveKitWriter.reset(); | ||
reserveKitWriter.resolve( | ||
harden({ | ||
...reserveKit, | ||
adminFacet, | ||
}), | ||
); | ||
Comment on lines
+59
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As long as you're doing this, might as well clean up the original, (we want those proposals to be usable to start a new chain, or to copy, even if we won't run them again on mainNet) and add a comment here as to why this fix is necessary. |
||
|
||
const upgradeResult = await E(adminFacet).upgradeContract( | ||
assetReserveRef.bundleID, | ||
newPrivateArgs, | ||
); | ||
|
||
tracer('AssetReserve upgraded: ', upgradeResult); | ||
tracer('Done.'); | ||
}; | ||
|
||
export const getManifestForUpgradingAssetReserve = ( | ||
_powers, | ||
{ assetReserveRef }, | ||
) => ({ | ||
manifest: { | ||
[upgradeAssetReserve.name]: { | ||
consume: { | ||
economicCommitteeCreatorFacet: true, | ||
instancePrivateArgs: true, | ||
reserveKit: true, | ||
}, | ||
produce: { | ||
reserveKit: true, | ||
}, | ||
}, | ||
}, | ||
options: { assetReserveRef }, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.pass()
is only necessary when there are no tests. There are a fewt.is()
, and at.truthy()
, so this isn't helpful.