Skip to content

Commit

Permalink
chore(cli): prepare cli package for web apps
Browse files Browse the repository at this point in the history
- [x] Make signer required
- [x] Update types
- [x] Added sdk folder for web app commands
  • Loading branch information
0xmad committed Feb 12, 2024
1 parent a807c67 commit f706d9a
Show file tree
Hide file tree
Showing 32 changed files with 605 additions and 553 deletions.
10 changes: 10 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
"version": "1.1.2",
"description": "CLI utilities for MACI",
"main": "build/ts/index.js",
"exports": {
".": {
"types": "./build/ts/index.d.ts",
"default": "./build/ts/index.js"
},
"./sdk": {
"types": "./build/ts/sdk/index.d.ts",
"default": "./build/ts/sdk/index.js"
}
},
"bin": {
"maci-cli": "./build/ts/index.js"
},
Expand Down
37 changes: 22 additions & 15 deletions cli/tests/ceremony-params/ceremonyParams.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { getDefaultSigner } from "maci-contracts";
import { genRandomSalt } from "maci-crypto";
import { Keypair } from "maci-domainobjs";

import type { Signer } from "ethers";

import {
deploy,
deployPoll,
Expand Down Expand Up @@ -52,8 +55,9 @@ describe("stress tests", function test() {
this.timeout(90000000);

let maciAddresses: DeployedContracts;
let signer: Signer;

const verifyingKeysArgs: SetVerifyingKeysArgs = {
const verifyingKeysArgs: Omit<SetVerifyingKeysArgs, "signer"> = {
quiet: true,
stateTreeDepth,
intStateTreeDepth,
Expand All @@ -64,11 +68,11 @@ describe("stress tests", function test() {
tallyVotesZkeyPath: ceremonyTallyVotesZkeyPath,
};

const ceremonyDeployArgs: DeployArgs = {
const ceremonyDeployArgs: Omit<DeployArgs, "signer"> = {
stateTreeDepth,
};

const deployPollArgs: DeployPollArgs = {
const deployPollArgs: Omit<DeployPollArgs, "signer"> = {
pollDuration,
intStateTreeDepth,
messageTreeSubDepth: messageBatchDepth,
Expand All @@ -78,7 +82,7 @@ describe("stress tests", function test() {
subsidyEnabled,
};

const genProofsCeremonyArgs: GenProofsArgs = {
const genProofsCeremonyArgs: Omit<GenProofsArgs, "signer"> = {
outputDir: testProofsDirPath,
tallyFile: testTallyFilePath,
tallyZkey: ceremonyTallyVotesZkeyPath,
Expand All @@ -97,10 +101,12 @@ describe("stress tests", function test() {

// before all tests we deploy the vk registry contract and set the verifying keys
before(async () => {
signer = await getDefaultSigner();

// we deploy the vk registry contract
await deployVkRegistryContract({});
await deployVkRegistryContract({ signer });
// we set the verifying keys
await setVerifyingKeys(verifyingKeysArgs);
await setVerifyingKeys({ ...verifyingKeysArgs, signer });
});

const users = Array<Keypair>(2).fill(new Keypair());
Expand All @@ -112,13 +118,13 @@ describe("stress tests", function test() {

before(async () => {
// deploy the smart contracts
maciAddresses = await deploy(ceremonyDeployArgs);
maciAddresses = await deploy({ ...ceremonyDeployArgs, signer });
// deploy a poll contract
await deployPoll(deployPollArgs);
await deployPoll({ ...deployPollArgs, signer });
});

it("should signup 1 user", async () => {
await signup({ maciPubKey: users[0].pubKey.serialize() });
await signup({ maciPubKey: users[0].pubKey.serialize(), signer });
});

it("should publish 2 messages", async () => {
Expand All @@ -137,17 +143,18 @@ describe("stress tests", function test() {
salt: genRandomSalt(),
privateKey: users[0].privKey.serialize(),
pollId: 0n,
signer,
});
}
});

it("should generate zk-SNARK proofs and verify them", async () => {
await timeTravel({ seconds: pollDuration });
await mergeMessages(mergeMessagesArgs);
await mergeSignups(mergeSignupsArgs);
await genProofs(genProofsCeremonyArgs);
await proveOnChain(proveOnChainArgs);
await verify(verifyArgs);
await timeTravel({ seconds: pollDuration, signer });
await mergeMessages({ ...mergeMessagesArgs, signer });
await mergeSignups({ ...mergeSignupsArgs, signer });
await genProofs({ ...genProofsCeremonyArgs, signer });
await proveOnChain({ ...proveOnChainArgs, signer });
await verify({ ...verifyArgs, signer });
});
});
});
20 changes: 10 additions & 10 deletions cli/tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const pollDuration = 90;
export const maxMessages = 25;
export const maxVoteOptions = 25;

export const setVerifyingKeysArgs: SetVerifyingKeysArgs = {
export const setVerifyingKeysArgs: Omit<SetVerifyingKeysArgs, "signer"> = {
quiet: true,
stateTreeDepth: STATE_TREE_DEPTH,
intStateTreeDepth: INT_STATE_TREE_DEPTH,
Expand All @@ -89,7 +89,7 @@ export const setVerifyingKeysArgs: SetVerifyingKeysArgs = {
tallyVotesZkeyPath: tallyVotesTestZkeyPath,
};

export const setVerifyingKeysNonQvArgs: SetVerifyingKeysArgs = {
export const setVerifyingKeysNonQvArgs: Omit<SetVerifyingKeysArgs, "signer"> = {
quiet: true,
stateTreeDepth: STATE_TREE_DEPTH,
intStateTreeDepth: INT_STATE_TREE_DEPTH,
Expand All @@ -100,7 +100,7 @@ export const setVerifyingKeysNonQvArgs: SetVerifyingKeysArgs = {
tallyVotesZkeyPath: tallyVotesTestNonQvZkeyPath,
};

export const checkVerifyingKeysArgs: CheckVerifyingKeysArgs = {
export const checkVerifyingKeysArgs: Omit<CheckVerifyingKeysArgs, "signer"> = {
stateTreeDepth: STATE_TREE_DEPTH,
intStateTreeDepth: INT_STATE_TREE_DEPTH,
messageTreeDepth: MSG_TREE_DEPTH,
Expand All @@ -110,35 +110,35 @@ export const checkVerifyingKeysArgs: CheckVerifyingKeysArgs = {
tallyVotesZkeyPath: tallyVotesTestZkeyPath,
};

export const timeTravelArgs: TimeTravelArgs = {
export const timeTravelArgs: Omit<TimeTravelArgs, "signer"> = {
seconds: pollDuration,
};

export const mergeMessagesArgs: MergeMessagesArgs = {
export const mergeMessagesArgs: Omit<MergeMessagesArgs, "signer"> = {
pollId: 0n,
};

export const mergeSignupsArgs: MergeSignupsArgs = {
export const mergeSignupsArgs: Omit<MergeSignupsArgs, "signer"> = {
pollId: 0n,
};

export const proveOnChainArgs: ProveOnChainArgs = {
export const proveOnChainArgs: Omit<ProveOnChainArgs, "signer"> = {
pollId: 0n,
proofDir: testProofsDirPath,
subsidyEnabled: false,
};

export const verifyArgs: VerifyArgs = {
export const verifyArgs: Omit<VerifyArgs, "signer"> = {
pollId: 0n,
subsidyEnabled: false,
tallyFile: testTallyFilePath,
};

export const deployArgs: DeployArgs = {
export const deployArgs: Omit<DeployArgs, "signer"> = {
stateTreeDepth: STATE_TREE_DEPTH,
};

export const deployPollArgs: DeployPollArgs = {
export const deployPollArgs: Omit<DeployPollArgs, "signer"> = {
pollDuration,
intStateTreeDepth: INT_STATE_TREE_DEPTH,
messageTreeSubDepth: MSG_BATCH_DEPTH,
Expand Down
15 changes: 8 additions & 7 deletions cli/tests/e2e/e2e.nonQv.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Signer } from "ethers";
import { getDefaultSigner } from "maci-contracts";
import { genRandomSalt } from "maci-crypto";
import { Keypair } from "maci-domainobjs";

import type { Signer } from "ethers";

import {
deploy,
deployPoll,
Expand Down Expand Up @@ -51,8 +52,9 @@ describe("e2e tests", function test() {
this.timeout(900000);

let maciAddresses: DeployedContracts;
let signer: Signer;

const genProofsArgs: GenProofsArgs = {
const genProofsArgs: Omit<GenProofsArgs, "signer"> = {
outputDir: testProofsDirPath,
tallyFile: testTallyFilePath,
tallyZkey: tallyVotesTestNonQvZkeyPath,
Expand All @@ -71,23 +73,22 @@ describe("e2e tests", function test() {

// before all tests we deploy the vk registry contract and set the verifying keys
before(async () => {
signer = await getDefaultSigner();

// we deploy the vk registry contract
await deployVkRegistryContract({});
await deployVkRegistryContract({ signer });
// we set the verifying keys
await setVerifyingKeys(setVerifyingKeysNonQvArgs);
await setVerifyingKeys({ ...setVerifyingKeysNonQvArgs, signer });
});

describe("1 signup, 1 message (with signer as argument)", () => {
let signer: Signer;

after(() => {
cleanVanilla();
});

const user = new Keypair();

before(async () => {
signer = await getDefaultSigner();
// deploy the smart contracts
maciAddresses = await deploy({ ...deployArgs, signer });
// deploy a poll contract
Expand Down
Loading

0 comments on commit f706d9a

Please sign in to comment.