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

Simplify Creation of parameter declarations #4005

Merged
merged 2 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
59 changes: 59 additions & 0 deletions packages/governance/src/paramMakers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// ts-check

import { ParamType } from './paramManager.js';

// It might be cleaner if these returned objects with behavior that included the
// type assertion from paramManager, and other polymorphism, but this is enough
// to get us a much simpler calling style.
Comment on lines +5 to +7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. not tackling as much as I hoped. But still, forward progress...


const makeGovernedNat = (name, value) => {
return harden({ name, type: ParamType.NAT, value });
};

const makeGovernedAmount = (name, value) => {
return harden({ name, type: ParamType.AMOUNT, value });
};

const makeGovernedRatio = (name, value) => {
return harden({ name, type: ParamType.RATIO, value });
};

const makeGovernedBrand = (name, value) => {
return harden({ name, type: ParamType.BRAND, value });
};

const makeGovernedInstance = (name, value) => {
return harden({ name, type: ParamType.INSTANCE, value });
};

const makeGovernedInstallation = (name, value) => {
return harden({ name, type: ParamType.INSTALLATION, value });
};

const makeGovernedString = (name, value) => {
return harden({ name, type: ParamType.STRING, value });
};

const makeGovernedUnknown = (name, value) => {
return harden({ name, type: ParamType.UNKNOWN, value });
};

harden(makeGovernedAmount);
harden(makeGovernedBrand);
harden(makeGovernedInstallation);
harden(makeGovernedInstance);
harden(makeGovernedNat);
harden(makeGovernedRatio);
harden(makeGovernedString);
harden(makeGovernedUnknown);

export {
makeGovernedAmount,
makeGovernedBrand,
makeGovernedInstallation,
makeGovernedInstance,
makeGovernedNat,
makeGovernedRatio,
makeGovernedString,
makeGovernedUnknown,
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { E } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { observeIteration } from '@agoric/notifier';
import { governedParameterInitialValues } from './governedContract.js';
import { makeGovernedNat } from '../../../src/paramMakers.js';
import { MALLEABLE_NUMBER } from './governedContract';

const { quote: q } = assert;

Expand Down Expand Up @@ -170,7 +171,9 @@ const makeBootstrap = (argv, cb, vatPowers) => async (vats, devices) => {
governedContractInstallation: installations.governedContract,
governed: {
issuerKeywordRecord: {},
terms: { main: governedParameterInitialValues },
terms: {
main: [makeGovernedNat(MALLEABLE_NUMBER, 602214090000000000000000n)],
},
},
};
const privateArgs = { electorateCreatorFacet };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
// @ts-check

import { handleParamGovernance } from '../../../src/contractHelper.js';
import { ParamType } from '../../../src/paramManager.js';

const MALLEABLE_NUMBER = 'MalleableNumber';

/** @type {ParameterNameList} */
const governedParameterTerms = {
main: [MALLEABLE_NUMBER],
};

/** @type {ParamDescriptions} */
const governedParameterInitialValues = [
{
name: MALLEABLE_NUMBER,
value: 602214090000000000000000n,
type: ParamType.NAT,
},
];
harden(governedParameterInitialValues);

/** @type {ContractStartFn} */
const start = async zcf => {
const { main: initialValue } = zcf.getTerms();
const { makePublicFacet, makeCreatorFacet } = handleParamGovernance(
zcf,
governedParameterInitialValues,
harden(initialValue),
);

return {
Expand All @@ -35,11 +20,5 @@ const start = async zcf => {

harden(start);
harden(MALLEABLE_NUMBER);
harden(governedParameterTerms);

export {
start,
governedParameterTerms,
MALLEABLE_NUMBER,
governedParameterInitialValues,
};
export { start, MALLEABLE_NUMBER };
12 changes: 5 additions & 7 deletions packages/governance/test/unitTests/test-paramGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ import {
setupGovernance,
makeParamChangePositions,
} from '../../src/governParam.js';
import {
governedParameterInitialValues,
MALLEABLE_NUMBER,
} from '../swingsetTests/contractGovernor/governedContract.js';
import { MALLEABLE_NUMBER } from '../swingsetTests/contractGovernor/governedContract.js';
import { makeGovernedNat } from '../../src/paramMakers.js';

const filename = new URL(import.meta.url).pathname;
const dirname = path.dirname(filename);
Expand All @@ -47,7 +45,7 @@ test('governParam happy path with fakes', async t => {
const governedFacets = await E(zoe).startInstance(
governedInstall,
{},
{ main: governedParameterInitialValues },
{ main: [makeGovernedNat(MALLEABLE_NUMBER, 602214090000000000000000n)] },
);
const Retriever = governedFacets.creatorFacet.getParamMgrRetriever();

Expand Down Expand Up @@ -109,7 +107,7 @@ test('governParam no votes', async t => {
const governedFacets = await E(zoe).startInstance(
governedInstall,
{},
{ main: governedParameterInitialValues },
{ main: [makeGovernedNat(MALLEABLE_NUMBER, 602214090000000000000000n)] },
);
const Retriever = governedFacets.creatorFacet.getParamMgrRetriever();

Expand Down Expand Up @@ -177,7 +175,7 @@ test('governParam bad update', async t => {
const governedFacets = await E(zoe).startInstance(
governedInstall,
{},
{ main: governedParameterInitialValues },
{ main: [makeGovernedNat(MALLEABLE_NUMBER, 602214090000000000000000n)] },
);
const brokenParamMgr = Far('broken ParamMgr', {
getParam: () => {
Expand Down