Skip to content

Commit

Permalink
feat: creating a new electorate
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Sep 19, 2024
1 parent e67cd91 commit 2dbffcf
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions packages/inter-protocol/test/psm/gov-replace-committee.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
* (aka big hammer)
*/

import { Fail } from '@endo/errors';

const runConfig = {
committeeName: 'Economic Committee',
economicCommitteeAddresses: {
// gov1: 'agoric1ldmtatp24qlllgxmrsjzcpe20fvlkp448zcuce',
gov1: 'agoric1ldmtatp24qlllgxmrsjzcpe20fvlkp448zcuce',
// gov2: 'agoric140dmkrz2e42ergjj7gyvejhzmjzurvqeq82ang',
// gov3: 'agoric1w8wktaur4zf8qmmtn3n7x3r0jhsjkjntcm3u6h',
gov4: 'agoric109q3uc0xt8aavne94rgd6rfeucavrx924e0ztf',
gov4: 'agoric1p2aqakv3ulz4qfy2nut86j9gx0dx0yw09h96md',
},
};

Expand All @@ -26,15 +24,7 @@ const { values } = Object;
/** @type {<X, Y>(xs: X[], ys: Y[]) => [X, Y][]} */
const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]);

/**
* @param {ERef<import('@agoric/vats').NameAdmin>} nameAdmin
* @param {string[][]} paths
*/
const reserveThenGetNamePaths = async (nameAdmin, paths) => {
/**
* @param {ERef<import('@agoric/vats').NameAdmin>} nextAdmin
* @param {string[]} path
*/
const nextPath = async (nextAdmin, path) => {
const [nextName, ...rest] = path;
assert.typeof(nextName, 'string');
Expand All @@ -55,7 +45,7 @@ const reserveThenGetNamePaths = async (nameAdmin, paths) => {

return Promise.all(
paths.map(async path => {
Array.isArray(path) || Fail`path ${path} is not an array`;
Array.isArray(path) || 'WWWW';
return nextPath(nameAdmin, path);
}),
);
Expand Down Expand Up @@ -93,7 +83,6 @@ const invitePSMCommitteeMembers = async (
).getVoterInvitations();
assert.equal(invitations.length, values(voterAddresses).length);

/** @param {[string, Promise<Invitation>][]} addrInvitations */
const distributeInvitations = async addrInvitations => {
await Promise.all(
addrInvitations.map(async ([addr, invitationP]) => {
Expand All @@ -117,15 +106,6 @@ const invitePSMCommitteeMembers = async (
};
harden(invitePSMCommitteeMembers);

/**
* Convenience function for returning a storage node at or under its input,
* falling back to an inert object with the correct interface (but incomplete
* behavior) when that is unavailable.
*
* @param {ERef<StorageNode>} storageNodeRef
* @param {string} childName
* @returns {Promise<StorageNode>}
*/
async function makeStorageNodeChild(storageNodeRef, childName) {
return E(storageNodeRef).makeChildNode(childName);
}
Expand All @@ -138,8 +118,7 @@ const pathSegmentPattern = /^[a-zA-Z0-9_-]{1,100}$/;

/** @type {(name: string) => void} */
const assertPathSegment = name => {
pathSegmentPattern.test(name) ||
Fail`Path segment names must consist of 1 to 100 characters limited to ASCII alphanumerics, underscores, and/or dashes: ${name}`;
pathSegmentPattern.test(name) || '';
};
harden(assertPathSegment);

Expand All @@ -159,6 +138,9 @@ const startNewEconomicCommittee = async ({
installation: {
consume: { committee },
},
instance: {
produce: { economicCommittee },
},
}) => {
const COMMITTEES_ROOT = 'committees';
trace('startNewEconomicCommittee');
Expand All @@ -178,18 +160,22 @@ const startNewEconomicCommittee = async ({
// NB: committee must only publish what it intended to be public
const marshaller = await E(board).getPublishingMarshaller();

const { creatorFacet } = await E(zoe).startInstance(
const { instance, creatorFacet } = await E(zoe).startInstance(
committee, // aka electorate
{},
{ committeeName, committeeSize },
{
storageNode,
marshaller,
},
'economicCommittee',
);

const newPoserInvitationP = E(creatorFacet).getPoserInvitation();

economicCommittee.reset();
economicCommittee.resolve(instance);

// reset because it's already been resolved
economicCommitteeCreatorFacet.reset();
economicCommitteeCreatorFacet.resolve(creatorFacet);
Expand All @@ -198,7 +184,6 @@ const startNewEconomicCommittee = async ({
harden(startNewEconomicCommittee);

const main = async permittedPowers => {
console.log('starting new economic committee:', runConfig);
const newElectoratePoser = await startNewEconomicCommittee(permittedPowers);

/*
Expand Down

0 comments on commit 2dbffcf

Please sign in to comment.