@maci-protocol/testing 0.0.0-ci.00107eb

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