Skip to content

Commit

Permalink
test(agoric-cli): upgrade-contract works
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed May 11, 2023
1 parent 0d36087 commit 0a90faf
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 23 deletions.
1 change: 1 addition & 0 deletions packages/agoric-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@agoric/swingset-vat": "^0.30.2",
"@agoric/vats": "^0.13.0",
"@agoric/zoe": "^0.25.3",
"@agoric/zone": "^0.1.0",
"@confio/relayer": "^0.9.0",
"@cosmjs/crypto": "^0.30.1",
"@cosmjs/encoding": "^0.30.1",
Expand Down
32 changes: 27 additions & 5 deletions packages/agoric-cli/test/upgrade-contract/buggy-contract.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import { Far } from '@endo/far';
import { AmountMath } from '@agoric/ertp';
// eslint-disable-next-line import/no-extraneous-dependencies
import { makeDurableZone } from '@agoric/zone/durable.js';

/**
* @param {ZCF} zcf
* @param {*} _privateArgs
* @param {MapStore<any, any>} baggage
*/
export const start = async (zcf, _privateArgs, baggage) => {
baggage.init('myMint', zcf.makeMint('GoodStuff'));
const zone = makeDurableZone(baggage);

const zcfMint = await zcf.makeZCFMint('GoodStuff');
const { brand } = zcfMint.getIssuerRecord();
baggage.init('myMint', zcfMint);

/** @type {OfferHandler} */
const offerHandler = seat => {
const amount = AmountMath.make(brand, 32n);
// NB: this is the bug. We should be minting to the seat, not throwing it
// away.
zcfMint.mintGains(harden({ Tokens: amount }));
seat.exit();
return 'Congratulations, free tokens!';
};

return harden({
publicFacet: Far('buggyPublicFacet', {
makeInvitationWrongName: () => {
return zcf.makeInvitation('oops, wrong name', () => {});
publicFacet: zone.exo('PublicFacet', undefined, {
makeInvitation: () => {
return zcf.makeInvitation(offerHandler, 'free tokens');
},
}),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ enactCoreEval() {
done
}

(cd "$PROPDIR" && agoric run "$ORIGDIR/test/propose-buggy-contract.js")
doTest "$PROPDIR"
if [ "${1-init}" = init ]; then
(cd "$PROPDIR" && agoric run "$ORIGDIR/test/upgrade-contract/propose-buggy-contract.js")
enactCoreEval "$PROPDIR"
fi

(cd "$PROPDIR2" && agoric run "$ORIGDIR/test/propose-upgrade-contract.js")
doTest "$PROPDIR2"
(cd "$PROPDIR2" && agoric run "$ORIGDIR/test/upgrade-contract/propose-upgrade-contract.js")
enactCoreEval "$PROPDIR2"
34 changes: 26 additions & 8 deletions packages/agoric-cli/test/upgrade-contract/fixed-contract.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import { Far } from '@endo/far';
import { AmountMath } from '@agoric/ertp';
// eslint-disable-next-line import/no-extraneous-dependencies
import { makeDurableZone } from '@agoric/zone/durable.js';

/**
* @param {ZCF} zcf
* @param {*} _privateArgs
* @param {MapStore<any, any>} baggage
*/
export const prepare = async (zcf, _privateArgs, baggage) => {
const zone = makeDurableZone(baggage);

/** @type {ZCFMint} */
const zcfMint = baggage.get('myMint');
const { brand } = zcfMint.getIssuerRecord();

/** @type {OfferHandler} */
const offerHandler = seat => {
const amount = AmountMath.make(brand, 32n);
zcfMint.mintGains(harden({ Tokens: amount }), seat);
seat.exit();
return 'Congratulations, free tokens!';
};

export const start = async (zcf, _privateArgs, baggage) => {
const { mint } = baggage.get('myMint');
return harden({
publicFacet: Far('buggyPublicFacet', {
makeInvitationRightName: () => {
return zcf.makeInvitation(`right invitation`, seat => {
seat;
});
publicFacet: zone.exo('PublicFacet', undefined, {
makeInvitation: () => {
return zcf.makeInvitation(offerHandler, 'free tokens fur realz');
},
}),
});
Expand Down
22 changes: 16 additions & 6 deletions packages/agoric-cli/test/upgrade-contract/init-proposal.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { E } from '@endo/far';

/**
* Initialize contractRef the first time.
*
* @param {BootstrapSpace} param0
*/
export const initContract = async ({
consume: { zoe },
produce: { myContractFacets },
installation: { consume: myInitInstallation },
instance: { produce: myInstance },
installation: {
consume: { myInitInstallation },
},
instance: {
produce: { myInstance },
},
}) => {
const instanceFacets = await zoe.startInstance(
myInitInstallation,
myInstance,
);
const instanceFacets = await E(zoe).startInstance(myInitInstallation);
myContractFacets.reset();
myContractFacets.resolve(instanceFacets);
myInstance.reset();
myInstance.resolve(instanceFacets.instance);
};

Expand Down

0 comments on commit 0a90faf

Please sign in to comment.