Skip to content

Commit

Permalink
fixup puppet
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Feb 10, 2023
1 parent 6aa0059 commit 1762a38
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const isAsync = {
* @typedef {[type: T, value: ParamValueForType<T>]} ST param spec tuple
*/

/**
* @typedef {{ type: 'invitation', value: Amount<'set'> }} InvitationParam
*/

// XXX better to use the manifest constant ParamTypes
// but importing that here turns this file into a module,
// breaking the ambient typing
Expand Down
6 changes: 5 additions & 1 deletion packages/governance/src/contractGovernor.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ const validateQuestionFromCounter = async (zoe, electorate, voteCounter) => {
*/

/**
* @template {() => {creatorFacet: GovernorFacet<any>, publicFacet: GovernedPublicFacetMethods} } SF Start function of governed contract
* @typedef {() => {creatorFacet: GovernorFacet<any>, publicFacet: GovernedPublicFacetMethods}} GovernableStartFn
*/

/**
* @template {GovernableStartFn} SF Start function of governed contract
* @param {ZCF<{
* timer: import('@agoric/time/src/types').TimerService,
* governedContractInstallation: Installation<SF>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test('multiple params bad change', async t => {
const timer = buildManualTimer(t.log);
const { governorFacets } = await setUpGovernedContract(
zoe,
governedBundleP,
E(zoe).install(governedBundleP),
timer,
governedTerms,
);
Expand All @@ -85,7 +85,7 @@ test('change a param', async t => {
const timer = buildManualTimer(t.log);
const { governorFacets, getFakeInvitation } = await setUpGovernedContract(
zoe,
governedBundleP,
E(zoe).install(governedBundleP),
timer,
governedTerms,
);
Expand Down Expand Up @@ -142,7 +142,7 @@ test('set offer Filter directly', async t => {
const timer = buildManualTimer(t.log);
const { governorFacets } = await setUpGovernedContract(
zoe,
governedBundleP,
E(zoe).install(governedBundleP),
timer,
governedTerms,
);
Expand All @@ -159,13 +159,14 @@ test('call API directly', async t => {
const timer = buildManualTimer(t.log);
const { governorFacets } = await setUpGovernedContract(
zoe,
governedBundleP,
E(zoe).install(governedBundleP),
timer,
governedTerms,
);

await E(governorFacets.creatorFacet).invokeAPI('governanceApi', []);
t.deepEqual(
// @ts-expect-error FIXME type the puppet extensions
await E(E(governorFacets.creatorFacet).getPublicFacet()).getApiCalled(),
1,
);
Expand Down
6 changes: 3 additions & 3 deletions packages/governance/tools/puppetContractGovernor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { CONTRACT_ELECTORATE } from '../src/contractGovernance/governParam.js';
// It adds the ability for tests to update parameters directly.

/**
* @template {() => {creatorFacet: GovernorFacet<any>, publicFacet: unknown} } SF Start function of governed contract
* @template {import('../src/contractGovernor.js').GovernableStartFn} SF Start function of governed contract
* @param {ZCF<{
* timer: import('@agoric/time/src/types').TimerService,
* governedContractInstallation: Installation<SF>,
* governed: {
* issuerKeywordRecord: IssuerKeywordRecord,
* terms: {governedParams: {[CONTRACT_ELECTORATE]: Amount<'set'>}},
* terms: {governedParams: {[CONTRACT_ELECTORATE]: import('../src/contractGovernance/typedParamManager.js').InvitationParam }},
* }
* }>} zcf
* @param {{
Expand Down Expand Up @@ -94,6 +94,6 @@ export const start = async (zcf, privateArgs) => {
};
harden(start);
/**
* @template {() => {creatorFacet: GovernorFacet<any>, publicFacet: unknown} } SF Start function of governed contract
* @template {import('../src/contractGovernor.js').GovernableStartFn} SF Start function of governed contract
* @typedef {Awaited<ReturnType<typeof start<SF>>>} PuppetContractGovernorKit<SF>
*/
31 changes: 21 additions & 10 deletions packages/governance/tools/puppetGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,39 @@ const autoRefundBundleP = makeBundle(
'@agoric/zoe/src/contracts/automaticRefund.js',
);

/** */

/**
*
* @template {import('../src/contractGovernor.js').GovernableStartFn} T governed contract startfn
* @param {ERef<ZoeService>} zoe
* @param {ERef<Installation>} governedBundleP
* @param {ERef<Installation<T>>} governedP
* @param {import('@agoric/swingset-vat/src/vats/timer/vat-timer.js').TimerService} timer
* @param {{ governedParams?: Record<string, unknown>, governedApis?: string[] }} governedTerms
* @param {{}} governedPrivateArgs
*/
export const setUpGovernedContract = async (
zoe,
governedBundleP,
governedP,
timer,
governedTerms = {},
governedPrivateArgs = {},
) => {
const [contractGovernorBundle, autoRefundBundle, governedBundle] =
await Promise.all([
contractGovernorBundleP,
autoRefundBundleP,
governedBundleP,
]);
const [contractGovernorBundle, autoRefundBundle] = await Promise.all([
contractGovernorBundleP,
autoRefundBundleP,
]);

/**
* @type {[
* Installation<import('./puppetContractGovernor').start>,
* Installation<any>,
* Installation<T>,
* ]}
*/
const [governor, autoRefund, governed] = await Promise.all([
E(zoe).install(contractGovernorBundle),
E(zoe).install(autoRefundBundle),
E(zoe).install(governedBundle),
governedP,
]);
const installs = { governor, autoRefund, governed };

Expand All @@ -63,6 +72,7 @@ export const setUpGovernedContract = async (
await getFakeInvitation();

const governedTermsWithElectorate = {
...governedTerms,
governedParams: {
...governedTerms.governedParams,
[CONTRACT_ELECTORATE]: {
Expand All @@ -87,6 +97,7 @@ export const setUpGovernedContract = async (
governorTerms,
{
governed: {
...governedPrivateArgs,
initialPoserInvitation: fakeInvitationPayment,
},
},
Expand Down

0 comments on commit 1762a38

Please sign in to comment.