Skip to content

Commit

Permalink
WIP: complete agoric11 and move to agoric12
Browse files Browse the repository at this point in the history
  • Loading branch information
iomekam committed Sep 1, 2023
1 parent bd5d3aa commit 3d611f7
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 159 deletions.
Original file line number Diff line number Diff line change
@@ -1,95 +1,3 @@
import { agd, agops, bundleSource } from "../cliHelper.mjs";
import { ATOM_DENOM, CHAINID, GOV1ADDR, SDK_ROOT, VALIDATORADDR } from "../constants.mjs";
import { promises as fs } from 'fs';
import { openVault, voteLatestProposalAndWait } from './upgradeHelpers.mjs'
import * as path from "path";
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import { $ } from 'execa';

const __dirname = dirname(fileURLToPath(import.meta.url));

export const installBundles = async (bundlesData) => {
const bundleIds = {};
await agd.tx("bank", "send", "validator", GOV1ADDR, `12340000000${ATOM_DENOM}`, "--from", VALIDATORADDR, "--chain-id", CHAINID, "--keyring-backend", "test", "--yes");
await openVault(GOV1ADDR, 10000, 2000);

for (const bundleData of bundlesData) {
const bundleFilePath = await bundleSource(bundleData.filePath, bundleData.name)

const bundleJSONData = await fs.readFile(
bundleFilePath,
'binary',
);

const bundle = JSON.parse(bundleJSONData);
bundleIds[bundleData.name] = bundle.endoZipBase64Sha512;

await agd.tx("swingset", "install-bundle", `@${bundleFilePath}`, "--from", GOV1ADDR, "--keyring-backend=test", "--gas=auto", "--chain-id", CHAINID, "-bblock", "--yes");
}

return bundleIds;
}

export const runProber = async (bundleId) => {
const proberScriptPath = path.join(__dirname, "zoe-full-upgrade", "run-prober-script.js");
const proberUpgradePermitPath = path.join(__dirname, "zoe-full-upgrade", "zcf-upgrade-permit.json");
const filePath = await prepForCoreEval(proberScriptPath, { PROBER_BUNDLE_ID: `b1-${bundleId}` })
await agd.tx(
"gov",
"submit-proposal",
"swingset-core-eval",
proberUpgradePermitPath,
filePath,
`--title="Run Prober"`,
`--description="run prober"`,
"--deposit=10000000ubld",
"--from",
VALIDATORADDR,
"--keyring-backend=test",
"--gas=auto",
"--gas-adjustment=1.2",
"--chain-id",
CHAINID,
"-bblock",
"--yes");

return voteLatestProposalAndWait();
}

export const runZcfUpgrade = async (zcfBundleId, zoeBundleId) => {
const zcfScriptPath = path.join(__dirname, "zoe-full-upgrade", "zcf-upgrade-script.js");
const zcfUpgradePermitPath = path.join(__dirname, "zoe-full-upgrade", "zcf-upgrade-permit.json");
const filePath = await prepForCoreEval(zcfScriptPath, { ZCF_BUNDLE_ID: `b1-${zcfBundleId}`, ZOE_BUNDLE_ID: `b1-${zoeBundleId}` })
await agd.tx(
"gov",
"submit-proposal",
"swingset-core-eval",
zcfUpgradePermitPath,
filePath,
`--title="Run Prober"`,
`--description="run prober"`,
"--deposit=10000000ubld",
"--from",
VALIDATORADDR,
"--keyring-backend=test",
"--gas=auto",
"--gas-adjustment=1.2",
"--chain-id",
CHAINID,
"-bblock",
"--yes");

return voteLatestProposalAndWait();
}

export const prepForCoreEval = async (filePath, constants) => {
let sourceFileData = await fs.readFile(filePath, 'binary');

for (const constant in constants) {
sourceFileData = sourceFileData.replace(`##${constant}##`, constants[constant]);
}

const newFilePath = `/tmp/${path.basename(filePath)}`;
await fs.writeFile(newFilePath, sourceFileData);
return newFilePath;
}
await $({ inherit: false })`agd start --log_level warn`
Original file line number Diff line number Diff line change
@@ -1,64 +1,23 @@
import test from 'ava';

import { adjustVault, closeVault, getUser, openVault } from './upgradeHelpers.mjs';
import { agd, agoric, agops, bundleSource } from '../cliHelper.mjs';
import { GOV1ADDR, SDK_ROOT } from '../constants.mjs';
import { installBundles, runZcfUpgrade, runProber } from './actions.mjs';

test.before(async t => {
const bundlesData = [
{
name: "Zcf-upgrade",
filePath: `${SDK_ROOT}/packages/zoe/src/contractFacet/vatRoot.js`
},
{
name: "Zoe-upgrade",
filePath: `${SDK_ROOT}/packages/vats/src/vat-zoe.js`
},
{
name: "prober-contract",
filePath: `${SDK_ROOT}/packages/boot/test/bootstrapTests/zcfProbe.js`
},
]

t.context.bundleIds = await installBundles(bundlesData);
});
import { adjustVault, closeVault, openVault } from './upgradeHelpers.mjs';
import { agoric, agops } from '../cliHelper.mjs';
import { GOV1ADDR } from '../constants.mjs';

test.serial('Open Vaults', async t => {
const currentVaults = await agops.vaults('list', '--from', GOV1ADDR);
t.is(currentVaults.length, 3);
t.is(currentVaults.length, 2);

await openVault(GOV1ADDR, 7, 11);
await adjustVault(GOV1ADDR, 'vault4', { giveMinted: 1.5 });
await adjustVault(GOV1ADDR, 'vault4', { giveCollateral: 2.0 });
await closeVault(GOV1ADDR, 'vault4', 5.75);
await adjustVault(GOV1ADDR, 'vault3', { giveMinted: 1.5 });
await adjustVault(GOV1ADDR, 'vault3', { giveCollateral: 2.0 });
await closeVault(GOV1ADDR, 'vault3', 5.75);

const vault4 = await agoric.follow(
const vault3 = await agoric.follow(
'-lF',
':published.vaultFactory.managers.manager0.vaults.vault4',
':published.vaultFactory.managers.manager0.vaults.vault3',
);
t.is(vault4.vaultState, 'closed');
t.is(vault4.locked.value, '0');
t.is(vault4.debtSnapshot.debt.value, '0');
});

test.serial("Run Prober (first time)", async t => {
await runProber(t.context.bundleIds["prober-contract"])
const data = await agd.query("vstorage", "data", "published.prober-asid9a");
const value = JSON.parse(data.value);
t.is(value.values[0], "false");
});

test.serial("Upgrade Zoe and ZCF", async t => {
await runZcfUpgrade(t.context.bundleIds["Zcf-upgrade"], t.context.bundleIds["Zoe-upgrade"])

t.pass()
});

test.serial("Run Prober (second time)", async t => {
await runProber(t.context.bundleIds["prober-contract"])

const data = await agd.query("vstorage", "data", "published.prober-asid9a");
const value = JSON.parse(data.value);
t.is(value.values[0], "true");
t.is(vault3.vaultState, 'closed');
t.is(vault3.locked.value, '0');
t.is(vault3.debtSnapshot.debt.value, '0');
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,76 @@
# Enable debugging
set -x

export_genesis() {
GENESIS_EXPORT_DIR="$1"
shift
GENESIS_HEIGHT_ARG=

if [ -n "$1" ]; then
GENESIS_HEIGHT_ARG="--height $1"
shift
fi

agd export --export-dir "$GENESIS_EXPORT_DIR" $GENESIS_HEIGHT_ARG "$@"
}

make_swing_store_snapshot() {( set -euo pipefail
EXPORT_DIR="$1"
shift
/usr/src/agoric-sdk/packages/cosmic-swingset/src/export-kernel-db.js --home "$HOME/.agoric" --export-dir "$EXPORT_DIR" --verbose --artifact-mode replay --export-data-mode all "$@"

EXPORT_MANIFEST_FILE="$EXPORT_DIR/export-manifest.json"
EXPORT_HEIGHT=$(cat "$EXPORT_MANIFEST_FILE" | jq -r .blockHeight)

[ "x${WITHOUT_GENESIS_EXPORT:-0}" = "x1" ] || {
EXPORT_DATA_FILE="$EXPORT_DIR/$(cat "$EXPORT_MANIFEST_FILE" | jq -r .data)"
EXPORT_DATA_UNTRUSTED_FILE="${EXPORT_DATA_FILE%.*}-untrusted.jsonl"
EXPORT_MANIFEST="$(cat $EXPORT_MANIFEST_FILE)"

mv "$EXPORT_DATA_FILE" "$EXPORT_DATA_UNTRUSTED_FILE"
export_genesis "$EXPORT_DIR/genesis-export" $EXPORT_HEIGHT
cat $EXPORT_DIR/genesis-export/genesis.json | jq -cr '.app_state.swingset.swing_store_export_data[] | [.key,.value]' > "$EXPORT_DATA_FILE"

jq -n "$EXPORT_MANIFEST | .untrustedData=\"$(basename -- "$EXPORT_DATA_UNTRUSTED_FILE")\"" > "$EXPORT_MANIFEST_FILE"
}

echo "Successful swing-store export for block $EXPORT_HEIGHT"
)}

restore_swing_store_snapshot() {( set -euo pipefail
rm -f $HOME/.agoric/data/agoric/swingstore.sqlite
EXPORT_DIR="$1"
shift

/usr/src/agoric-sdk/packages/cosmic-swingset/src/import-kernel-db.js --home "$HOME/.agoric" --export-dir "$EXPORT_DIR" --verbose --artifact-mode replay --export-data-mode all "$@"
)}

compare_swing_store_export_data() {
EXPORT_DIR="$1"
EXPORT_MANIFEST_FILE="$EXPORT_DIR/export-manifest.json"
EXPORT_DATA_FILE="$(cat "$EXPORT_MANIFEST_FILE" | jq -r .data)"
EXPORT_DATA_UNTRUSTED_FILE="$(cat "$EXPORT_MANIFEST_FILE" | jq -r .untrustedData)"

if [ -z "$EXPORT_DATA_FILE" ]; then
echo "missing-export-data"
return
fi

if [ -z "$EXPORT_DATA_UNTRUSTED_FILE" ]; then
echo "missing-untrusted-export-data"
return
fi

sort $EXPORT_DIR/$EXPORT_DATA_FILE > "${EXPORT_DIR}/sorted_${EXPORT_DATA_FILE}"
sort $EXPORT_DIR/$EXPORT_DATA_UNTRUSTED_FILE > "${EXPORT_DIR}/sorted_${EXPORT_DATA_UNTRUSTED_FILE}"

diff "${EXPORT_DIR}/sorted_${EXPORT_DATA_FILE}" "${EXPORT_DIR}/sorted_${EXPORT_DATA_UNTRUSTED_FILE}" >&2 && {
echo "match"
} || {
echo "mismatch"
}
}

# hacky restore of pruned artifacts
killAgd
EXPORT_DIR=$(mktemp -t -d swing-store-export-upgrade-11-XXX)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import test from 'ava';
import { main } from './vat-status.mjs';

test(`Verify Zoe vat incarnatin`, async t => {
const incarantion = await main("zoe");
t.is(incarantion, 1)
test(`Replace me`, async t => {
t.pass()
});
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import test from 'ava';

import { waitForBlock } from './upgradeHelpers.mjs';
import { agd, agoric, agops } from '../cliHelper.mjs';
import { main } from './vat-status.mjs';
import { agd, agoric } from '../cliHelper.mjs';

test.before(async () => {
console.log('Wait for upgrade to settle');

await waitForBlock(5);
});

test(`Ensure Zoe Vat is at 0`, async t => {
const incarnation = await main("zoe")
t.is(incarnation, 0)
});

test('Validate vaults', async t => {
const vaults = await agd.query(
'vstorage',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { agd, agops, bundleSource } from "../cliHelper.mjs";
import { ATOM_DENOM, CHAINID, GOV1ADDR, SDK_ROOT, VALIDATORADDR } from "../constants.mjs";
import { promises as fs } from 'fs';
import { openVault, voteLatestProposalAndWait } from '../coreUpgradeHelpers.mjs'
import * as path from "path";
import { dirname } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));

export const installBundles = async (bundlesData) => {
const bundleIds = {};
await agd.tx("bank", "send", "validator", GOV1ADDR, `12340000000${ATOM_DENOM}`, "--from", VALIDATORADDR, "--chain-id", CHAINID, "--keyring-backend", "test", "--yes");
await openVault(GOV1ADDR, 10000, 2000);

for (const bundleData of bundlesData) {
const bundleFilePath = await bundleSource(bundleData.filePath, bundleData.name)

const bundleJSONData = await fs.readFile(
bundleFilePath,
'binary',
);

const bundle = JSON.parse(bundleJSONData);
bundleIds[bundleData.name] = bundle.endoZipBase64Sha512;

await agd.tx("swingset", "install-bundle", `@${bundleFilePath}`, "--from", GOV1ADDR, "--keyring-backend=test", "--gas=auto", "--chain-id", CHAINID, "-bblock", "--yes");
}

return bundleIds;
}

export const runProber = async (bundleId) => {
const proberScriptPath = path.join(__dirname, "zoe-full-upgrade", "run-prober-script.js");
const proberUpgradePermitPath = path.join(__dirname, "zoe-full-upgrade", "zcf-upgrade-permit.json");
const filePath = await prepForCoreEval(proberScriptPath, { PROBER_BUNDLE_ID: `b1-${bundleId}` })
await agd.tx(
"gov",
"submit-proposal",
"swingset-core-eval",
proberUpgradePermitPath,
filePath,
`--title="Run Prober"`,
`--description="run prober"`,
"--deposit=10000000ubld",
"--from",
VALIDATORADDR,
"--keyring-backend=test",
"--gas=auto",
"--gas-adjustment=1.2",
"--chain-id",
CHAINID,
"-bblock",
"--yes");

return voteLatestProposalAndWait();
}

export const runZcfUpgrade = async (zcfBundleId, zoeBundleId) => {
const zcfScriptPath = path.join(__dirname, "zoe-full-upgrade", "zcf-upgrade-script.js");
const zcfUpgradePermitPath = path.join(__dirname, "zoe-full-upgrade", "zcf-upgrade-permit.json");
const filePath = await prepForCoreEval(zcfScriptPath, { ZCF_BUNDLE_ID: `b1-${zcfBundleId}`, ZOE_BUNDLE_ID: `b1-${zoeBundleId}` })
await agd.tx(
"gov",
"submit-proposal",
"swingset-core-eval",
zcfUpgradePermitPath,
filePath,
`--title="Run Prober"`,
`--description="run prober"`,
"--deposit=10000000ubld",
"--from",
VALIDATORADDR,
"--keyring-backend=test",
"--gas=auto",
"--gas-adjustment=1.2",
"--chain-id",
CHAINID,
"-bblock",
"--yes");

return voteLatestProposalAndWait();
}

export const prepForCoreEval = async (filePath, constants) => {
let sourceFileData = await fs.readFile(filePath, 'binary');

for (const constant in constants) {
sourceFileData = sourceFileData.replace(`##${constant}##`, constants[constant]);
}

const newFilePath = `/tmp/${path.basename(filePath)}`;
await fs.writeFile(newFilePath, sourceFileData);
return newFilePath;
}
Loading

0 comments on commit 3d611f7

Please sign in to comment.