Skip to content

Commit

Permalink
test: a docker test for the zoe/zcf upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Jul 17, 2023
1 parent cde1e35 commit ee9a305
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/deployment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@agoric/assert": "^0.6.0",
"@endo/init": "^0.5.56",
"@endo/marshal": "^0.8.5",
"better-sqlite3": "^8.4.0",
"chalk": "^5.2.0",
"deterministic-json": "^1.0.5",
"inquirer": "^8.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,54 @@
# CWD is agoric-sdk
here=./upgrade-test-scripts/agoric-upgrade-11

# run zoe thru "null upgrade"
$here/zoe-upgrade/zoe-upgrade-driver.sh
# Pre-steps:
# * fill Wallets
# * install bundles
# * create instance of prober contract and run expecting no atomicRearrange
#
# Action:
# * upgrade Zoe and ZCF
#
# Finish
# * create instance of prober contract and run expecting to see atomicRearrange

echo XXXX fill wallet XXXXXX
agd tx bank send validator $GOV1ADDR 12340000000${ATOM_DENOM} --from validator --chain-id agoriclocal --keyring-backend test --yes
agops vaults open --wantMinted 10000 --giveCollateral 2000 > wantIST
agops perf satisfaction --executeOffer wantIST --from gov1 --keyring-backend test


# This test needs bundles for Zoe, ZCF, and the prober to be installed in this
# directory, with names matching *bundle.json. The bundleIds for Zoe and ZCF
# must be updated in zcf-upgrade-script.js, while the prober's bundleId goes in
# run-prober.script. The bundles can be generated by running the test in
# vats/test/bootstrapTests/test-zcf-upgrade.js. The Zoe and ZCF bundle files are
# generated in ~/.agoric/cache, and their bundleIds are logged in the test. The
# prober bundle is generated by uncommenting `fs.writeFile(...)` in that test.
# !! THERE HAS TO BE A BETTER WAY !!


echo XXXX install bundles XXXXXX
for f in $here/zoe-full-upgrade/*bundle.json; do
echo installing $f
agd tx swingset install-bundle "@$f" \
--from gov1 --keyring-backend=test --gas=auto \
--chain-id=agoriclocal -bblock --yes
done


echo XXXX Run prober first time XXXXXX
$here/zoe-full-upgrade/run-prober.sh
test_val "$(agd query vstorage data published.prober-asid9a -o jsonlines | jq -r '.value' | jq -r '.values[0]')" "false" "Prober couldn't call zcf.atomicReallocate()"


# upgrade zoe to a version that can change which ZCF is installed; tell Zoe to
# use a new version of ZCF. THIS MATCHES THE UPGRADE OF THE LIVE CHAIN
echo XXXX upgrade Zoe and ZCF XXXXXX
$here/zoe-full-upgrade/zcf-upgrade-driver.sh


echo XXXX Run prober second time XXXXXX
# Re-run prober test and expect internal atomicRearrange.
$here/zoe-full-upgrade/run-prober.sh
test_val "$(agd query vstorage data published.prober-asid9a -o jsonlines | jq -r '.value' | jq -r '.values[0]')" "true" "Prober called zcf.atomicReallocate()"

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// to turn on ts-check:
/* global E */

// import { E } from "@endo/far";

const PROBER_BUNDLE_ID =
'b1-3af827f96f8623a5f271a995a7a5156892100066324d942a45a5e77699eee9984c74bacb6891fcc7f82c52d5496d81f046ff09fc45e0be58f4db889ea0243ae1';

console.info('zoe upgrade: evaluating script');

const sub = (a, v) => {
return { brand: a.brand, value: a.value - v };
};

const probeReallocation = async (value, payment, creatorFacet, zoe) => {
const stagingInv = await E(creatorFacet).makeProbeStagingInvitation();

const stagingSeat = await E(zoe).offer(
stagingInv,
{ give: { Ducats: value } },
{ Ducats: payment },
);
const helperPayments = await E(stagingSeat).getPayouts();

const helperInv = await E(creatorFacet).makeProbeHelperInvitation();
const helperSeat = await E(zoe).offer(
helperInv,
{ give: { Ducats: sub(value, 1n) } },
{ Ducats: helperPayments.Ducats },
);
const internalPayments = await E(helperSeat).getPayouts();

const internalInv = await E(creatorFacet).makeProbeInternalInvitation();
const internalSeat = await E(zoe).offer(
internalInv,
{ give: { Ducats: sub(value, 2n) } },
{ Ducats: internalPayments.Ducats },
);
const leftoverPayments = await E(internalSeat).getPayouts();

return {
stagingResult: await E(stagingSeat).getOfferResult(),
helperResult: await E(helperSeat).getOfferResult(),
internalResult: await E(internalSeat).getOfferResult(),
leftoverPayments,
};
};

/*
* Test a full upgrade of Zzoe and ZCF.
* This will include a change to Zoe's code, and a call to Zoe to change the ZCF
* code that will get used for new and upgraded contracts.
*/
const runProber = async powers => {
console.info('install prober');
const {
consume: { zoe, chainStorage },
} = powers;

const installation = await E(zoe).installBundleID(PROBER_BUNDLE_ID);
const storageNode = await E(chainStorage).makeChildNode('prober-asid9a');

const { instance, creatorFacet } = await E(zoe).startInstance(
installation,
undefined,
undefined,
{ storageNode },
'probe',
);

const issuers = await E(zoe).getIssuers(instance);

const faucetInv = await E(creatorFacet).makeFaucetInvitation();
const seat = await E(zoe).offer(faucetInv);
const payoutDucats = await E(seat).getPayout('Ducats');
const faucetAmount = await E(issuers.Ducats).getAmountOf(payoutDucats);

const result1 = await probeReallocation(
faucetAmount,
payoutDucats,
creatorFacet,
zoe,
);
console.info('PROBE results', result1);
};

runProber;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

. ./upgrade-test-scripts/env_setup.sh

set -euo pipefail

here='upgrade-test-scripts/agoric-upgrade-11/zoe-full-upgrade'

agd --chain-id=agoriclocal \
tx gov submit-proposal swingset-core-eval \
${here}/zcf-upgrade-permit.json ${here}/run-prober-script.js \
--title="Run Prober" --description="run prober" \
--deposit=10000000ubld \
--gas=auto --gas-adjustment=1.2 \
--yes -o json --from=validator --keyring-backend=test -b block

agd --chain-id=agoriclocal query gov proposals --output json | \
jq -c '.proposals[] | [.proposal_id,.voting_end_time,.status]';

voteLatestProposalAndWait
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

. ./upgrade-test-scripts/env_setup.sh

set -euo pipefail

# This shows how to upgrade Zoe and ZCF on a running chain. It presumes that
# The bundles for Zoe and ZCF have been installed, and their hashes updated in
# zcf-upgrade-script.js. The bundles can be generated by running the test in
# vats/test/bootstrapTests/test-zcf-upgrade.js, noting the logged ZOE BUNDLE ID
# and ZCF BUNDLE ID, and finding the corresponding bundles in ~/.agoric/cache.
# !! THERE HAS TO BE A BETTER WAY !!

here='upgrade-test-scripts/agoric-upgrade-11/zoe-full-upgrade'

agd --chain-id=agoriclocal \
tx gov submit-proposal swingset-core-eval \
${here}/zcf-upgrade-permit.json ${here}/zcf-upgrade-script.js \
--title="Zoe Upgrade" --description="zoe upgrade test" \
--deposit=10000000ubld \
--gas=auto --gas-adjustment=1.2 \
--yes -o json --from=validator --keyring-backend=test -b block

agd --chain-id=agoriclocal query gov proposals --output json | \
jq -c '.proposals[] | [.proposal_id,.voting_end_time,.status]';

voteLatestProposalAndWait
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// to turn on ts-check:
/* global E */

// import { E } from "@endo/far";

const ZCF_BUNDLE_ID =
'b1-8674abc9a8de561c4a33fb475b87be75708cd901c37931fd5ac1f40d3ee99937a459a6ca7b4a8b7907512626caf98c125f22c15384826e37dfc899dc0bf2a63a';
const ZOE_BUNDLE_ID =
'b1-68963663488ee6d178293b559b9d902cea1857dddac257f08540cb9748647d0218a991ce02cf9f61e1e49cca3979b20473103a7fee509cf808de43e323afab54';

console.info('zoe upgrade: evaluating script');

/*
* Test a full upgrade of Zzoe and ZCF.
* This will include a change to Zoe's code, and a call to Zoe to change the ZCF
* code that will get used for new and upgraded contracts.
*/
const upgradeZoeAndZcf = async powers => {
console.info('upgradeZoeAndZcf');
const {
consume: { vatStore, vatAdminSvc },
} = powers;

const newZoeBundleCap = await E(vatAdminSvc).getBundleCap(ZOE_BUNDLE_ID);
const { adminNode, root: zoeRoot } = await E(vatStore).get('zoe');

await E(adminNode).upgrade(newZoeBundleCap, {});

const zoeConfigFacet = await E(zoeRoot).getZoeConfigFacet();
await E(zoeConfigFacet).updateZcfBundleId(ZCF_BUNDLE_ID);
};

upgradeZoeAndZcf;

0 comments on commit ee9a305

Please sign in to comment.