Skip to content

Commit

Permalink
Merge pull request #8911 from Agoric/a3p-test-zcfBundleCap
Browse files Browse the repository at this point in the history
A3p test zcf bundle cap
  • Loading branch information
mergify[bot] authored Feb 28, 2024
2 parents 18d561f + 003ed74 commit 111247f
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 11 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = {
'./packages/*/tsconfig.json',
'./packages/*/tsconfig.json',
'./packages/wallet/*/tsconfig.json',
'./a3p-integration/proposals/*/tsconfig.json',
'./tsconfig.json',
],
tsconfigRootDir: __dirname,
Expand Down
11 changes: 6 additions & 5 deletions a3p-integration/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Dockerfile
docker-bake.*
upgrade-test-scripts
*submission/

# Yarn (https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored)
.pnp.*
Expand All @@ -14,8 +15,8 @@ upgrade-test-scripts
# same for each proposal, an independent project
proposals/*/.pnp.*
proposals/*/.yarn/*
proposals/*/!.yarn/patches
proposals/*/!.yarn/plugins
proposals/*/!.yarn/releases
proposals/*/!.yarn/sdks
proposals/*/!.yarn/versions
!proposals/*/.yarn/patches
!proposals/*/.yarn/plugins
!proposals/*/.yarn/releases
!proposals/*/.yarn/sdks
!proposals/*/.yarn/versions
1 change: 1 addition & 0 deletions a3p-integration/proposals/a:upgrade-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"ava": {
"concurrency": 1,
"serial": true,
"timeout": "1m",
"files": [
"!submission"
]
Expand Down
36 changes: 36 additions & 0 deletions a3p-integration/proposals/a:upgrade-next/probeZcfBundleCap.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import test from 'ava';

import {
evalBundles,
getIncarnation,
getVatDetails,
} from '@agoric/synthetic-chain';

const SUBMISSION_DIR = 'probe-submission';

test('upgrade Zoe to verify ZcfBundleCap endures', async t => {
await null;
t.assert((await getIncarnation('zoe')) === 1, 'zoe incarnation must be one');

// Before the test, the Wallet Factory should be using the legacy ZCF
const detailsBefore = await getVatDetails('walletFactory');
t.true(detailsBefore.incarnation >= 2, 'wf incarnation must be >= 2');

await evalBundles(SUBMISSION_DIR);

const detailsAfter = await getVatDetails('walletFactory');
t.is(
detailsAfter.incarnation,
detailsBefore.incarnation + 2,
'wf incarnation must increase by 2',
);

// The test restarts the WalletFactory, so it'll use the recently assigned
// ZCF bundle. It then restarts Zoe, so it'll revert to whichever ZCF bundle
// made it to persistent store. We then restart the Wallet Factory and see if
// it's gone back to the ZCF that Zoe initially knew about. If we could get the
// ZCF bundleID here from the probe, we'd explicitly check for that. Instead,
// we have to be content that it did indeed use the newly assigned bundle in
// manual tests.
t.not(detailsAfter.bundleID, detailsBefore.bundleID);
});
4 changes: 3 additions & 1 deletion a3p-integration/proposals/a:upgrade-next/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
# Place here any test that should be executed using the executed proposal.
# The effects of this step are not persisted in further proposal layers.

yarn ava
yarn ava post.test.js
GLOBIGNORE=post.test.js
yarn ava *.test.js
22 changes: 22 additions & 0 deletions packages/builders/scripts/vats/probe-zcf-bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { makeHelpers } from '@agoric/deploy-script-support';

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */
export const defaultProposalBuilder = async ({ publishRef, install }) =>
harden({
sourceSpec: '@agoric/vats/src/proposals/probeZcfBundle.js',
getManifestCall: [
'getManifestForProbeZcfBundleCap',
{
zoeRef: publishRef(install('@agoric/vats/src/vat-zoe.js')),
zcfRef: publishRef(install('@agoric/zoe/src/contractFacet/vatRoot.js')),
walletRef: publishRef(
install('@agoric/smart-wallet/src/walletFactory.js'),
),
},
],
});

export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('probeZcfBundle', defaultProposalBuilder);
};
72 changes: 72 additions & 0 deletions packages/vats/src/proposals/probeZcfBundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { E } from '@endo/far';
import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';

// verify that Zoe remembers the zcfBundleCap across upgrades
export const probeZcfBundleCap = async (
{
consume: {
vatAdminSvc,
walletFactoryStartResult,
provisionPoolStartResult,
chainStorage,
walletBridgeManager: walletBridgeManagerP,
vatStore,
},
},
options,
) => {
const { zoeRef, zcfRef, walletRef } = options.options;

const { adminNode, root: zoeRoot } = await E(vatStore).get('zoe');
const zoeConfigFacet = await E(zoeRoot).getZoeConfigFacet();

// STEP 1: restart WF; it'll use the newest ZCF known to Zoe ////////////////

const WALLET_STORAGE_PATH_SEGMENT = 'wallet';
const [walletBridgeManager, walletStorageNode, ppFacets] = await Promise.all([
walletBridgeManagerP,
makeStorageNodeChild(chainStorage, WALLET_STORAGE_PATH_SEGMENT),
provisionPoolStartResult,
]);
const walletReviver = await E(ppFacets.creatorFacet).getWalletReviver();
const privateArgs = {
storageNode: walletStorageNode,
walletBridgeManager,
walletReviver,
};

const { adminFacet: walletAdminFacet } = await walletFactoryStartResult;
await E(walletAdminFacet).upgradeContract(walletRef.bundleID, privateArgs);

// STEP 2: Set the ZCF bundle ////////////////////////
await E(zoeConfigFacet).updateZcfBundleId(zcfRef.bundleID);

// STEP 3: Upgrade Zoe again ////////////////////////
// ////// See if Zoe forgets ZcfBundleCap //////////

const zoeBundleCap = await E(vatAdminSvc).getBundleCap(zoeRef.bundleID);
await E(adminNode).upgrade(zoeBundleCap, {});

// STEP 4: restart WF ////////////////////////
await E(walletAdminFacet).restartContract(privateArgs);

// ////// See which zcf bundle was used //////////
};
harden(probeZcfBundleCap);

export const getManifestForProbeZcfBundleCap = (_powers, options) => ({
manifest: {
[probeZcfBundleCap.name]: {
consume: {
vatAdminSvc: true,
vatStore: true,
walletBridgeManager: true,
walletFactoryStartResult: true,
provisionPoolStartResult: true,
chainStorage: true,
},
},
},
options,
});
harden(getManifestForProbeZcfBundleCap);
8 changes: 6 additions & 2 deletions packages/zoe/src/contractFacet/zcfZygote.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,12 @@ export const makeZCFZygote = async (

await null;
if (!zcfBaggage.has('repairedContractCompletionWatcher')) {
await E(zoeInstanceAdmin).repairContractCompletionWatcher();
console.log(`Repaired contract completion watcher`);
// We don't wait because it's a cross-vat call (to Zoe) that can't be
// completed during this vat's start-up
E(zoeInstanceAdmin)
.repairContractCompletionWatcher()
.catch(() => {});

zcfBaggage.init('repairedContractCompletionWatcher', true);
}

Expand Down
1 change: 1 addition & 0 deletions packages/zoe/src/zoeService/startInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export const makeStartInstance = (
contractBundleCap: newContractBundleCap,
privateArgs: newPrivateArgs,
};
state.contractBundleCap = newContractBundleCap;
return E.when(getFreshZcfBundleCap(), bCap =>
E(state.adminNode).upgrade(bCap, { vatParameters }),
);
Expand Down
10 changes: 7 additions & 3 deletions scripts/generate-a3p-submission.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ cd "$sdkroot"
buildSubmission() {
proposalName=$1
a3pProposal=$2
output=${3:-$proposalName}
submissionName=${4:-submission}

yarn agoric run "packages/builders/scripts/vats/$proposalName.js"

submissionDir="a3p-integration/proposals/$a3pProposal/submission"

submissionDir="a3p-integration/proposals/$a3pProposal/$submissionName"
mkdir -p "$submissionDir"
cp $(grep -oh '/.*b1-.*.json' "$proposalName"*) "$submissionDir"
mv "$proposalName"* "$submissionDir"
cp $(grep -oh '/.*b1-.*.json' "$output"*) "$submissionDir"
mv "$output"* "$submissionDir"
}

buildSubmission probe-zcf-bundle "a:upgrade-next" probeZcfBundle probe-submission
buildSubmission test-localchain "b:localchain"

0 comments on commit 111247f

Please sign in to comment.