Skip to content

Commit

Permalink
refactor(run-protocol): vaultDirector to multifacted vobj (#5116)
Browse files Browse the repository at this point in the history
* defineKindMulti

* types

* esm

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
turadg and mergify[bot] authored Apr 19, 2022
1 parent 97ea98c commit 1842a73
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const { quote: q } = assert;
* @param {Record<string,Installation>} installations
* @param {ERef<GovernedContractFacetAccess<unknown>>} contractFacetAccess
* @param {bigint} deadline
* @returns {Promise<*>}
*/
const voteToChangeParameter = async (
zoe,
Expand Down Expand Up @@ -67,6 +66,12 @@ const installContracts = async (zoe, cb) => {
return installations;
};

/**
* @param {ERef<ZoeService>} zoe
* @param {Record<string, Installation>} installations
* @param {Record<string, unknown>} electorateTerms
* @returns {Promise<{electorateCreatorFacet: *, electorateInstance: Instance}>}
*/
const startElectorate = async (zoe, installations, electorateTerms) => {
const { creatorFacet: electorateCreatorFacet, instance: electorateInstance } =
await E(zoe).startInstance(installations.committee, {}, electorateTerms);
Expand Down Expand Up @@ -95,14 +100,23 @@ const votersVote = async (detailsP, votersP, selections) => {
);
};

/**
*
* @param {ERef<import('./vat-voter.js').EVatVoter[]>} votersP
* @param {ERef<QuestionDetails>} detailsP
* @param {Instance} governedInstanceP
* @param {Instance} electorateInstance
* @param {Instance} governorInstanceP
* @param {Record<string, Installation>} installations
* @returns {Promise<void>}
*/
const oneVoterValidate = async (
votersP,
detailsP,
governedInstanceP,
electorateInstance,
governorInstanceP,
installations,
timer,
) => {
const [voters, details, governedInstance, governorInstance] =
await Promise.all([
Expand All @@ -113,13 +127,12 @@ const oneVoterValidate = async (
]);
const { counterInstance } = details;

E(voters[0]).validate(
return E(voters[0]).validate(
counterInstance,
governedInstance,
electorateInstance,
governorInstance,
installations,
timer,
);
};

Expand Down Expand Up @@ -275,7 +288,6 @@ const makeBootstrap = (argv, cb, vatPowers) => async (vats, devices) => {
firstElectorateInstance,
governorInstance,
installations,
timer,
);

await E(timer).tick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const expectedcontractGovernorStartLog = [
'Voter Carol voted for {"noChange":["MalleableNumber"]}',
'Voter Dave voted for {"changes":{"MalleableNumber":"[299792458n]"}}',
'Voter Emma voted for {"changes":{"MalleableNumber":"[299792458n]"}}',
'Voter Alice validated all the things',
'@@ tick:1 @@',
'@@ tick:2 @@',
'@@ tick:3 @@',
Expand All @@ -99,7 +100,6 @@ const expectedcontractGovernorStartLog = [
'Electorate was {"brand":"[Alleged: Zoe Invitation brand]","value":[{"description":"questionPoser","handle":"[Alleged: InvitationHandle]","installation":"[Alleged: Installation]","instance":"[Alleged: InstanceHandle]"}]} after the vote.',
'Number after: 299792458',
'MalleableNumber was "[299792458n]" after the vote.',
'Voter Alice validated all the things',
];

test.serial('contract governance', async t => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ const build = async (log, zoe) => {
log(`Voter ${name} voted for ${q(choice)}`);
return E(voteFacet).castBallotFor(questionHandle, [choice]);
},
/**
*
* @param {Instance} counterInstance
* @param {Instance} governedInstance
* @param {Instance} electorateInstance
* @param {Instance} governorInstance
* @param {Record<string, Installation>} installations
* @returns {Promise<void>}
*/
validate: async (
counterInstance,
governedInstance,
Expand Down Expand Up @@ -98,6 +107,10 @@ const build = async (log, zoe) => {
});
};

/**
* @typedef {ReturnType<Awaited<ReturnType<typeof build>>['createVoter']>} EVatVoter
*/

export const buildRootObject = vatPowers =>
Far('root', {
build: (...args) => build(vatPowers.testLog, ...args),
Expand Down
Loading

0 comments on commit 1842a73

Please sign in to comment.