Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support changes to governed APIs #10822

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/boot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@agoric/cosmic-swingset": "^0.41.3",
"@agoric/ertp": "^0.16.2",
"@agoric/fast-usdc": "0.1.0",
"@agoric/governance": "^0.10.3",
"@agoric/inter-protocol": "^0.16.1",
"@agoric/internal": "^0.3.2",
"@agoric/kmarshal": "^0.1.0",
Expand Down
85 changes: 85 additions & 0 deletions packages/boot/test/bootstrapTests/governedContract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {
CONTRACT_ELECTORATE,
ParamTypes,
handleParamGovernance,
} from '@agoric/governance';
import { prepareExoClassKit, provide } from '@agoric/vat-data';

/**
* @import {GovernanceTerms} from '@agoric/governance/src/types.js';
* @import {Baggage} from '@agoric/vat-data';
*/

const MALLEABLE_NUMBER = 'MalleableNumber';

const makeTerms = (number, invitationAmount) => {
return harden({
governedParams: {
[MALLEABLE_NUMBER]: { type: ParamTypes.NAT, value: number },
[CONTRACT_ELECTORATE]: {
type: ParamTypes.INVITATION,
value: invitationAmount,
},
},
});
};

/**
*
* @param {ZCF<
* GovernanceTerms<{
* MalleableNumber: 'nat',
* }>>} zcf
* @param {{initialPoserInvitation: Invitation}} privateArgs
* @param {Baggage} baggage
*/
const start = async (zcf, privateArgs, baggage) => {
const { makeDurableGovernorFacet, params } = await handleParamGovernance(
zcf,
privateArgs.initialPoserInvitation,
{
[MALLEABLE_NUMBER]: ParamTypes.NAT,
},
);

const makeGoverned = prepareExoClassKit(
baggage,
'governed Public',
undefined,
() =>
harden({
governanceAPICalled: 0,
}),
{
public: {
getNum() {
return params.getMalleableNumber();
},
getApiCalled() {
const { governanceAPICalled } = this.state;
return governanceAPICalled;
},
},
creator: {},
governed: {
add1() {
const { state } = this;
state.governanceAPICalled += 1;
},
},
},
);
const facets = provide(baggage, 'theContract', () => makeGoverned());

const { governorFacet } = makeDurableGovernorFacet(baggage, facets.creator, {
add1: () => facets.governed.add1(),
});

return { publicFacet: facets.public, creatorFacet: governorFacet };
};

harden(start);
harden(MALLEABLE_NUMBER);
harden(makeTerms);

export { start, MALLEABLE_NUMBER, makeTerms };
90 changes: 90 additions & 0 deletions packages/boot/test/bootstrapTests/governedContract2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import {
CONTRACT_ELECTORATE,
ParamTypes,
handleParamGovernance,
} from '@agoric/governance';
import { prepareExoClassKit, provide } from '@agoric/vat-data';

/**
* @import {GovernanceTerms} from '@agoric/governance/src/types.js';
* @import {Baggage} from '@agoric/vat-data';
*/

const MALLEABLE_NUMBER = 'MalleableNumber';

const makeTerms = (number, invitationAmount) => {
return harden({
governedParams: {
[MALLEABLE_NUMBER]: { type: ParamTypes.NAT, value: number },
[CONTRACT_ELECTORATE]: {
type: ParamTypes.INVITATION,
value: invitationAmount,
},
},
});
};

/**
*
* @param {ZCF<
* GovernanceTerms<{
* MalleableNumber: 'nat',
* }>>} zcf
* @param {{initialPoserInvitation: Invitation}} privateArgs
* @param {Baggage} baggage
*/
const start = async (zcf, privateArgs, baggage) => {
const { makeDurableGovernorFacet, params } = await handleParamGovernance(
zcf,
privateArgs.initialPoserInvitation,
{
[MALLEABLE_NUMBER]: ParamTypes.NAT,
},
);

const makeGoverned = prepareExoClassKit(
baggage,
'governed Public',
undefined,
() =>
harden({
governanceAPICalled: 0,
}),
{
public: {
getNum() {
return params.getMalleableNumber();
},
getApiCalled() {
const { governanceAPICalled } = this.state;
return governanceAPICalled;
},
},
creator: {},
governed: {
add1() {
const { state } = this;
state.governanceAPICalled += 1;
},
add2() {
const { state } = this;
state.governanceAPICalled += 2;
},
},
},
);
const facets = provide(baggage, 'theContract', () => makeGoverned());

const { governorFacet } = makeDurableGovernorFacet(baggage, facets.creator, {
add1: () => facets.governed.add1(),
add2: () => facets.governed.add2(),
});

return { publicFacet: facets.public, creatorFacet: governorFacet };
};

harden(start);
harden(MALLEABLE_NUMBER);
harden(makeTerms);

export { start, MALLEABLE_NUMBER, makeTerms };
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* We change a parameter so that provideParamGovernance() is called once, and
* paramGoverance has been set. Then upgrade vaultFactory, so any ephemeral
* objects from the contract held by the governor are gone, then try to change
* param again, to show that the bug is fixedd.
* param again, to show that the bug is fixed.
*/
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js';

Expand Down
Loading
Loading