From 6ac762379e2660353a23202acd2d6fb52ed13682 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Wed, 31 Jan 2024 16:50:36 -0800 Subject: [PATCH 1/2] feat: repair KREAd contract on zoe upgrade --- golang/cosmos/app/app.go | 2 ++ packages/vats/scripts/revive-kread.js | 13 ++++++++++ packages/vats/src/proposals/kread-proposal.js | 24 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 packages/vats/scripts/revive-kread.js create mode 100644 packages/vats/src/proposals/kread-proposal.js diff --git a/golang/cosmos/app/app.go b/golang/cosmos/app/app.go index 94b27c80ace..8bb38103444 100644 --- a/golang/cosmos/app/app.go +++ b/golang/cosmos/app/app.go @@ -849,6 +849,8 @@ func upgrade14Handler(app *GaiaApp, targetUpgrade string) func(sdk.Context, upgr vm.CoreProposalStepForModules("@agoric/vats/scripts/build-wallet-factory2-upgrade.js"), // Then, upgrade Zoe and ZCF vm.CoreProposalStepForModules("@agoric/vats/scripts/replace-zoe.js"), + // Next revive KREAd characters + vm.CoreProposalStepForModules("@agoric/vats/scripts/revive-kread.js"), } app.upgradeDetails = &upgradeDetails{ diff --git a/packages/vats/scripts/revive-kread.js b/packages/vats/scripts/revive-kread.js new file mode 100644 index 00000000000..57caed8f1fd --- /dev/null +++ b/packages/vats/scripts/revive-kread.js @@ -0,0 +1,13 @@ +import { makeHelpers } from '@agoric/deploy-script-support'; + +/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */ +export const defaultProposalBuilder = async () => + harden({ + sourceSpec: '@agoric/vats/src/proposals/kread-proposal.js', + getManifestCall: ['getManifestForKread'], + }); + +export default async (homeP, endowments) => { + const { writeCoreProposal } = await makeHelpers(homeP, endowments); + await writeCoreProposal('revive-kread', defaultProposalBuilder); +}; diff --git a/packages/vats/src/proposals/kread-proposal.js b/packages/vats/src/proposals/kread-proposal.js new file mode 100644 index 00000000000..f24556967a0 --- /dev/null +++ b/packages/vats/src/proposals/kread-proposal.js @@ -0,0 +1,24 @@ +import { E } from '@endo/far'; + +/** + * @param {BootstrapPowers & { + * consume: { kreadKit: KreadKit }; + * }} powers + */ +export const repairKread = async ({ consume: { kreadKit: kreadKitP } }) => { + console.log('repairSubscribers'); + + const kreadKit = await kreadKitP; + const creatorFacet = kreadKit.creatorFacet; + console.log(`KREAd creatorFacet`, creatorFacet); + await E(creatorFacet).reviveMarketExitSubscribers(); + console.log('KREAd subscribers were revived!'); +}; + +export const getManifestForKread = _powers => ({ + manifest: { + [repairKread.name]: { + consume: { kreadKit: true }, + }, + }, +}); From cb20dc9687e09958311102b0f103b0f5f12bcf42 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Mon, 5 Feb 2024 12:11:34 -0800 Subject: [PATCH 2/2] test: validate KREAd character purchase --- .../a:upgrade-14/create-kread-item-test.sh | 20 +++++ .../generate-kread-item-request.mjs | 76 +++++++++++++++++++ .../proposals/a:upgrade-14/test.sh | 2 + 3 files changed, 98 insertions(+) create mode 100755 a3p-integration/proposals/a:upgrade-14/create-kread-item-test.sh create mode 100644 a3p-integration/proposals/a:upgrade-14/generate-kread-item-request.mjs diff --git a/a3p-integration/proposals/a:upgrade-14/create-kread-item-test.sh b/a3p-integration/proposals/a:upgrade-14/create-kread-item-test.sh new file mode 100755 index 00000000000..0fdae98f792 --- /dev/null +++ b/a3p-integration/proposals/a:upgrade-14/create-kread-item-test.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -euo pipefail + +source /usr/src/upgrade-test-scripts/env_setup.sh + +OFFER=$(mktemp -t agops.XXX) +agops vaults open --wantMinted 6.00 --giveCollateral 9.0 >|"$OFFER" +agoric wallet send --offer "$OFFER" --from gov1 --keyring-backend="test" + + +govamount="200000000ubld" +provisionSmartWallet $GOV1ADDR $govamount + +KREAD_ITEM_OFFER=$(mktemp -t kreadItem.XXX) +node ./generate-kread-item-request.mjs > $KREAD_ITEM_OFFER +agops perf satisfaction --from $GOV1ADDR --executeOffer $KREAD_ITEM_OFFER --keyring-backend=test + +agd query vstorage data published.wallet.$GOV1ADDR.current -o json >& gov1.out +name=`jq '.value | fromjson | .values[2] | fromjson | .body[1:] | fromjson | .purses[1].balance.value.payload[0][0].name ' gov1.out` +test_val $name \"ephemeral_Ace\" "found KREAd character" diff --git a/a3p-integration/proposals/a:upgrade-14/generate-kread-item-request.mjs b/a3p-integration/proposals/a:upgrade-14/generate-kread-item-request.mjs new file mode 100644 index 00000000000..be9e07d6dde --- /dev/null +++ b/a3p-integration/proposals/a:upgrade-14/generate-kread-item-request.mjs @@ -0,0 +1,76 @@ +/* global process */ +import assert from 'assert'; +import { execFile } from 'child_process'; + +const ISTunit = 1_000_000n; // aka displayInfo: { decimalPlaces: 6 } + +const id = `KREAd-test-${Date.now()}`; + +// poor-man's zx +const $ = cmd => { + const [file, ...args] = cmd.split(' '); + + return new Promise((resolve, reject) => { + execFile(file, args, { encoding: 'utf8' }, (err, out) => { + if (err) return reject(err); + resolve(out); + }); + }); +}; + +const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]); + +const fromSmallCapsEntries = txt => { + const { body, slots } = JSON.parse(txt); + const theEntries = zip(JSON.parse(body.slice(1)), slots).map( + ([[name, ref], boardID]) => { + const iface = ref.replace(/^\$\d+\./, ''); + return [name, { iface, boardID }]; + }, + ); + return Object.fromEntries(theEntries); +}; + +const brand = fromSmallCapsEntries( + await $('agoric follow -lF :published.agoricNames.brand -o text'), +); +assert(brand.IST); + +const slots = []; // XXX global mutable state + +const smallCaps = { + Nat: n => `+${n}`, + // XXX mutates obj + ref: obj => { + if (obj.ix) return obj.ix; + const ix = slots.length; + slots.push(obj.boardID); + obj.ix = `$${ix}.Alleged: ${obj.iface}`; + return obj.ix; + }, +}; + +const body = { + method: 'executeOffer', + offer: { + id, + invitationSpec: { + source: 'agoricContract', + instancePath: ['kread'], + callPipe: [['makeMintCharacterInvitation', []]], + }, + offerArgs: { name: 'ephemeral_Ace' }, + proposal: { + give: { + Price: { + brand: smallCaps.ref(brand.IST), + value: smallCaps.Nat(5n * ISTunit) } + }, + }, + }, +}; + +const capData = { body: `#${JSON.stringify(body)}`, slots }; +const action = JSON.stringify(capData); + +console.log(action); diff --git a/a3p-integration/proposals/a:upgrade-14/test.sh b/a3p-integration/proposals/a:upgrade-14/test.sh index dd653d58e64..e5ffbbe5f9c 100755 --- a/a3p-integration/proposals/a:upgrade-14/test.sh +++ b/a3p-integration/proposals/a:upgrade-14/test.sh @@ -4,3 +4,5 @@ # The effects of this step are not persisted in further proposal layers. yarn ava + +./create-kread-item-test.sh