@maci-protocol/testing 0.0.0-ci.2653bc0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +262 -0
  2. package/LICENSE +22 -0
  3. package/README.md +16 -0
  4. package/build/hardhat.config.d.ts +5 -0
  5. package/build/hardhat.config.d.ts.map +1 -0
  6. package/build/hardhat.config.js +37 -0
  7. package/build/hardhat.config.js.map +1 -0
  8. package/build/ts/__tests__/e2e.nonQv.test.d.ts +2 -0
  9. package/build/ts/__tests__/e2e.nonQv.test.d.ts.map +1 -0
  10. package/build/ts/__tests__/e2e.nonQv.test.js +208 -0
  11. package/build/ts/__tests__/e2e.nonQv.test.js.map +1 -0
  12. package/build/ts/__tests__/e2e.test.d.ts +2 -0
  13. package/build/ts/__tests__/e2e.test.d.ts.map +1 -0
  14. package/build/ts/__tests__/e2e.test.js +1588 -0
  15. package/build/ts/__tests__/e2e.test.js.map +1 -0
  16. package/build/ts/__tests__/integration.test.d.ts +2 -0
  17. package/build/ts/__tests__/integration.test.d.ts.map +1 -0
  18. package/build/ts/__tests__/integration.test.js +288 -0
  19. package/build/ts/__tests__/integration.test.js.map +1 -0
  20. package/build/ts/__tests__/keyChange.test.d.ts +2 -0
  21. package/build/ts/__tests__/keyChange.test.d.ts.map +1 -0
  22. package/build/ts/__tests__/keyChange.test.js +444 -0
  23. package/build/ts/__tests__/keyChange.test.js.map +1 -0
  24. package/build/ts/__tests__/maci-keys.test.d.ts +2 -0
  25. package/build/ts/__tests__/maci-keys.test.d.ts.map +1 -0
  26. package/build/ts/__tests__/maci-keys.test.js +78 -0
  27. package/build/ts/__tests__/maci-keys.test.js.map +1 -0
  28. package/build/ts/__tests__/unit/fundWallet.test.d.ts +2 -0
  29. package/build/ts/__tests__/unit/fundWallet.test.d.ts.map +1 -0
  30. package/build/ts/__tests__/unit/fundWallet.test.js +15 -0
  31. package/build/ts/__tests__/unit/fundWallet.test.js.map +1 -0
  32. package/build/ts/__tests__/unit/joinPoll.test.d.ts +2 -0
  33. package/build/ts/__tests__/unit/joinPoll.test.d.ts.map +1 -0
  34. package/build/ts/__tests__/unit/joinPoll.test.js +125 -0
  35. package/build/ts/__tests__/unit/joinPoll.test.js.map +1 -0
  36. package/build/ts/__tests__/unit/poll.test.d.ts +2 -0
  37. package/build/ts/__tests__/unit/poll.test.d.ts.map +1 -0
  38. package/build/ts/__tests__/unit/poll.test.js +89 -0
  39. package/build/ts/__tests__/unit/poll.test.js.map +1 -0
  40. package/build/ts/__tests__/unit/publish.test.d.ts +2 -0
  41. package/build/ts/__tests__/unit/publish.test.d.ts.map +1 -0
  42. package/build/ts/__tests__/unit/publish.test.js +129 -0
  43. package/build/ts/__tests__/unit/publish.test.js.map +1 -0
  44. package/build/ts/__tests__/unit/signup.test.d.ts +2 -0
  45. package/build/ts/__tests__/unit/signup.test.d.ts.map +1 -0
  46. package/build/ts/__tests__/unit/signup.test.js +63 -0
  47. package/build/ts/__tests__/unit/signup.test.js.map +1 -0
  48. package/build/ts/__tests__/unit/timeTravel.test.d.ts +2 -0
  49. package/build/ts/__tests__/unit/timeTravel.test.d.ts.map +1 -0
  50. package/build/ts/__tests__/unit/timeTravel.test.js +14 -0
  51. package/build/ts/__tests__/unit/timeTravel.test.js.map +1 -0
  52. package/build/ts/__tests__/unit/utils.test.d.ts +2 -0
  53. package/build/ts/__tests__/unit/utils.test.d.ts.map +1 -0
  54. package/build/ts/__tests__/unit/utils.test.js +36 -0
  55. package/build/ts/__tests__/unit/utils.test.js.map +1 -0
  56. package/build/ts/constants.d.ts +83 -0
  57. package/build/ts/constants.d.ts.map +1 -0
  58. package/build/ts/constants.js +156 -0
  59. package/build/ts/constants.js.map +1 -0
  60. package/build/ts/index.d.ts +4 -0
  61. package/build/ts/index.d.ts.map +1 -0
  62. package/build/ts/index.js +23 -0
  63. package/build/ts/index.js.map +1 -0
  64. package/build/ts/testingClass.d.ts +43 -0
  65. package/build/ts/testingClass.d.ts.map +1 -0
  66. package/build/ts/testingClass.js +139 -0
  67. package/build/ts/testingClass.js.map +1 -0
  68. package/build/ts/types.d.ts +100 -0
  69. package/build/ts/types.d.ts.map +1 -0
  70. package/build/ts/types.js +3 -0
  71. package/build/ts/types.js.map +1 -0
  72. package/build/ts/user.d.ts +31 -0
  73. package/build/ts/user.d.ts.map +1 -0
  74. package/build/ts/user.js +37 -0
  75. package/build/ts/user.js.map +1 -0
  76. package/build/ts/utils.d.ts +70 -0
  77. package/build/ts/utils.d.ts.map +1 -0
  78. package/build/ts/utils.js +192 -0
  79. package/build/ts/utils.js.map +1 -0
  80. package/build/tsconfig.tsbuildinfo +1 -0
  81. package/package.json +53 -0
@@ -0,0 +1,1588 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const core_1 = require("@maci-protocol/core");
7
+ const crypto_1 = require("@maci-protocol/crypto");
8
+ const domainobjs_1 = require("@maci-protocol/domainobjs");
9
+ const sdk_1 = require("@maci-protocol/sdk");
10
+ const chai_1 = require("chai");
11
+ const fs_1 = __importDefault(require("fs"));
12
+ const constants_1 = require("../constants");
13
+ const utils_1 = require("../utils");
14
+ /**
15
+ Test scenarios:
16
+ 4 signups, 8 messages, 16 relayed messages
17
+ 8 signups (same key), 12 messages (same message), 12 relayed messages (same message)
18
+ 30 signups (31 ballots), 4 messages
19
+ 30 signups (31 ballots), 4 messages, 3 relayed messages
20
+ multiple polls tests
21
+ 2 signups (1 after stateAq is merged and logs are fetched), 1 message
22
+ 30 signups (31 ballots), 21 messages (> 1 batch)
23
+ 1 signup and 1 valid message for multiple polls
24
+ 7 signups and 1 message, another polls and 6 messages
25
+ */
26
+ describe("e2e tests", function test() {
27
+ const useWasm = (0, sdk_1.isArm)();
28
+ this.timeout(900000);
29
+ let maciAddresses;
30
+ let vkRegistryAddress;
31
+ let initialVoiceCreditProxyContractAddress;
32
+ let verifierContractAddress;
33
+ let signer;
34
+ const generateProofsArgs = {
35
+ outputDir: constants_1.testProofsDirPath,
36
+ tallyFile: constants_1.testTallyFilePath,
37
+ tallyZkey: constants_1.tallyVotesTestZkeyPath,
38
+ processZkey: constants_1.processMessageTestZkeyPath,
39
+ pollId: 0n,
40
+ rapidsnark: constants_1.testRapidsnarkPath,
41
+ processWitgen: constants_1.testProcessMessagesWitnessPath,
42
+ processDatFile: constants_1.testProcessMessagesWitnessDatPath,
43
+ tallyWitgen: constants_1.testTallyVotesWitnessPath,
44
+ tallyDatFile: constants_1.testTallyVotesWitnessDatPath,
45
+ coordinatorPrivateKey: constants_1.coordinatorPrivKey,
46
+ processWasm: constants_1.testProcessMessagesWasmPath,
47
+ tallyWasm: constants_1.testTallyVotesWasmPath,
48
+ useWasm,
49
+ useQuadraticVoting: true,
50
+ };
51
+ // before all tests we deploy the vk registry contract and set the verifying keys
52
+ before(async () => {
53
+ signer = await (0, sdk_1.getDefaultSigner)();
54
+ // we deploy the vk registry contract
55
+ vkRegistryAddress = await (0, sdk_1.deployVkRegistryContract)({ signer });
56
+ const [initialVoiceCreditProxy] = await (0, sdk_1.deployConstantInitialVoiceCreditProxy)({ amount: constants_1.DEFAULT_INITIAL_VOICE_CREDITS }, signer, undefined, true);
57
+ initialVoiceCreditProxyContractAddress = await initialVoiceCreditProxy.getAddress();
58
+ const verifier = await (0, sdk_1.deployVerifier)(signer, true);
59
+ verifierContractAddress = await verifier.getAddress();
60
+ // we set the verifying keys
61
+ await (0, sdk_1.setVerifyingKeys)({ ...(await (0, constants_1.verifyingKeysArgs)(signer)), vkRegistryAddress });
62
+ });
63
+ describe("2 signups (1 after stateAq is merged and logs are fetched), 1 message", () => {
64
+ after(async () => {
65
+ await (0, utils_1.clean)();
66
+ });
67
+ const user = new domainobjs_1.Keypair();
68
+ before(async () => {
69
+ const [signupPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
70
+ const signupPolicyContractAddress = await signupPolicy.getAddress();
71
+ const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
72
+ const pollPolicyContractAddress = await pollPolicy.getAddress();
73
+ // deploy the smart contracts
74
+ maciAddresses = await (0, sdk_1.deployMaci)({
75
+ ...constants_1.deployArgs,
76
+ signer,
77
+ signupPolicyAddress: signupPolicyContractAddress,
78
+ });
79
+ const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
80
+ // deploy a poll contract
81
+ await (0, sdk_1.deployPoll)({
82
+ ...constants_1.deployPollArgs,
83
+ signer,
84
+ pollStartTimestamp: startDate,
85
+ pollEndTimestamp: startDate + constants_1.pollDuration,
86
+ relayers: [await signer.getAddress()],
87
+ maciAddress: maciAddresses.maciContractAddress,
88
+ verifierContractAddress,
89
+ vkRegistryContractAddress: vkRegistryAddress,
90
+ policyContractAddress: pollPolicyContractAddress,
91
+ initialVoiceCreditProxyContractAddress,
92
+ });
93
+ });
94
+ it("should signup one user", async () => {
95
+ await (0, sdk_1.signup)({
96
+ maciAddress: maciAddresses.maciContractAddress,
97
+ maciPubKey: user.pubKey.serialize(),
98
+ sgData: constants_1.DEFAULT_SG_DATA,
99
+ signer,
100
+ });
101
+ });
102
+ it("should join one user", async () => {
103
+ await (0, sdk_1.joinPoll)({
104
+ maciAddress: maciAddresses.maciContractAddress,
105
+ privateKey: user.privKey.serialize(),
106
+ stateIndex: 1n,
107
+ pollId: 0n,
108
+ pollJoiningZkey: constants_1.pollJoiningTestZkeyPath,
109
+ useWasm: true,
110
+ pollWasm: constants_1.testPollJoiningWasmPath,
111
+ pollWitgen: constants_1.testPollJoiningWitnessPath,
112
+ rapidsnark: constants_1.testRapidsnarkPath,
113
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
114
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
115
+ signer,
116
+ });
117
+ });
118
+ it("should publish one message", async () => {
119
+ await (0, sdk_1.publish)({
120
+ pubkey: user.pubKey.serialize(),
121
+ stateIndex: 1n,
122
+ voteOptionIndex: 0n,
123
+ nonce: 1n,
124
+ pollId: 0n,
125
+ newVoteWeight: 9n,
126
+ maciAddress: maciAddresses.maciContractAddress,
127
+ salt: (0, crypto_1.genRandomSalt)(),
128
+ privateKey: user.privKey.serialize(),
129
+ signer,
130
+ });
131
+ });
132
+ it("should generate zk-SNARK proofs and verify them", async () => {
133
+ await (0, sdk_1.timeTravel)({ ...constants_1.timeTravelArgs, signer });
134
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
135
+ const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
136
+ ...generateProofsArgs,
137
+ maciAddress: maciAddresses.maciContractAddress,
138
+ signer,
139
+ });
140
+ await (0, sdk_1.signup)({
141
+ maciAddress: maciAddresses.maciContractAddress,
142
+ maciPubKey: new domainobjs_1.Keypair().pubKey.serialize(),
143
+ sgData: constants_1.DEFAULT_SG_DATA,
144
+ signer,
145
+ });
146
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
147
+ await (0, sdk_1.verify)({
148
+ ...(await (0, constants_1.verifyArgs)(signer)),
149
+ tallyData: tallyFileData,
150
+ maciAddress: tallyFileData.maci,
151
+ });
152
+ });
153
+ });
154
+ describe("4 signups, 8 messages, 16 relayed messages", () => {
155
+ after(async () => {
156
+ await (0, utils_1.clean)();
157
+ });
158
+ const users = [new domainobjs_1.Keypair(), new domainobjs_1.Keypair(), new domainobjs_1.Keypair(), new domainobjs_1.Keypair()];
159
+ before(async () => {
160
+ const [signupPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
161
+ const signupPolicyContractAddress = await signupPolicy.getAddress();
162
+ const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
163
+ const pollPolicyContractAddress = await pollPolicy.getAddress();
164
+ // deploy the smart contracts
165
+ maciAddresses = await (0, sdk_1.deployMaci)({
166
+ ...constants_1.deployArgs,
167
+ signer,
168
+ signupPolicyAddress: signupPolicyContractAddress,
169
+ });
170
+ const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
171
+ // deploy a poll contract
172
+ await (0, sdk_1.deployPoll)({
173
+ ...constants_1.deployPollArgs,
174
+ signer,
175
+ pollStartTimestamp: startDate,
176
+ pollEndTimestamp: startDate + constants_1.pollDuration,
177
+ relayers: [await signer.getAddress()],
178
+ maciAddress: maciAddresses.maciContractAddress,
179
+ verifierContractAddress,
180
+ vkRegistryContractAddress: vkRegistryAddress,
181
+ policyContractAddress: pollPolicyContractAddress,
182
+ initialVoiceCreditProxyContractAddress,
183
+ });
184
+ });
185
+ it("should signup four users", async () => {
186
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
187
+ for (let i = 0; i < users.length; i += 1) {
188
+ // eslint-disable-next-line no-await-in-loop
189
+ await (0, sdk_1.signup)({
190
+ maciAddress: maciAddresses.maciContractAddress,
191
+ maciPubKey: users[i].pubKey.serialize(),
192
+ sgData: constants_1.DEFAULT_SG_DATA,
193
+ signer,
194
+ });
195
+ }
196
+ });
197
+ it("should join four users", async () => {
198
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
199
+ for (let i = 0; i < users.length; i += 1) {
200
+ // eslint-disable-next-line no-await-in-loop
201
+ await (0, sdk_1.joinPoll)({
202
+ maciAddress: maciAddresses.maciContractAddress,
203
+ privateKey: users[i].privKey.serialize(),
204
+ stateIndex: BigInt(i + 1),
205
+ pollId: 0n,
206
+ pollJoiningZkey: constants_1.pollJoiningTestZkeyPath,
207
+ useWasm: true,
208
+ pollWasm: constants_1.testPollJoiningWasmPath,
209
+ pollWitgen: constants_1.testPollJoiningWitnessPath,
210
+ rapidsnark: constants_1.testRapidsnarkPath,
211
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
212
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
213
+ signer,
214
+ });
215
+ }
216
+ });
217
+ it("should publish eight messages", async () => {
218
+ await (0, sdk_1.publish)({
219
+ pubkey: users[0].pubKey.serialize(),
220
+ stateIndex: 1n,
221
+ voteOptionIndex: 0n,
222
+ nonce: 2n,
223
+ pollId: 0n,
224
+ newVoteWeight: 4n,
225
+ maciAddress: maciAddresses.maciContractAddress,
226
+ salt: (0, crypto_1.genRandomSalt)(),
227
+ privateKey: users[0].privKey.serialize(),
228
+ signer,
229
+ });
230
+ await (0, sdk_1.publish)({
231
+ pubkey: users[0].pubKey.serialize(),
232
+ stateIndex: 1n,
233
+ voteOptionIndex: 0n,
234
+ nonce: 2n,
235
+ pollId: 0n,
236
+ newVoteWeight: 3n,
237
+ maciAddress: maciAddresses.maciContractAddress,
238
+ salt: (0, crypto_1.genRandomSalt)(),
239
+ privateKey: users[0].privKey.serialize(),
240
+ signer,
241
+ });
242
+ await (0, sdk_1.publish)({
243
+ pubkey: users[0].pubKey.serialize(),
244
+ stateIndex: 1n,
245
+ voteOptionIndex: 0n,
246
+ nonce: 1n,
247
+ pollId: 0n,
248
+ newVoteWeight: 9n,
249
+ maciAddress: maciAddresses.maciContractAddress,
250
+ salt: (0, crypto_1.genRandomSalt)(),
251
+ privateKey: users[0].privKey.serialize(),
252
+ signer,
253
+ });
254
+ await (0, sdk_1.publish)({
255
+ pubkey: users[1].pubKey.serialize(),
256
+ stateIndex: 2n,
257
+ voteOptionIndex: 2n,
258
+ nonce: 1n,
259
+ pollId: 0n,
260
+ newVoteWeight: 9n,
261
+ maciAddress: maciAddresses.maciContractAddress,
262
+ salt: (0, crypto_1.genRandomSalt)(),
263
+ privateKey: users[1].privKey.serialize(),
264
+ signer,
265
+ });
266
+ await (0, sdk_1.publish)({
267
+ pubkey: users[2].pubKey.serialize(),
268
+ stateIndex: 3n,
269
+ voteOptionIndex: 2n,
270
+ nonce: 1n,
271
+ pollId: 0n,
272
+ newVoteWeight: 9n,
273
+ maciAddress: maciAddresses.maciContractAddress,
274
+ salt: (0, crypto_1.genRandomSalt)(),
275
+ privateKey: users[2].privKey.serialize(),
276
+ signer,
277
+ });
278
+ await (0, sdk_1.publish)({
279
+ pubkey: users[3].pubKey.serialize(),
280
+ stateIndex: 4n,
281
+ voteOptionIndex: 2n,
282
+ nonce: 3n,
283
+ pollId: 0n,
284
+ newVoteWeight: 3n,
285
+ maciAddress: maciAddresses.maciContractAddress,
286
+ salt: (0, crypto_1.genRandomSalt)(),
287
+ privateKey: users[3].privKey.serialize(),
288
+ signer,
289
+ });
290
+ await (0, sdk_1.publish)({
291
+ pubkey: users[3].pubKey.serialize(),
292
+ stateIndex: 4n,
293
+ voteOptionIndex: 2n,
294
+ nonce: 2n,
295
+ pollId: 0n,
296
+ newVoteWeight: 2n,
297
+ maciAddress: maciAddresses.maciContractAddress,
298
+ salt: (0, crypto_1.genRandomSalt)(),
299
+ privateKey: users[3].privKey.serialize(),
300
+ signer,
301
+ });
302
+ await (0, sdk_1.publish)({
303
+ pubkey: users[3].pubKey.serialize(),
304
+ stateIndex: 4n,
305
+ voteOptionIndex: 1n,
306
+ nonce: 1n,
307
+ pollId: 0n,
308
+ newVoteWeight: 9n,
309
+ maciAddress: maciAddresses.maciContractAddress,
310
+ salt: (0, crypto_1.genRandomSalt)(),
311
+ privateKey: users[3].privKey.serialize(),
312
+ signer,
313
+ });
314
+ });
315
+ it("should relay sixteen messages", async () => {
316
+ const votes = [
317
+ {
318
+ pollId: 0n,
319
+ voteOptionIndex: 1n,
320
+ salt: (0, crypto_1.genRandomSalt)(),
321
+ nonce: 2n,
322
+ privateKey: users[0].privKey,
323
+ stateIndex: 1n,
324
+ voteWeight: 4n,
325
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
326
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
327
+ newPubKey: users[0].pubKey,
328
+ },
329
+ {
330
+ pollId: 0n,
331
+ voteOptionIndex: 1n,
332
+ salt: (0, crypto_1.genRandomSalt)(),
333
+ nonce: 2n,
334
+ privateKey: users[0].privKey,
335
+ stateIndex: 1n,
336
+ voteWeight: 3n,
337
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
338
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
339
+ newPubKey: users[0].pubKey,
340
+ },
341
+ {
342
+ pollId: 0n,
343
+ voteOptionIndex: 1n,
344
+ salt: (0, crypto_1.genRandomSalt)(),
345
+ nonce: 1n,
346
+ privateKey: users[0].privKey,
347
+ stateIndex: 1n,
348
+ voteWeight: 9n,
349
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
350
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
351
+ newPubKey: users[0].pubKey,
352
+ },
353
+ {
354
+ pollId: 0n,
355
+ voteOptionIndex: 1n,
356
+ salt: (0, crypto_1.genRandomSalt)(),
357
+ nonce: 1n,
358
+ privateKey: users[1].privKey,
359
+ stateIndex: 2n,
360
+ voteWeight: 9n,
361
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
362
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
363
+ newPubKey: users[1].pubKey,
364
+ },
365
+ {
366
+ pollId: 0n,
367
+ voteOptionIndex: 1n,
368
+ salt: (0, crypto_1.genRandomSalt)(),
369
+ nonce: 1n,
370
+ privateKey: users[2].privKey,
371
+ stateIndex: 3n,
372
+ voteWeight: 9n,
373
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
374
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
375
+ newPubKey: users[2].pubKey,
376
+ },
377
+ {
378
+ pollId: 0n,
379
+ voteOptionIndex: 0n,
380
+ salt: (0, crypto_1.genRandomSalt)(),
381
+ nonce: 3n,
382
+ privateKey: users[3].privKey,
383
+ stateIndex: 4n,
384
+ voteWeight: 3n,
385
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
386
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
387
+ newPubKey: users[3].pubKey,
388
+ },
389
+ {
390
+ pollId: 0n,
391
+ voteOptionIndex: 0n,
392
+ salt: (0, crypto_1.genRandomSalt)(),
393
+ nonce: 2n,
394
+ privateKey: users[3].privKey,
395
+ stateIndex: 4n,
396
+ voteWeight: 2n,
397
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
398
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
399
+ newPubKey: users[3].pubKey,
400
+ },
401
+ {
402
+ pollId: 0n,
403
+ voteOptionIndex: 0n,
404
+ salt: (0, crypto_1.genRandomSalt)(),
405
+ nonce: 1n,
406
+ privateKey: users[3].privKey,
407
+ stateIndex: 4n,
408
+ voteWeight: 9n,
409
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
410
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
411
+ newPubKey: users[3].pubKey,
412
+ },
413
+ ];
414
+ const messages = votes
415
+ .map((vote) => (0, sdk_1.generateVote)(vote))
416
+ .map(({ message, ephemeralKeypair }) => ({
417
+ maciAddress: maciAddresses.maciContractAddress,
418
+ poll: 0,
419
+ data: message.data.map(String),
420
+ publicKey: ephemeralKeypair.pubKey.asArray().map(String),
421
+ hash: message.hash(ephemeralKeypair.pubKey).toString(),
422
+ }));
423
+ await (0, utils_1.relayTestMessages)({ messages, signer, pollId: 0, maciAddress: maciAddresses.maciContractAddress });
424
+ });
425
+ it("should generate zk-SNARK proofs and verify them", async () => {
426
+ const ipfsMessageBackupFiles = await (0, utils_1.getBackupFilenames)();
427
+ await (0, sdk_1.timeTravel)({ ...constants_1.timeTravelArgs, signer });
428
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
429
+ await (0, sdk_1.generateProofs)({
430
+ ...generateProofsArgs,
431
+ signer,
432
+ maciAddress: maciAddresses.maciContractAddress,
433
+ ipfsMessageBackupFiles,
434
+ });
435
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
436
+ await (0, sdk_1.verify)({ ...(await (0, constants_1.verifyArgs)(signer)) });
437
+ });
438
+ });
439
+ describe("8 signups (same key), 12 messages (same message), 12 relayed messages (same message)", () => {
440
+ after(async () => {
441
+ await (0, utils_1.clean)();
442
+ });
443
+ const users = Array.from({ length: 30 }, () => new domainobjs_1.Keypair());
444
+ before(async () => {
445
+ const [signupPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
446
+ const signupPolicyContractAddress = await signupPolicy.getAddress();
447
+ const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
448
+ const pollPolicyContractAddress = await pollPolicy.getAddress();
449
+ // deploy the smart contracts
450
+ maciAddresses = await (0, sdk_1.deployMaci)({
451
+ ...constants_1.deployArgs,
452
+ signer,
453
+ signupPolicyAddress: signupPolicyContractAddress,
454
+ });
455
+ const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
456
+ // deploy a poll contract
457
+ await (0, sdk_1.deployPoll)({
458
+ ...constants_1.deployPollArgs,
459
+ signer,
460
+ pollStartTimestamp: startDate,
461
+ pollEndTimestamp: startDate + constants_1.pollDuration,
462
+ relayers: [await signer.getAddress()],
463
+ maciAddress: maciAddresses.maciContractAddress,
464
+ verifierContractAddress,
465
+ vkRegistryContractAddress: vkRegistryAddress,
466
+ policyContractAddress: pollPolicyContractAddress,
467
+ initialVoiceCreditProxyContractAddress,
468
+ });
469
+ });
470
+ it("should signup eight users", async () => {
471
+ for (let i = 0; i < 8; i += 1) {
472
+ // eslint-disable-next-line no-await-in-loop
473
+ await (0, sdk_1.signup)({
474
+ maciAddress: maciAddresses.maciContractAddress,
475
+ maciPubKey: users[i].pubKey.serialize(),
476
+ sgData: constants_1.DEFAULT_SG_DATA,
477
+ signer,
478
+ });
479
+ }
480
+ });
481
+ it("should join user", async () => {
482
+ // eslint-disable-next-line no-await-in-loop
483
+ await (0, sdk_1.joinPoll)({
484
+ maciAddress: maciAddresses.maciContractAddress,
485
+ privateKey: users[0].privKey.serialize(),
486
+ stateIndex: 1n,
487
+ pollId: 0n,
488
+ pollJoiningZkey: constants_1.pollJoiningTestZkeyPath,
489
+ useWasm: true,
490
+ pollWasm: constants_1.testPollJoiningWasmPath,
491
+ pollWitgen: constants_1.testPollJoiningWitnessPath,
492
+ rapidsnark: constants_1.testRapidsnarkPath,
493
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
494
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
495
+ signer,
496
+ });
497
+ });
498
+ it("should publish and relay 12 messages with the same nonce", async () => {
499
+ const messages = new Array(12)
500
+ .fill(0)
501
+ .map(() => (0, sdk_1.generateVote)({
502
+ pollId: 0n,
503
+ voteOptionIndex: 0n,
504
+ salt: (0, crypto_1.genRandomSalt)(),
505
+ nonce: 1n,
506
+ privateKey: users[0].privKey,
507
+ stateIndex: 1n,
508
+ voteWeight: 9n,
509
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
510
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
511
+ newPubKey: users[0].pubKey,
512
+ }))
513
+ .map(({ message, ephemeralKeypair }) => ({
514
+ maciAddress: maciAddresses.maciContractAddress,
515
+ poll: 0,
516
+ data: message.data.map(String),
517
+ publicKey: ephemeralKeypair.pubKey.asArray().map(String),
518
+ hash: message.hash(ephemeralKeypair.pubKey).toString(),
519
+ }));
520
+ await (0, utils_1.relayTestMessages)({ messages, signer, pollId: 0, maciAddress: maciAddresses.maciContractAddress });
521
+ for (let i = 0; i < 12; i += 1) {
522
+ // eslint-disable-next-line no-await-in-loop
523
+ await (0, sdk_1.publish)({
524
+ pubkey: users[0].pubKey.serialize(),
525
+ stateIndex: 1n,
526
+ voteOptionIndex: 0n,
527
+ nonce: 1n,
528
+ pollId: 0n,
529
+ newVoteWeight: 9n,
530
+ maciAddress: maciAddresses.maciContractAddress,
531
+ salt: (0, crypto_1.genRandomSalt)(),
532
+ privateKey: users[0].privKey.serialize(),
533
+ signer,
534
+ });
535
+ }
536
+ });
537
+ it("should generate zk-SNARK proofs and verify them", async () => {
538
+ const ipfsMessageBackupFiles = await (0, utils_1.getBackupFilenames)();
539
+ await (0, sdk_1.timeTravel)({ ...constants_1.timeTravelArgs, signer });
540
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
541
+ await (0, sdk_1.generateProofs)({
542
+ ...generateProofsArgs,
543
+ maciAddress: maciAddresses.maciContractAddress,
544
+ signer,
545
+ ipfsMessageBackupFiles,
546
+ });
547
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
548
+ await (0, sdk_1.verify)({ ...(await (0, constants_1.verifyArgs)(signer)) });
549
+ });
550
+ });
551
+ describe("30 signups (31 ballots), 30 messages", () => {
552
+ after(async () => {
553
+ await (0, utils_1.clean)();
554
+ });
555
+ const users = Array.from({ length: 30 }, () => new domainobjs_1.Keypair());
556
+ before(async () => {
557
+ const [signupPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
558
+ const signupPolicyContractAddress = await signupPolicy.getAddress();
559
+ const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
560
+ const pollPolicyContractAddress = await pollPolicy.getAddress();
561
+ // deploy the smart contracts
562
+ maciAddresses = await (0, sdk_1.deployMaci)({
563
+ ...constants_1.deployArgs,
564
+ signer,
565
+ signupPolicyAddress: signupPolicyContractAddress,
566
+ });
567
+ const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
568
+ // deploy a poll contract
569
+ await (0, sdk_1.deployPoll)({
570
+ ...constants_1.deployPollArgs,
571
+ signer,
572
+ pollStartTimestamp: startDate,
573
+ pollEndTimestamp: startDate + constants_1.pollDuration,
574
+ relayers: [await signer.getAddress()],
575
+ maciAddress: maciAddresses.maciContractAddress,
576
+ verifierContractAddress,
577
+ vkRegistryContractAddress: vkRegistryAddress,
578
+ policyContractAddress: pollPolicyContractAddress,
579
+ initialVoiceCreditProxyContractAddress,
580
+ });
581
+ });
582
+ it("should signup thirty users", async () => {
583
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
584
+ for (let i = 0; i < users.length; i += 1) {
585
+ // eslint-disable-next-line no-await-in-loop
586
+ await (0, sdk_1.signup)({
587
+ maciAddress: maciAddresses.maciContractAddress,
588
+ maciPubKey: users[i].pubKey.serialize(),
589
+ sgData: constants_1.DEFAULT_SG_DATA,
590
+ signer,
591
+ });
592
+ }
593
+ });
594
+ it("should join thirty users", async () => {
595
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
596
+ for (let i = 0; i < users.length; i += 1) {
597
+ // eslint-disable-next-line no-await-in-loop
598
+ await (0, sdk_1.joinPoll)({
599
+ maciAddress: maciAddresses.maciContractAddress,
600
+ privateKey: users[i].privKey.serialize(),
601
+ stateIndex: BigInt(i + 1),
602
+ pollId: 0n,
603
+ pollJoiningZkey: constants_1.pollJoiningTestZkeyPath,
604
+ useWasm: true,
605
+ pollWasm: constants_1.testPollJoiningWasmPath,
606
+ pollWitgen: constants_1.testPollJoiningWitnessPath,
607
+ rapidsnark: constants_1.testRapidsnarkPath,
608
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
609
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
610
+ signer,
611
+ });
612
+ }
613
+ });
614
+ it("should publish 30 messages", async () => {
615
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
616
+ for (let i = 0; i < users.length; i += 1) {
617
+ // eslint-disable-next-line no-await-in-loop
618
+ await (0, sdk_1.publish)({
619
+ maciAddress: maciAddresses.maciContractAddress,
620
+ pubkey: users[i].pubKey.serialize(),
621
+ stateIndex: BigInt(i + 1),
622
+ voteOptionIndex: 0n,
623
+ nonce: 1n,
624
+ pollId: 0n,
625
+ newVoteWeight: 9n,
626
+ salt: (0, crypto_1.genRandomSalt)(),
627
+ privateKey: users[i].privKey.serialize(),
628
+ signer,
629
+ });
630
+ }
631
+ });
632
+ it("should generate zk-SNARK proofs and verify them", async () => {
633
+ await (0, sdk_1.timeTravel)({ ...constants_1.timeTravelArgs, signer });
634
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
635
+ const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
636
+ ...generateProofsArgs,
637
+ maciAddress: maciAddresses.maciContractAddress,
638
+ signer,
639
+ });
640
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
641
+ await (0, sdk_1.verify)({ ...(await (0, constants_1.verifyArgs)(signer)), tallyData: tallyFileData });
642
+ });
643
+ });
644
+ describe("30 signups (31 ballots), 30 messages, 3 relayed messages", () => {
645
+ after(async () => {
646
+ await (0, utils_1.clean)();
647
+ });
648
+ const users = Array.from({ length: 30 }, () => new domainobjs_1.Keypair());
649
+ before(async () => {
650
+ const [signupPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
651
+ const signupPolicyContractAddress = await signupPolicy.getAddress();
652
+ const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
653
+ const pollPolicyContractAddress = await pollPolicy.getAddress();
654
+ // deploy the smart contracts
655
+ maciAddresses = await (0, sdk_1.deployMaci)({
656
+ ...constants_1.deployArgs,
657
+ signer,
658
+ signupPolicyAddress: signupPolicyContractAddress,
659
+ });
660
+ const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
661
+ // deploy a poll contract
662
+ await (0, sdk_1.deployPoll)({
663
+ ...constants_1.deployPollArgs,
664
+ signer,
665
+ pollStartTimestamp: startDate,
666
+ pollEndTimestamp: startDate + constants_1.pollDuration,
667
+ relayers: [await signer.getAddress()],
668
+ maciAddress: maciAddresses.maciContractAddress,
669
+ verifierContractAddress,
670
+ vkRegistryContractAddress: vkRegistryAddress,
671
+ policyContractAddress: pollPolicyContractAddress,
672
+ initialVoiceCreditProxyContractAddress,
673
+ });
674
+ });
675
+ it("should signup thirty users", async () => {
676
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
677
+ for (let i = 0; i < users.length; i += 1) {
678
+ // eslint-disable-next-line no-await-in-loop
679
+ await (0, sdk_1.signup)({
680
+ maciAddress: maciAddresses.maciContractAddress,
681
+ maciPubKey: users[i].pubKey.serialize(),
682
+ sgData: constants_1.DEFAULT_SG_DATA,
683
+ signer,
684
+ });
685
+ }
686
+ });
687
+ it("should join thirty users", async () => {
688
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
689
+ for (let i = 0; i < users.length; i += 1) {
690
+ // eslint-disable-next-line no-await-in-loop
691
+ await (0, sdk_1.joinPoll)({
692
+ maciAddress: maciAddresses.maciContractAddress,
693
+ privateKey: users[i].privKey.serialize(),
694
+ stateIndex: BigInt(i + 1),
695
+ pollId: 0n,
696
+ pollJoiningZkey: constants_1.pollJoiningTestZkeyPath,
697
+ useWasm: true,
698
+ pollWasm: constants_1.testPollJoiningWasmPath,
699
+ pollWitgen: constants_1.testPollJoiningWitnessPath,
700
+ rapidsnark: constants_1.testRapidsnarkPath,
701
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
702
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
703
+ signer,
704
+ });
705
+ }
706
+ });
707
+ it("should publish 30 messages", async () => {
708
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
709
+ for (let i = 0; i < users.length; i += 1) {
710
+ // eslint-disable-next-line no-await-in-loop
711
+ await (0, sdk_1.publish)({
712
+ maciAddress: maciAddresses.maciContractAddress,
713
+ pubkey: users[i].pubKey.serialize(),
714
+ stateIndex: 1n,
715
+ voteOptionIndex: 0n,
716
+ nonce: 1n,
717
+ pollId: 0n,
718
+ newVoteWeight: 9n,
719
+ salt: (0, crypto_1.genRandomSalt)(),
720
+ privateKey: users[i].privKey.serialize(),
721
+ signer,
722
+ });
723
+ }
724
+ });
725
+ it("should relay 3 messages", async () => {
726
+ const votes = [
727
+ {
728
+ pollId: 0n,
729
+ voteOptionIndex: 1n,
730
+ salt: (0, crypto_1.genRandomSalt)(),
731
+ nonce: 2n,
732
+ privateKey: users[0].privKey,
733
+ stateIndex: 1n,
734
+ voteWeight: 5n,
735
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
736
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
737
+ newPubKey: users[0].pubKey,
738
+ },
739
+ {
740
+ pollId: 0n,
741
+ voteOptionIndex: 2n,
742
+ salt: (0, crypto_1.genRandomSalt)(),
743
+ nonce: 3n,
744
+ privateKey: users[2].privKey,
745
+ stateIndex: 3n,
746
+ voteWeight: 9n,
747
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
748
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
749
+ newPubKey: users[2].pubKey,
750
+ },
751
+ {
752
+ pollId: 0n,
753
+ voteOptionIndex: 3n,
754
+ salt: (0, crypto_1.genRandomSalt)(),
755
+ nonce: 3n,
756
+ privateKey: users[3].privKey,
757
+ stateIndex: 4n,
758
+ voteWeight: 7n,
759
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
760
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
761
+ newPubKey: users[3].pubKey,
762
+ },
763
+ ];
764
+ const messages = votes
765
+ .map((vote) => (0, sdk_1.generateVote)(vote))
766
+ .map(({ message, ephemeralKeypair }) => ({
767
+ maciAddress: maciAddresses.maciContractAddress,
768
+ poll: 0,
769
+ data: message.data.map(String),
770
+ publicKey: ephemeralKeypair.pubKey.asArray().map(String),
771
+ hash: message.hash(ephemeralKeypair.pubKey).toString(),
772
+ }));
773
+ await (0, utils_1.relayTestMessages)({ messages, signer, pollId: 0, maciAddress: maciAddresses.maciContractAddress });
774
+ });
775
+ it("should generate zk-SNARK proofs and verify them", async () => {
776
+ const ipfsMessageBackupFiles = await (0, utils_1.getBackupFilenames)();
777
+ await (0, sdk_1.timeTravel)({ ...constants_1.timeTravelArgs, signer });
778
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
779
+ const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
780
+ ...generateProofsArgs,
781
+ maciAddress: maciAddresses.maciContractAddress,
782
+ signer,
783
+ ipfsMessageBackupFiles,
784
+ });
785
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
786
+ await (0, sdk_1.verify)({ ...(await (0, constants_1.verifyArgs)(signer)), tallyData: tallyFileData });
787
+ });
788
+ });
789
+ describe("multiplePolls with new signups", () => {
790
+ after(async () => {
791
+ await (0, utils_1.clean)();
792
+ });
793
+ const users = Array.from({ length: 5 }, () => new domainobjs_1.Keypair());
794
+ before(async () => {
795
+ const [signupPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
796
+ const signupPolicyContractAddress = await signupPolicy.getAddress();
797
+ const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
798
+ const pollPolicyContractAddress = await pollPolicy.getAddress();
799
+ // deploy the smart contracts
800
+ maciAddresses = await (0, sdk_1.deployMaci)({
801
+ ...constants_1.deployArgs,
802
+ signer,
803
+ signupPolicyAddress: signupPolicyContractAddress,
804
+ });
805
+ const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
806
+ // deploy a poll contract
807
+ await (0, sdk_1.deployPoll)({
808
+ ...constants_1.deployPollArgs,
809
+ signer,
810
+ pollStartTimestamp: startDate,
811
+ pollEndTimestamp: startDate + constants_1.pollDuration,
812
+ relayers: [await signer.getAddress()],
813
+ maciAddress: maciAddresses.maciContractAddress,
814
+ verifierContractAddress,
815
+ vkRegistryContractAddress: vkRegistryAddress,
816
+ policyContractAddress: pollPolicyContractAddress,
817
+ initialVoiceCreditProxyContractAddress,
818
+ });
819
+ // signup
820
+ await (0, sdk_1.signup)({
821
+ maciAddress: maciAddresses.maciContractAddress,
822
+ maciPubKey: users[0].pubKey.serialize(),
823
+ sgData: constants_1.DEFAULT_SG_DATA,
824
+ signer,
825
+ });
826
+ // joinPoll
827
+ await (0, sdk_1.joinPoll)({
828
+ maciAddress: maciAddresses.maciContractAddress,
829
+ privateKey: users[0].privKey.serialize(),
830
+ stateIndex: 1n,
831
+ pollId: 0n,
832
+ pollJoiningZkey: constants_1.pollJoiningTestZkeyPath,
833
+ useWasm: true,
834
+ pollWasm: constants_1.testPollJoiningWasmPath,
835
+ pollWitgen: constants_1.testPollJoiningWitnessPath,
836
+ rapidsnark: constants_1.testRapidsnarkPath,
837
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
838
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
839
+ signer,
840
+ });
841
+ // publish
842
+ await (0, sdk_1.publish)({
843
+ pubkey: users[0].pubKey.serialize(),
844
+ stateIndex: 1n,
845
+ voteOptionIndex: 0n,
846
+ nonce: 1n,
847
+ pollId: 0n,
848
+ newVoteWeight: 9n,
849
+ maciAddress: maciAddresses.maciContractAddress,
850
+ salt: (0, crypto_1.genRandomSalt)(),
851
+ privateKey: users[0].privKey.serialize(),
852
+ signer,
853
+ });
854
+ await (0, sdk_1.signup)({
855
+ maciAddress: maciAddresses.maciContractAddress,
856
+ maciPubKey: users[1].pubKey.serialize(),
857
+ sgData: constants_1.DEFAULT_SG_DATA,
858
+ signer,
859
+ });
860
+ await (0, sdk_1.signup)({
861
+ maciAddress: maciAddresses.maciContractAddress,
862
+ maciPubKey: users[2].pubKey.serialize(),
863
+ sgData: constants_1.DEFAULT_SG_DATA,
864
+ signer,
865
+ });
866
+ // joinPoll
867
+ await (0, sdk_1.joinPoll)({
868
+ maciAddress: maciAddresses.maciContractAddress,
869
+ privateKey: users[1].privKey.serialize(),
870
+ stateIndex: 2n,
871
+ pollId: 0n,
872
+ pollJoiningZkey: constants_1.pollJoiningTestZkeyPath,
873
+ useWasm: true,
874
+ pollWasm: constants_1.testPollJoiningWasmPath,
875
+ pollWitgen: constants_1.testPollJoiningWitnessPath,
876
+ rapidsnark: constants_1.testRapidsnarkPath,
877
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
878
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
879
+ signer,
880
+ });
881
+ const votes = [
882
+ {
883
+ pollId: 0n,
884
+ voteOptionIndex: 0n,
885
+ salt: (0, crypto_1.genRandomSalt)(),
886
+ nonce: 1n,
887
+ privateKey: users[1].privKey,
888
+ stateIndex: 2n,
889
+ voteWeight: 2n,
890
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
891
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
892
+ newPubKey: users[1].pubKey,
893
+ },
894
+ ];
895
+ const messages = votes
896
+ .map((vote) => (0, sdk_1.generateVote)(vote))
897
+ .map(({ message, ephemeralKeypair }) => ({
898
+ maciAddress: maciAddresses.maciContractAddress,
899
+ poll: 0,
900
+ data: message.data.map(String),
901
+ publicKey: ephemeralKeypair.pubKey.asArray().map(String),
902
+ hash: message.hash(ephemeralKeypair.pubKey).toString(),
903
+ }));
904
+ await (0, utils_1.relayTestMessages)({ messages, signer, pollId: 0, maciAddress: maciAddresses.maciContractAddress });
905
+ const ipfsMessageBackupFiles = await (0, utils_1.getBackupFilenames)();
906
+ // time travel
907
+ await (0, sdk_1.timeTravel)({ ...constants_1.timeTravelArgs, signer });
908
+ // generate proofs
909
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
910
+ const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
911
+ ...generateProofsArgs,
912
+ maciAddress: maciAddresses.maciContractAddress,
913
+ signer,
914
+ ipfsMessageBackupFiles,
915
+ });
916
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
917
+ await (0, sdk_1.verify)({ ...(await (0, constants_1.verifyArgs)(signer)), tallyData: tallyFileData });
918
+ await (0, utils_1.clean)();
919
+ });
920
+ it("should deploy a new poll", async () => {
921
+ const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
922
+ const pollPolicyContractAddress = await pollPolicy.getAddress();
923
+ const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
924
+ // deploy a poll contract
925
+ await (0, sdk_1.deployPoll)({
926
+ ...constants_1.deployPollArgs,
927
+ signer,
928
+ pollStartTimestamp: startDate,
929
+ pollEndTimestamp: startDate + constants_1.pollDuration,
930
+ relayers: [await signer.getAddress()],
931
+ maciAddress: maciAddresses.maciContractAddress,
932
+ verifierContractAddress,
933
+ vkRegistryContractAddress: vkRegistryAddress,
934
+ policyContractAddress: pollPolicyContractAddress,
935
+ initialVoiceCreditProxyContractAddress,
936
+ });
937
+ });
938
+ it("should signup two new users", async () => {
939
+ await (0, sdk_1.signup)({
940
+ maciAddress: maciAddresses.maciContractAddress,
941
+ maciPubKey: users[3].pubKey.serialize(),
942
+ sgData: constants_1.DEFAULT_SG_DATA,
943
+ signer,
944
+ });
945
+ await (0, sdk_1.signup)({
946
+ maciAddress: maciAddresses.maciContractAddress,
947
+ maciPubKey: users[4].pubKey.serialize(),
948
+ sgData: constants_1.DEFAULT_SG_DATA,
949
+ signer,
950
+ });
951
+ });
952
+ it("should join users", async () => {
953
+ // joinPoll
954
+ await (0, sdk_1.joinPoll)({
955
+ maciAddress: maciAddresses.maciContractAddress,
956
+ privateKey: users[3].privKey.serialize(),
957
+ stateIndex: 4n,
958
+ pollId: 1n,
959
+ pollJoiningZkey: constants_1.pollJoiningTestZkeyPath,
960
+ useWasm: true,
961
+ pollWasm: constants_1.testPollJoiningWasmPath,
962
+ pollWitgen: constants_1.testPollJoiningWitnessPath,
963
+ rapidsnark: constants_1.testRapidsnarkPath,
964
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
965
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
966
+ signer,
967
+ });
968
+ // joinPoll
969
+ await (0, sdk_1.joinPoll)({
970
+ maciAddress: maciAddresses.maciContractAddress,
971
+ privateKey: users[4].privKey.serialize(),
972
+ stateIndex: 5n,
973
+ pollId: 1n,
974
+ pollJoiningZkey: constants_1.pollJoiningTestZkeyPath,
975
+ useWasm: true,
976
+ pollWasm: constants_1.testPollJoiningWasmPath,
977
+ pollWitgen: constants_1.testPollJoiningWitnessPath,
978
+ rapidsnark: constants_1.testRapidsnarkPath,
979
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
980
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
981
+ signer,
982
+ });
983
+ });
984
+ it("should relay new messages", async () => {
985
+ const votes = [
986
+ {
987
+ pollId: 1n,
988
+ voteOptionIndex: 1n,
989
+ salt: (0, crypto_1.genRandomSalt)(),
990
+ nonce: 1n,
991
+ privateKey: users[0].privKey,
992
+ stateIndex: 1n,
993
+ voteWeight: 9n,
994
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
995
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
996
+ newPubKey: users[0].pubKey,
997
+ },
998
+ {
999
+ pollId: 1n,
1000
+ voteOptionIndex: 0n,
1001
+ salt: (0, crypto_1.genRandomSalt)(),
1002
+ nonce: 1n,
1003
+ privateKey: users[1].privKey,
1004
+ stateIndex: 1n,
1005
+ voteWeight: 5n,
1006
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
1007
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
1008
+ newPubKey: users[1].pubKey,
1009
+ },
1010
+ ];
1011
+ const messages = votes
1012
+ .map((vote) => (0, sdk_1.generateVote)(vote))
1013
+ .map(({ message, ephemeralKeypair }) => ({
1014
+ maciAddress: maciAddresses.maciContractAddress,
1015
+ poll: 1,
1016
+ data: message.data.map(String),
1017
+ publicKey: ephemeralKeypair.pubKey.asArray().map(String),
1018
+ hash: message.hash(ephemeralKeypair.pubKey).toString(),
1019
+ }));
1020
+ await (0, utils_1.relayTestMessages)({ messages, signer, pollId: 1, maciAddress: maciAddresses.maciContractAddress });
1021
+ });
1022
+ it("should publish a new message from the first poll voter", async () => {
1023
+ await (0, sdk_1.publish)({
1024
+ pubkey: users[0].pubKey.serialize(),
1025
+ stateIndex: 1n,
1026
+ voteOptionIndex: 0n,
1027
+ nonce: 1n,
1028
+ pollId: 1n,
1029
+ newVoteWeight: 7n,
1030
+ maciAddress: maciAddresses.maciContractAddress,
1031
+ salt: (0, crypto_1.genRandomSalt)(),
1032
+ privateKey: users[0].privKey.serialize(),
1033
+ signer,
1034
+ });
1035
+ });
1036
+ it("should publish a new message by the new poll voters", async () => {
1037
+ await (0, sdk_1.publish)({
1038
+ pubkey: users[1].pubKey.serialize(),
1039
+ stateIndex: 1n,
1040
+ voteOptionIndex: 0n,
1041
+ nonce: 1n,
1042
+ pollId: 1n,
1043
+ newVoteWeight: 7n,
1044
+ maciAddress: maciAddresses.maciContractAddress,
1045
+ salt: (0, crypto_1.genRandomSalt)(),
1046
+ privateKey: users[1].privKey.serialize(),
1047
+ signer,
1048
+ });
1049
+ });
1050
+ it("should generate proofs and verify them", async () => {
1051
+ const ipfsMessageBackupFiles = await (0, utils_1.getBackupFilenames)();
1052
+ await (0, sdk_1.timeTravel)({ ...constants_1.timeTravelArgs, signer });
1053
+ await (0, sdk_1.mergeSignups)({ maciAddress: maciAddresses.maciContractAddress, pollId: 1n, signer });
1054
+ await (0, sdk_1.generateProofs)({
1055
+ ...generateProofsArgs,
1056
+ pollId: 1,
1057
+ maciAddress: maciAddresses.maciContractAddress,
1058
+ signer,
1059
+ ipfsMessageBackupFiles,
1060
+ });
1061
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, pollId: 1n, maciAddress: maciAddresses.maciContractAddress, signer });
1062
+ await (0, sdk_1.verify)({ ...(await (0, constants_1.verifyArgs)(signer)), pollId: 1n });
1063
+ });
1064
+ });
1065
+ describe("multiplePolls", () => {
1066
+ const users = [
1067
+ new domainobjs_1.Keypair(),
1068
+ new domainobjs_1.Keypair(),
1069
+ new domainobjs_1.Keypair(),
1070
+ new domainobjs_1.Keypair(),
1071
+ new domainobjs_1.Keypair(),
1072
+ new domainobjs_1.Keypair(),
1073
+ new domainobjs_1.Keypair(),
1074
+ ];
1075
+ after(async () => {
1076
+ await (0, utils_1.clean)();
1077
+ });
1078
+ before(async () => {
1079
+ const [signupPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
1080
+ const signupPolicyContractAddress = await signupPolicy.getAddress();
1081
+ // deploy the smart contracts
1082
+ maciAddresses = await (0, sdk_1.deployMaci)({
1083
+ ...constants_1.deployArgs,
1084
+ signer,
1085
+ signupPolicyAddress: signupPolicyContractAddress,
1086
+ });
1087
+ });
1088
+ it("should run the first poll", async () => {
1089
+ const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
1090
+ const pollPolicyContractAddress = await pollPolicy.getAddress();
1091
+ const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
1092
+ // deploy a poll contract
1093
+ await (0, sdk_1.deployPoll)({
1094
+ ...constants_1.deployPollArgs,
1095
+ signer,
1096
+ pollStartTimestamp: startDate,
1097
+ pollEndTimestamp: startDate + constants_1.pollDuration,
1098
+ relayers: [await signer.getAddress()],
1099
+ maciAddress: maciAddresses.maciContractAddress,
1100
+ verifierContractAddress,
1101
+ vkRegistryContractAddress: vkRegistryAddress,
1102
+ policyContractAddress: pollPolicyContractAddress,
1103
+ initialVoiceCreditProxyContractAddress,
1104
+ });
1105
+ // signup
1106
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
1107
+ for (let i = 0; i < users.length; i += 1) {
1108
+ // eslint-disable-next-line no-await-in-loop
1109
+ await (0, sdk_1.signup)({
1110
+ maciAddress: maciAddresses.maciContractAddress,
1111
+ maciPubKey: users[i].pubKey.serialize(),
1112
+ sgData: constants_1.DEFAULT_SG_DATA,
1113
+ signer,
1114
+ });
1115
+ // eslint-disable-next-line no-await-in-loop
1116
+ const { isRegistered, stateIndex } = await (0, sdk_1.getSignedupUserData)({
1117
+ maciAddress: maciAddresses.maciContractAddress,
1118
+ maciPubKey: users[i].pubKey.serialize(),
1119
+ signer,
1120
+ });
1121
+ (0, chai_1.expect)(isRegistered).to.eq(true);
1122
+ (0, chai_1.expect)(stateIndex).to.not.eq(undefined);
1123
+ }
1124
+ // join the first poll
1125
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
1126
+ for (let i = 0; i < users.length; i += 1) {
1127
+ // eslint-disable-next-line no-await-in-loop
1128
+ await (0, sdk_1.joinPoll)({
1129
+ maciAddress: maciAddresses.maciContractAddress,
1130
+ privateKey: users[i].privKey.serialize(),
1131
+ stateIndex: BigInt(i + 1),
1132
+ pollId: 0n,
1133
+ pollJoiningZkey: constants_1.pollJoiningTestZkeyPath,
1134
+ useWasm: true,
1135
+ pollWasm: constants_1.testPollJoiningWasmPath,
1136
+ pollWitgen: constants_1.testPollJoiningWitnessPath,
1137
+ rapidsnark: constants_1.testRapidsnarkPath,
1138
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
1139
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
1140
+ signer,
1141
+ });
1142
+ // eslint-disable-next-line no-await-in-loop
1143
+ const { isJoined, pollStateIndex } = await (0, sdk_1.getJoinedUserData)({
1144
+ maciAddress: maciAddresses.maciContractAddress,
1145
+ pollId: 0n,
1146
+ pollPubKey: users[i].pubKey.serialize(),
1147
+ signer,
1148
+ startBlock: 0,
1149
+ });
1150
+ (0, chai_1.expect)(isJoined).to.eq(true);
1151
+ (0, chai_1.expect)(pollStateIndex).to.not.eq(undefined);
1152
+ }
1153
+ // publish
1154
+ await (0, sdk_1.publish)({
1155
+ pubkey: users[0].pubKey.serialize(),
1156
+ stateIndex: 1n,
1157
+ voteOptionIndex: 0n,
1158
+ nonce: 1n,
1159
+ pollId: 0n,
1160
+ newVoteWeight: 9n,
1161
+ maciAddress: maciAddresses.maciContractAddress,
1162
+ salt: (0, crypto_1.genRandomSalt)(),
1163
+ privateKey: users[0].privKey.serialize(),
1164
+ signer,
1165
+ });
1166
+ const votes = [
1167
+ {
1168
+ pollId: 0n,
1169
+ voteOptionIndex: 0n,
1170
+ salt: (0, crypto_1.genRandomSalt)(),
1171
+ nonce: 1n,
1172
+ privateKey: users[0].privKey,
1173
+ stateIndex: 1n,
1174
+ voteWeight: 5n,
1175
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
1176
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
1177
+ newPubKey: users[0].pubKey,
1178
+ },
1179
+ ];
1180
+ const messages = votes
1181
+ .map((vote) => (0, sdk_1.generateVote)(vote))
1182
+ .map(({ message, ephemeralKeypair }) => ({
1183
+ maciAddress: maciAddresses.maciContractAddress,
1184
+ poll: 0,
1185
+ data: message.data.map(String),
1186
+ publicKey: ephemeralKeypair.pubKey.asArray().map(String),
1187
+ hash: message.hash(ephemeralKeypair.pubKey).toString(),
1188
+ }));
1189
+ await (0, utils_1.relayTestMessages)({ messages, signer, pollId: 0, maciAddress: maciAddresses.maciContractAddress });
1190
+ const ipfsMessageBackupFiles = await (0, utils_1.getBackupFilenames)();
1191
+ // time travel
1192
+ await (0, sdk_1.timeTravel)({ ...constants_1.timeTravelArgs, signer });
1193
+ // generate proofs
1194
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
1195
+ await (0, sdk_1.generateProofs)({
1196
+ ...generateProofsArgs,
1197
+ maciAddress: maciAddresses.maciContractAddress,
1198
+ signer,
1199
+ ipfsMessageBackupFiles,
1200
+ });
1201
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
1202
+ await (0, sdk_1.verify)({ ...(await (0, constants_1.verifyArgs)(signer)) });
1203
+ await (0, utils_1.clean)();
1204
+ });
1205
+ it("should deploy two more polls", async () => {
1206
+ const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
1207
+ {
1208
+ const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
1209
+ const pollPolicyContractAddress = await pollPolicy.getAddress();
1210
+ // deploy a poll contract
1211
+ await (0, sdk_1.deployPoll)({
1212
+ ...constants_1.deployPollArgs,
1213
+ signer,
1214
+ pollStartTimestamp: startDate,
1215
+ pollEndTimestamp: startDate + constants_1.pollDuration,
1216
+ relayers: [await signer.getAddress()],
1217
+ maciAddress: maciAddresses.maciContractAddress,
1218
+ verifierContractAddress,
1219
+ vkRegistryContractAddress: vkRegistryAddress,
1220
+ policyContractAddress: pollPolicyContractAddress,
1221
+ initialVoiceCreditProxyContractAddress,
1222
+ });
1223
+ }
1224
+ {
1225
+ const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
1226
+ const pollPolicyContractAddress = await pollPolicy.getAddress();
1227
+ // deploy a poll contract
1228
+ await (0, sdk_1.deployPoll)({
1229
+ ...constants_1.deployPollArgs,
1230
+ signer,
1231
+ pollStartTimestamp: startDate,
1232
+ pollEndTimestamp: startDate + constants_1.pollDuration,
1233
+ relayers: [await signer.getAddress()],
1234
+ maciAddress: maciAddresses.maciContractAddress,
1235
+ verifierContractAddress,
1236
+ vkRegistryContractAddress: vkRegistryAddress,
1237
+ policyContractAddress: pollPolicyContractAddress,
1238
+ initialVoiceCreditProxyContractAddress,
1239
+ });
1240
+ }
1241
+ });
1242
+ it("join the second and third polls", async () => {
1243
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
1244
+ for (let p = 1; p <= 2; p += 1) {
1245
+ for (let i = 0; i < users.length; i += 1) {
1246
+ // eslint-disable-next-line no-await-in-loop
1247
+ await (0, sdk_1.joinPoll)({
1248
+ maciAddress: maciAddresses.maciContractAddress,
1249
+ privateKey: users[i].privKey.serialize(),
1250
+ stateIndex: BigInt(i + 1),
1251
+ pollId: BigInt(p),
1252
+ pollJoiningZkey: constants_1.pollJoiningTestZkeyPath,
1253
+ useWasm: true,
1254
+ pollWasm: constants_1.testPollJoiningWasmPath,
1255
+ pollWitgen: constants_1.testPollJoiningWitnessPath,
1256
+ rapidsnark: constants_1.testRapidsnarkPath,
1257
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
1258
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
1259
+ signer,
1260
+ });
1261
+ // eslint-disable-next-line no-await-in-loop
1262
+ const { isJoined, pollStateIndex } = await (0, sdk_1.getJoinedUserData)({
1263
+ maciAddress: maciAddresses.maciContractAddress,
1264
+ pollId: BigInt(p),
1265
+ pollPubKey: users[i].pubKey.serialize(),
1266
+ signer,
1267
+ startBlock: 0,
1268
+ });
1269
+ (0, chai_1.expect)(isJoined).to.eq(true);
1270
+ (0, chai_1.expect)(pollStateIndex).to.not.eq(undefined);
1271
+ }
1272
+ }
1273
+ });
1274
+ it("should publish messages to the second poll", async () => {
1275
+ await (0, sdk_1.publish)({
1276
+ pubkey: users[0].pubKey.serialize(),
1277
+ stateIndex: 1n,
1278
+ voteOptionIndex: 0n,
1279
+ nonce: 1n,
1280
+ pollId: 1n,
1281
+ newVoteWeight: 9n,
1282
+ maciAddress: maciAddresses.maciContractAddress,
1283
+ salt: (0, crypto_1.genRandomSalt)(),
1284
+ privateKey: users[0].privKey.serialize(),
1285
+ signer,
1286
+ });
1287
+ await (0, sdk_1.publish)({
1288
+ pubkey: users[1].pubKey.serialize(),
1289
+ stateIndex: 2n,
1290
+ voteOptionIndex: 3n,
1291
+ nonce: 1n,
1292
+ pollId: 1n,
1293
+ newVoteWeight: 1n,
1294
+ maciAddress: maciAddresses.maciContractAddress,
1295
+ salt: (0, crypto_1.genRandomSalt)(),
1296
+ privateKey: users[1].privKey.serialize(),
1297
+ signer,
1298
+ });
1299
+ await (0, sdk_1.publish)({
1300
+ pubkey: users[2].pubKey.serialize(),
1301
+ stateIndex: 3n,
1302
+ voteOptionIndex: 5n,
1303
+ nonce: 1n,
1304
+ pollId: 1n,
1305
+ newVoteWeight: 3n,
1306
+ maciAddress: maciAddresses.maciContractAddress,
1307
+ salt: (0, crypto_1.genRandomSalt)(),
1308
+ privateKey: users[2].privKey.serialize(),
1309
+ signer,
1310
+ });
1311
+ });
1312
+ it("should relay a message to the second poll", async () => {
1313
+ const votes = [
1314
+ {
1315
+ pollId: 1n,
1316
+ voteOptionIndex: 0n,
1317
+ salt: (0, crypto_1.genRandomSalt)(),
1318
+ nonce: 1n,
1319
+ privateKey: users[0].privKey,
1320
+ stateIndex: 1n,
1321
+ voteWeight: 3n,
1322
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
1323
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
1324
+ newPubKey: users[0].pubKey,
1325
+ },
1326
+ ];
1327
+ const messages = votes
1328
+ .map((vote) => (0, sdk_1.generateVote)(vote))
1329
+ .map(({ message, ephemeralKeypair }) => ({
1330
+ maciAddress: maciAddresses.maciContractAddress,
1331
+ poll: 1,
1332
+ data: message.data.map(String),
1333
+ publicKey: ephemeralKeypair.pubKey.asArray().map(String),
1334
+ hash: message.hash(ephemeralKeypair.pubKey).toString(),
1335
+ }));
1336
+ await (0, utils_1.relayTestMessages)({ messages, signer, pollId: 1, maciAddress: maciAddresses.maciContractAddress });
1337
+ });
1338
+ it("should relay two messages to the third poll", async () => {
1339
+ const votes = [
1340
+ {
1341
+ pollId: 2n,
1342
+ voteOptionIndex: 7n,
1343
+ salt: (0, crypto_1.genRandomSalt)(),
1344
+ nonce: 1n,
1345
+ privateKey: users[4].privKey,
1346
+ stateIndex: 4n,
1347
+ voteWeight: 3n,
1348
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
1349
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
1350
+ newPubKey: users[4].pubKey,
1351
+ },
1352
+ {
1353
+ pollId: 2n,
1354
+ voteOptionIndex: 5n,
1355
+ salt: (0, crypto_1.genRandomSalt)(),
1356
+ nonce: 1n,
1357
+ privateKey: users[5].privKey,
1358
+ stateIndex: 5n,
1359
+ voteWeight: 4n,
1360
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
1361
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
1362
+ newPubKey: users[5].pubKey,
1363
+ },
1364
+ ];
1365
+ const messages = votes
1366
+ .map((vote) => (0, sdk_1.generateVote)(vote))
1367
+ .map(({ message, ephemeralKeypair }) => ({
1368
+ maciAddress: maciAddresses.maciContractAddress,
1369
+ poll: 2,
1370
+ data: message.data.map(String),
1371
+ publicKey: ephemeralKeypair.pubKey.asArray().map(String),
1372
+ hash: message.hash(ephemeralKeypair.pubKey).toString(),
1373
+ }));
1374
+ await (0, utils_1.relayTestMessages)({ messages, signer, pollId: 2, maciAddress: maciAddresses.maciContractAddress });
1375
+ });
1376
+ it("should publish messages to the third poll", async () => {
1377
+ await (0, sdk_1.publish)({
1378
+ pubkey: users[3].pubKey.serialize(),
1379
+ stateIndex: 3n,
1380
+ voteOptionIndex: 5n,
1381
+ nonce: 1n,
1382
+ pollId: 2n,
1383
+ newVoteWeight: 3n,
1384
+ maciAddress: maciAddresses.maciContractAddress,
1385
+ salt: (0, crypto_1.genRandomSalt)(),
1386
+ privateKey: users[3].privKey.serialize(),
1387
+ signer,
1388
+ });
1389
+ await (0, sdk_1.publish)({
1390
+ pubkey: users[4].pubKey.serialize(),
1391
+ stateIndex: 4n,
1392
+ voteOptionIndex: 7n,
1393
+ nonce: 1n,
1394
+ pollId: 2n,
1395
+ newVoteWeight: 2n,
1396
+ maciAddress: maciAddresses.maciContractAddress,
1397
+ salt: (0, crypto_1.genRandomSalt)(),
1398
+ privateKey: users[4].privKey.serialize(),
1399
+ signer,
1400
+ });
1401
+ await (0, sdk_1.publish)({
1402
+ pubkey: users[5].pubKey.serialize(),
1403
+ stateIndex: 5n,
1404
+ voteOptionIndex: 5n,
1405
+ nonce: 1n,
1406
+ pollId: 2n,
1407
+ newVoteWeight: 9n,
1408
+ maciAddress: maciAddresses.maciContractAddress,
1409
+ salt: (0, crypto_1.genRandomSalt)(),
1410
+ privateKey: users[5].privKey.serialize(),
1411
+ signer,
1412
+ });
1413
+ });
1414
+ it("should complete the second poll", async () => {
1415
+ const ipfsMessageBackupFiles = await (0, utils_1.getBackupFilenames)();
1416
+ await (0, sdk_1.timeTravel)({ ...constants_1.timeTravelArgs, signer });
1417
+ await (0, sdk_1.mergeSignups)({ maciAddress: maciAddresses.maciContractAddress, pollId: 1n, signer });
1418
+ const { tallyData } = await (0, sdk_1.generateProofs)({
1419
+ ...generateProofsArgs,
1420
+ pollId: 1,
1421
+ maciAddress: maciAddresses.maciContractAddress,
1422
+ signer,
1423
+ ipfsMessageBackupFiles,
1424
+ });
1425
+ await (0, sdk_1.proveOnChain)({
1426
+ ...constants_1.proveOnChainArgs,
1427
+ pollId: 1n,
1428
+ maciAddress: maciAddresses.maciContractAddress,
1429
+ signer,
1430
+ });
1431
+ await (0, sdk_1.verify)({
1432
+ ...(await (0, constants_1.verifyArgs)(signer)),
1433
+ pollId: 1n,
1434
+ tallyData,
1435
+ maciAddress: maciAddresses.maciContractAddress,
1436
+ });
1437
+ await (0, utils_1.clean)(false);
1438
+ });
1439
+ it("should complete the third poll", async () => {
1440
+ const ipfsMessageBackupFiles = await (0, utils_1.getBackupFilenames)();
1441
+ await (0, sdk_1.mergeSignups)({ maciAddress: maciAddresses.maciContractAddress, pollId: 2n, signer });
1442
+ const { tallyData } = await (0, sdk_1.generateProofs)({
1443
+ ...generateProofsArgs,
1444
+ pollId: 2,
1445
+ maciAddress: maciAddresses.maciContractAddress,
1446
+ signer,
1447
+ ipfsMessageBackupFiles,
1448
+ });
1449
+ await (0, sdk_1.proveOnChain)({
1450
+ ...constants_1.proveOnChainArgs,
1451
+ pollId: 2n,
1452
+ maciAddress: maciAddresses.maciContractAddress,
1453
+ signer,
1454
+ });
1455
+ await (0, sdk_1.verify)({
1456
+ ...(await (0, constants_1.verifyArgs)(signer)),
1457
+ pollId: 2n,
1458
+ tallyData,
1459
+ maciAddress: maciAddresses.maciContractAddress,
1460
+ });
1461
+ });
1462
+ });
1463
+ describe("pre fetch logs", () => {
1464
+ const stateOutPath = "./state.json";
1465
+ const user = new domainobjs_1.Keypair();
1466
+ after(async () => {
1467
+ await (0, utils_1.clean)();
1468
+ if (fs_1.default.existsSync(stateOutPath)) {
1469
+ await fs_1.default.promises.unlink(stateOutPath);
1470
+ }
1471
+ });
1472
+ before(async () => {
1473
+ const [signupPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
1474
+ const signupPolicyContractAddress = await signupPolicy.getAddress();
1475
+ const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)(signer, true);
1476
+ const pollPolicyContractAddress = await pollPolicy.getAddress();
1477
+ // deploy the smart contracts
1478
+ maciAddresses = await (0, sdk_1.deployMaci)({
1479
+ ...constants_1.deployArgs,
1480
+ signer,
1481
+ signupPolicyAddress: signupPolicyContractAddress,
1482
+ });
1483
+ const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
1484
+ // deploy a poll contract
1485
+ await (0, sdk_1.deployPoll)({
1486
+ ...constants_1.deployPollArgs,
1487
+ signer,
1488
+ pollStartTimestamp: startDate,
1489
+ pollEndTimestamp: startDate + constants_1.pollDuration,
1490
+ relayers: [await signer.getAddress()],
1491
+ maciAddress: maciAddresses.maciContractAddress,
1492
+ verifierContractAddress,
1493
+ vkRegistryContractAddress: vkRegistryAddress,
1494
+ policyContractAddress: pollPolicyContractAddress,
1495
+ initialVoiceCreditProxyContractAddress,
1496
+ });
1497
+ });
1498
+ it("should signup one user", async () => {
1499
+ await (0, sdk_1.signup)({
1500
+ maciAddress: maciAddresses.maciContractAddress,
1501
+ maciPubKey: user.pubKey.serialize(),
1502
+ sgData: constants_1.DEFAULT_SG_DATA,
1503
+ signer,
1504
+ });
1505
+ });
1506
+ it("should join one user", async () => {
1507
+ // joinPoll
1508
+ await (0, sdk_1.joinPoll)({
1509
+ maciAddress: maciAddresses.maciContractAddress,
1510
+ privateKey: user.privKey.serialize(),
1511
+ stateIndex: 1n,
1512
+ pollId: 0n,
1513
+ pollJoiningZkey: constants_1.pollJoiningTestZkeyPath,
1514
+ useWasm: true,
1515
+ pollWasm: constants_1.testPollJoiningWasmPath,
1516
+ pollWitgen: constants_1.testPollJoiningWitnessPath,
1517
+ rapidsnark: constants_1.testRapidsnarkPath,
1518
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
1519
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
1520
+ signer,
1521
+ });
1522
+ });
1523
+ it("should publish one message", async () => {
1524
+ await (0, sdk_1.publish)({
1525
+ pubkey: user.pubKey.serialize(),
1526
+ stateIndex: 1n,
1527
+ voteOptionIndex: 5n,
1528
+ nonce: 1n,
1529
+ pollId: 0n,
1530
+ newVoteWeight: 3n,
1531
+ maciAddress: maciAddresses.maciContractAddress,
1532
+ salt: (0, crypto_1.genRandomSalt)(),
1533
+ privateKey: user.privKey.serialize(),
1534
+ signer,
1535
+ });
1536
+ });
1537
+ it("should relay one message", async () => {
1538
+ const votes = [
1539
+ {
1540
+ pollId: 0n,
1541
+ voteOptionIndex: 5n,
1542
+ salt: (0, crypto_1.genRandomSalt)(),
1543
+ nonce: 1n,
1544
+ privateKey: user.privKey,
1545
+ stateIndex: 1n,
1546
+ voteWeight: 5n,
1547
+ coordinatorPubKey: constants_1.coordinatorKeypair.pubKey,
1548
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
1549
+ newPubKey: user.pubKey,
1550
+ },
1551
+ ];
1552
+ const messages = votes
1553
+ .map((vote) => (0, sdk_1.generateVote)(vote))
1554
+ .map(({ message, ephemeralKeypair }) => ({
1555
+ maciAddress: maciAddresses.maciContractAddress,
1556
+ poll: 0,
1557
+ data: message.data.map(String),
1558
+ publicKey: ephemeralKeypair.pubKey.asArray().map(String),
1559
+ hash: message.hash(ephemeralKeypair.pubKey).toString(),
1560
+ }));
1561
+ await (0, utils_1.relayTestMessages)({ messages, signer, pollId: 0, maciAddress: maciAddresses.maciContractAddress });
1562
+ });
1563
+ it("should generate zk-SNARK proofs and verify them", async () => {
1564
+ const ipfsMessageBackupFiles = await (0, utils_1.getBackupFilenames)();
1565
+ await (0, sdk_1.timeTravel)({ ...constants_1.timeTravelArgs, signer });
1566
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
1567
+ await (0, sdk_1.generateMaciState)({
1568
+ maciAddress: maciAddresses.maciContractAddress,
1569
+ outputPath: stateOutPath,
1570
+ coordinatorPrivateKey: constants_1.coordinatorPrivKey,
1571
+ blockPerBatch: 50,
1572
+ pollId: 0n,
1573
+ signer,
1574
+ ipfsMessageBackupFiles,
1575
+ });
1576
+ await (0, sdk_1.generateProofs)({
1577
+ ...generateProofsArgs,
1578
+ stateFile: stateOutPath,
1579
+ maciAddress: maciAddresses.maciContractAddress,
1580
+ signer,
1581
+ ipfsMessageBackupFiles,
1582
+ });
1583
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
1584
+ await (0, sdk_1.verify)({ ...(await (0, constants_1.verifyArgs)(signer)) });
1585
+ });
1586
+ });
1587
+ });
1588
+ //# sourceMappingURL=e2e.test.js.map