@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,839 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@maci-protocol/core");
4
+ const crypto_1 = require("@maci-protocol/crypto");
5
+ const domainobjs_1 = require("@maci-protocol/domainobjs");
6
+ const sdk_1 = require("@maci-protocol/sdk");
7
+ const chai_1 = require("chai");
8
+ const constants_1 = require("../constants");
9
+ const utils_1 = require("../utils");
10
+ /**
11
+ Test scenarios:
12
+ 1 signup, 1 message
13
+ 1 signup, 1 relayed message
14
+ 1 signup, 2 valid messages
15
+ 1 signup, 2 valid and 2 invalid messages
16
+ 4 signups, 8 messages, 16 relayed messages
17
+ 30 signups (31 ballots), 21 messages
18
+ 30 signups, 30 invalid and 1 valid messages
19
+ */
20
+ describe("e2e tests with full credits voting", function test() {
21
+ const useWasm = (0, sdk_1.isArm)();
22
+ this.timeout(900000);
23
+ let maciAddresses;
24
+ let initialVoiceCreditProxyContractAddress;
25
+ let signer;
26
+ const generateProofsArgs = {
27
+ outputDir: constants_1.testProofsDirPath,
28
+ tallyFile: constants_1.testTallyFilePath,
29
+ voteTallyZkey: constants_1.testTallyVotesFullZkeyPath,
30
+ messageProcessorZkey: constants_1.testProcessMessageFullZkeyPath,
31
+ pollId: 0n,
32
+ rapidsnark: constants_1.testRapidsnarkPath,
33
+ messageProcessorWitnessGenerator: constants_1.testProcessMessagesFullWitnessPath,
34
+ messageProcessorWitnessDatFile: constants_1.testProcessMessagesFullWitnessDatPath,
35
+ voteTallyWitnessGenerator: constants_1.testTallyVotesFullWitnessPath,
36
+ voteTallyWitnessDatFile: constants_1.testTallyVotesFullWitnessDatPath,
37
+ coordinatorPrivateKey: constants_1.coordinatorPrivateKey,
38
+ messageProcessorWasm: constants_1.testProcessMessagesFullWasmPath,
39
+ voteTallyWasm: constants_1.testTallyVotesFullWasmPath,
40
+ useWasm,
41
+ mode: sdk_1.EMode.FULL,
42
+ };
43
+ const prepareTest = async () => {
44
+ const [signupPolicy, , signupPolicyFactory, signupCheckerFactory] = await (0, sdk_1.deployFreeForAllSignUpPolicy)({}, signer, true);
45
+ const signupPolicyContractAddress = await signupPolicy.getAddress();
46
+ const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)({ policy: signupPolicyFactory, checker: signupCheckerFactory }, signer, true);
47
+ const pollPolicyContractAddress = await pollPolicy.getAddress();
48
+ // deploy the smart contracts
49
+ const maciContractsAddresses = await (0, sdk_1.deployMaci)({
50
+ ...constants_1.deployArgs,
51
+ signer,
52
+ signupPolicyAddress: signupPolicyContractAddress,
53
+ });
54
+ // we set the verifying keys
55
+ const { verifyingKeysRegistryContractAddress } = maciContractsAddresses;
56
+ await (0, sdk_1.setVerifyingKeys)({
57
+ ...(await (0, constants_1.verifyingKeysArgs)(signer, [sdk_1.EMode.FULL])),
58
+ verifyingKeysRegistryAddress: verifyingKeysRegistryContractAddress,
59
+ });
60
+ const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
61
+ // deploy a poll contract
62
+ await (0, sdk_1.deployPoll)({
63
+ ...constants_1.deployPollArgs,
64
+ signer,
65
+ pollStartTimestamp: startDate,
66
+ pollEndTimestamp: startDate + constants_1.pollDuration,
67
+ relayers: [await signer.getAddress()],
68
+ maciAddress: maciContractsAddresses.maciContractAddress,
69
+ policyContractAddress: pollPolicyContractAddress,
70
+ initialVoiceCreditProxyContractAddress,
71
+ mode: sdk_1.EMode.FULL,
72
+ });
73
+ return maciContractsAddresses;
74
+ };
75
+ // before all tests we deploy the verifying keys registry contract and set the verifying keys
76
+ before(async () => {
77
+ signer = await (0, sdk_1.getDefaultSigner)();
78
+ const constantInitialVoiceCreditProxyFactory = await (0, sdk_1.deployConstantInitialVoiceCreditProxyFactory)(signer, true);
79
+ const initialVoiceCreditProxy = await (0, sdk_1.deployConstantInitialVoiceCreditProxy)({ amount: constants_1.DEFAULT_INITIAL_VOICE_CREDITS }, constantInitialVoiceCreditProxyFactory, signer);
80
+ initialVoiceCreditProxyContractAddress = await initialVoiceCreditProxy.getAddress();
81
+ });
82
+ describe("1 signup, 1 message", () => {
83
+ after(async () => {
84
+ await (0, utils_1.clean)();
85
+ });
86
+ const user = new domainobjs_1.Keypair();
87
+ before(async () => {
88
+ // deploy the smart contracts
89
+ maciAddresses = await prepareTest();
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: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
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)({ seconds: constants_1.pollDuration, 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
+ signer,
134
+ maciAddress: maciAddresses.maciContractAddress,
135
+ mode: sdk_1.EMode.FULL,
136
+ });
137
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
138
+ await (0, sdk_1.verify)({
139
+ ...(await (0, constants_1.verifyArgs)(signer)),
140
+ tallyData: tallyFileData,
141
+ maciAddress: tallyFileData.maci,
142
+ });
143
+ (0, chai_1.expect)(tallyFileData.totalSpentVoiceCredits.spent.toString()).to.eq(constants_1.DEFAULT_INITIAL_VOICE_CREDITS.toString());
144
+ tallyFileData.results.tally.forEach((result, index) => {
145
+ (0, chai_1.expect)(result.toString()).to.eq(index === 0 ? constants_1.DEFAULT_INITIAL_VOICE_CREDITS.toString() : "0");
146
+ });
147
+ });
148
+ });
149
+ describe("1 signup, 1 relayed message", () => {
150
+ after(async () => {
151
+ await (0, utils_1.clean)();
152
+ });
153
+ const user = new domainobjs_1.Keypair();
154
+ before(async () => {
155
+ // deploy the smart contracts
156
+ maciAddresses = await prepareTest();
157
+ });
158
+ it("should signup one user", async () => {
159
+ await (0, sdk_1.signup)({
160
+ maciAddress: maciAddresses.maciContractAddress,
161
+ maciPublicKey: user.publicKey.serialize(),
162
+ sgData: constants_1.DEFAULT_SG_DATA,
163
+ signer,
164
+ });
165
+ });
166
+ it("should join one user", async () => {
167
+ await (0, sdk_1.joinPoll)({
168
+ maciAddress: maciAddresses.maciContractAddress,
169
+ privateKey: user.privateKey.serialize(),
170
+ pollId: 0n,
171
+ pollJoiningZkey: constants_1.testPollJoiningZkeyPath,
172
+ useWasm,
173
+ pollJoiningWasm: constants_1.testPollJoiningWasmPath,
174
+ pollWitnessGenerator: constants_1.testPollJoiningWitnessPath,
175
+ rapidsnark: constants_1.testRapidsnarkPath,
176
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
177
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
178
+ signer,
179
+ });
180
+ });
181
+ it("should relay one message", async () => {
182
+ const { message, ephemeralKeypair } = (0, sdk_1.generateVote)({
183
+ pollId: 0n,
184
+ voteOptionIndex: 0n,
185
+ salt: (0, crypto_1.generateRandomSalt)(),
186
+ nonce: 1n,
187
+ privateKey: user.privateKey,
188
+ stateIndex: 1n,
189
+ voteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
190
+ coordinatorPublicKey: constants_1.coordinatorKeypair.publicKey,
191
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
192
+ newPublicKey: user.publicKey,
193
+ });
194
+ const messages = [
195
+ {
196
+ maciAddress: maciAddresses.maciContractAddress,
197
+ poll: 0,
198
+ data: message.data.map(String),
199
+ publicKey: ephemeralKeypair.publicKey.asArray().map(String),
200
+ hash: message.hash(ephemeralKeypair.publicKey).toString(),
201
+ },
202
+ ];
203
+ await (0, utils_1.relayTestMessages)({ messages, signer, pollId: 0, maciAddress: maciAddresses.maciContractAddress });
204
+ });
205
+ it("should generate zk-SNARK proofs and verify them", async () => {
206
+ const ipfsMessageBackupFiles = await (0, utils_1.getBackupFilenames)();
207
+ await (0, sdk_1.timeTravel)({ seconds: constants_1.pollDuration, signer });
208
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
209
+ const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
210
+ ...generateProofsArgs,
211
+ signer,
212
+ maciAddress: maciAddresses.maciContractAddress,
213
+ ipfsMessageBackupFiles,
214
+ mode: sdk_1.EMode.FULL,
215
+ });
216
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
217
+ await (0, sdk_1.verify)({
218
+ ...(await (0, constants_1.verifyArgs)(signer)),
219
+ tallyData: tallyFileData,
220
+ maciAddress: tallyFileData.maci,
221
+ });
222
+ (0, chai_1.expect)(tallyFileData.totalSpentVoiceCredits.spent.toString()).to.eq(constants_1.DEFAULT_INITIAL_VOICE_CREDITS.toString());
223
+ tallyFileData.results.tally.forEach((result, index) => {
224
+ (0, chai_1.expect)(result.toString()).to.eq(index === 0 ? constants_1.DEFAULT_INITIAL_VOICE_CREDITS.toString() : "0");
225
+ });
226
+ });
227
+ });
228
+ describe("1 signup, 2 valid messages", () => {
229
+ after(async () => {
230
+ await (0, utils_1.clean)();
231
+ });
232
+ const user = new domainobjs_1.Keypair();
233
+ before(async () => {
234
+ // deploy the smart contracts
235
+ maciAddresses = await prepareTest();
236
+ });
237
+ it("should signup one user", async () => {
238
+ await (0, sdk_1.signup)({
239
+ maciAddress: maciAddresses.maciContractAddress,
240
+ maciPublicKey: user.publicKey.serialize(),
241
+ sgData: constants_1.DEFAULT_SG_DATA,
242
+ signer,
243
+ });
244
+ });
245
+ it("should join one user", async () => {
246
+ await (0, sdk_1.joinPoll)({
247
+ maciAddress: maciAddresses.maciContractAddress,
248
+ privateKey: user.privateKey.serialize(),
249
+ pollId: 0n,
250
+ pollJoiningZkey: constants_1.testPollJoiningZkeyPath,
251
+ useWasm,
252
+ pollJoiningWasm: constants_1.testPollJoiningWasmPath,
253
+ pollWitnessGenerator: constants_1.testPollJoiningWitnessPath,
254
+ rapidsnark: constants_1.testRapidsnarkPath,
255
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
256
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
257
+ signer,
258
+ });
259
+ });
260
+ it("should publish two messages", async () => {
261
+ await (0, sdk_1.publish)({
262
+ publicKey: user.publicKey.serialize(),
263
+ stateIndex: 1n,
264
+ voteOptionIndex: 0n,
265
+ nonce: 1n,
266
+ pollId: 0n,
267
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
268
+ maciAddress: maciAddresses.maciContractAddress,
269
+ salt: (0, crypto_1.generateRandomSalt)(),
270
+ privateKey: user.privateKey.serialize(),
271
+ signer,
272
+ });
273
+ await (0, sdk_1.publish)({
274
+ publicKey: user.publicKey.serialize(),
275
+ stateIndex: 1n,
276
+ voteOptionIndex: 1n,
277
+ nonce: 1n,
278
+ pollId: 0n,
279
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
280
+ maciAddress: maciAddresses.maciContractAddress,
281
+ salt: (0, crypto_1.generateRandomSalt)(),
282
+ privateKey: user.privateKey.serialize(),
283
+ signer,
284
+ });
285
+ });
286
+ it("should generate zk-SNARK proofs and verify them", async () => {
287
+ await (0, sdk_1.timeTravel)({ seconds: constants_1.pollDuration, signer });
288
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
289
+ const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
290
+ ...generateProofsArgs,
291
+ signer,
292
+ maciAddress: maciAddresses.maciContractAddress,
293
+ mode: sdk_1.EMode.FULL,
294
+ });
295
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
296
+ await (0, sdk_1.verify)({
297
+ ...(await (0, constants_1.verifyArgs)(signer)),
298
+ tallyData: tallyFileData,
299
+ maciAddress: tallyFileData.maci,
300
+ });
301
+ (0, chai_1.expect)(tallyFileData.totalSpentVoiceCredits.spent.toString()).to.eq(constants_1.DEFAULT_INITIAL_VOICE_CREDITS.toString());
302
+ tallyFileData.results.tally.forEach((result, index) => {
303
+ (0, chai_1.expect)(result.toString()).to.eq(index === 1 ? constants_1.DEFAULT_INITIAL_VOICE_CREDITS.toString() : "0");
304
+ });
305
+ });
306
+ });
307
+ describe("1 signup, 2 valid and 2 invalid message", () => {
308
+ after(async () => {
309
+ await (0, utils_1.clean)();
310
+ });
311
+ const user = new domainobjs_1.Keypair();
312
+ before(async () => {
313
+ // deploy the smart contracts
314
+ maciAddresses = await prepareTest();
315
+ });
316
+ it("should signup one user", async () => {
317
+ await (0, sdk_1.signup)({
318
+ maciAddress: maciAddresses.maciContractAddress,
319
+ maciPublicKey: user.publicKey.serialize(),
320
+ sgData: constants_1.DEFAULT_SG_DATA,
321
+ signer,
322
+ });
323
+ });
324
+ it("should join one user", async () => {
325
+ await (0, sdk_1.joinPoll)({
326
+ maciAddress: maciAddresses.maciContractAddress,
327
+ privateKey: user.privateKey.serialize(),
328
+ pollId: 0n,
329
+ pollJoiningZkey: constants_1.testPollJoiningZkeyPath,
330
+ useWasm,
331
+ pollJoiningWasm: constants_1.testPollJoiningWasmPath,
332
+ pollWitnessGenerator: constants_1.testPollJoiningWitnessPath,
333
+ rapidsnark: constants_1.testRapidsnarkPath,
334
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
335
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
336
+ signer,
337
+ });
338
+ });
339
+ it("should publish two valid and two invalid messages", async () => {
340
+ await (0, sdk_1.publish)({
341
+ publicKey: user.publicKey.serialize(),
342
+ stateIndex: 1n,
343
+ voteOptionIndex: 0n,
344
+ nonce: 1n,
345
+ pollId: 0n,
346
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
347
+ maciAddress: maciAddresses.maciContractAddress,
348
+ salt: (0, crypto_1.generateRandomSalt)(),
349
+ privateKey: user.privateKey.serialize(),
350
+ signer,
351
+ });
352
+ await (0, sdk_1.publish)({
353
+ publicKey: user.publicKey.serialize(),
354
+ stateIndex: 1n,
355
+ voteOptionIndex: 1n,
356
+ nonce: 1n,
357
+ pollId: 0n,
358
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
359
+ maciAddress: maciAddresses.maciContractAddress,
360
+ salt: (0, crypto_1.generateRandomSalt)(),
361
+ privateKey: user.privateKey.serialize(),
362
+ signer,
363
+ });
364
+ await (0, sdk_1.publish)({
365
+ publicKey: user.publicKey.serialize(),
366
+ stateIndex: 1n,
367
+ voteOptionIndex: 1n,
368
+ nonce: 1n,
369
+ pollId: 0n,
370
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS - 10),
371
+ maciAddress: maciAddresses.maciContractAddress,
372
+ salt: (0, crypto_1.generateRandomSalt)(),
373
+ privateKey: user.privateKey.serialize(),
374
+ signer,
375
+ });
376
+ await (0, sdk_1.publish)({
377
+ publicKey: user.publicKey.serialize(),
378
+ stateIndex: 1n,
379
+ voteOptionIndex: 1n,
380
+ nonce: 1n,
381
+ pollId: 0n,
382
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS + 10),
383
+ maciAddress: maciAddresses.maciContractAddress,
384
+ salt: (0, crypto_1.generateRandomSalt)(),
385
+ privateKey: user.privateKey.serialize(),
386
+ signer,
387
+ });
388
+ });
389
+ it("should generate zk-SNARK proofs and verify them", async () => {
390
+ await (0, sdk_1.timeTravel)({ seconds: constants_1.pollDuration, signer });
391
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
392
+ const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
393
+ ...generateProofsArgs,
394
+ signer,
395
+ maciAddress: maciAddresses.maciContractAddress,
396
+ mode: sdk_1.EMode.FULL,
397
+ });
398
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
399
+ await (0, sdk_1.verify)({
400
+ ...(await (0, constants_1.verifyArgs)(signer)),
401
+ tallyData: tallyFileData,
402
+ maciAddress: tallyFileData.maci,
403
+ });
404
+ (0, chai_1.expect)(tallyFileData.totalSpentVoiceCredits.spent.toString()).to.eq(constants_1.DEFAULT_INITIAL_VOICE_CREDITS.toString());
405
+ tallyFileData.results.tally.forEach((result, index) => {
406
+ (0, chai_1.expect)(result.toString()).to.eq(index === 1 ? constants_1.DEFAULT_INITIAL_VOICE_CREDITS.toString() : "0");
407
+ });
408
+ });
409
+ });
410
+ describe("4 signups, 8 messages, 16 relayed messages", () => {
411
+ after(async () => {
412
+ await (0, utils_1.clean)();
413
+ });
414
+ const users = [new domainobjs_1.Keypair(), new domainobjs_1.Keypair(), new domainobjs_1.Keypair(), new domainobjs_1.Keypair()];
415
+ before(async () => {
416
+ // deploy the smart contracts
417
+ maciAddresses = await prepareTest();
418
+ });
419
+ it("should signup four users", async () => {
420
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
421
+ for (let i = 0; i < users.length; i += 1) {
422
+ // eslint-disable-next-line no-await-in-loop
423
+ await (0, sdk_1.signup)({
424
+ maciAddress: maciAddresses.maciContractAddress,
425
+ maciPublicKey: users[i].publicKey.serialize(),
426
+ sgData: constants_1.DEFAULT_SG_DATA,
427
+ signer,
428
+ });
429
+ }
430
+ });
431
+ it("should join four users", async () => {
432
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
433
+ for (let i = 0; i < users.length; i += 1) {
434
+ // eslint-disable-next-line no-await-in-loop
435
+ await (0, sdk_1.joinPoll)({
436
+ maciAddress: maciAddresses.maciContractAddress,
437
+ privateKey: users[i].privateKey.serialize(),
438
+ pollId: 0n,
439
+ pollJoiningZkey: constants_1.testPollJoiningZkeyPath,
440
+ useWasm,
441
+ pollJoiningWasm: constants_1.testPollJoiningWasmPath,
442
+ pollWitnessGenerator: constants_1.testPollJoiningWitnessPath,
443
+ rapidsnark: constants_1.testRapidsnarkPath,
444
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
445
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
446
+ signer,
447
+ });
448
+ }
449
+ });
450
+ it("should publish eight messages", async () => {
451
+ await (0, sdk_1.publish)({
452
+ publicKey: users[0].publicKey.serialize(),
453
+ stateIndex: 1n,
454
+ voteOptionIndex: 0n,
455
+ nonce: 2n,
456
+ pollId: 0n,
457
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
458
+ maciAddress: maciAddresses.maciContractAddress,
459
+ salt: (0, crypto_1.generateRandomSalt)(),
460
+ privateKey: users[0].privateKey.serialize(),
461
+ signer,
462
+ });
463
+ await (0, sdk_1.publish)({
464
+ publicKey: users[0].publicKey.serialize(),
465
+ stateIndex: 1n,
466
+ voteOptionIndex: 0n,
467
+ nonce: 2n,
468
+ pollId: 0n,
469
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
470
+ maciAddress: maciAddresses.maciContractAddress,
471
+ salt: (0, crypto_1.generateRandomSalt)(),
472
+ privateKey: users[0].privateKey.serialize(),
473
+ signer,
474
+ });
475
+ await (0, sdk_1.publish)({
476
+ publicKey: users[0].publicKey.serialize(),
477
+ stateIndex: 1n,
478
+ voteOptionIndex: 0n,
479
+ nonce: 1n,
480
+ pollId: 0n,
481
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
482
+ maciAddress: maciAddresses.maciContractAddress,
483
+ salt: (0, crypto_1.generateRandomSalt)(),
484
+ privateKey: users[0].privateKey.serialize(),
485
+ signer,
486
+ });
487
+ await (0, sdk_1.publish)({
488
+ publicKey: users[1].publicKey.serialize(),
489
+ stateIndex: 2n,
490
+ voteOptionIndex: 2n,
491
+ nonce: 1n,
492
+ pollId: 0n,
493
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
494
+ maciAddress: maciAddresses.maciContractAddress,
495
+ salt: (0, crypto_1.generateRandomSalt)(),
496
+ privateKey: users[1].privateKey.serialize(),
497
+ signer,
498
+ });
499
+ await (0, sdk_1.publish)({
500
+ publicKey: users[2].publicKey.serialize(),
501
+ stateIndex: 3n,
502
+ voteOptionIndex: 2n,
503
+ nonce: 1n,
504
+ pollId: 0n,
505
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
506
+ maciAddress: maciAddresses.maciContractAddress,
507
+ salt: (0, crypto_1.generateRandomSalt)(),
508
+ privateKey: users[2].privateKey.serialize(),
509
+ signer,
510
+ });
511
+ await (0, sdk_1.publish)({
512
+ publicKey: users[3].publicKey.serialize(),
513
+ stateIndex: 4n,
514
+ voteOptionIndex: 2n,
515
+ nonce: 3n,
516
+ pollId: 0n,
517
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
518
+ maciAddress: maciAddresses.maciContractAddress,
519
+ salt: (0, crypto_1.generateRandomSalt)(),
520
+ privateKey: users[3].privateKey.serialize(),
521
+ signer,
522
+ });
523
+ await (0, sdk_1.publish)({
524
+ publicKey: users[3].publicKey.serialize(),
525
+ stateIndex: 4n,
526
+ voteOptionIndex: 2n,
527
+ nonce: 2n,
528
+ pollId: 0n,
529
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
530
+ maciAddress: maciAddresses.maciContractAddress,
531
+ salt: (0, crypto_1.generateRandomSalt)(),
532
+ privateKey: users[3].privateKey.serialize(),
533
+ signer,
534
+ });
535
+ await (0, sdk_1.publish)({
536
+ publicKey: users[3].publicKey.serialize(),
537
+ stateIndex: 4n,
538
+ voteOptionIndex: 1n,
539
+ nonce: 1n,
540
+ pollId: 0n,
541
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
542
+ maciAddress: maciAddresses.maciContractAddress,
543
+ salt: (0, crypto_1.generateRandomSalt)(),
544
+ privateKey: users[3].privateKey.serialize(),
545
+ signer,
546
+ });
547
+ });
548
+ it("should relay sixteen messages", async () => {
549
+ const votes = [
550
+ {
551
+ pollId: 0n,
552
+ voteOptionIndex: 1n,
553
+ salt: (0, crypto_1.generateRandomSalt)(),
554
+ nonce: 2n,
555
+ privateKey: users[0].privateKey,
556
+ stateIndex: 1n,
557
+ voteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
558
+ coordinatorPublicKey: constants_1.coordinatorKeypair.publicKey,
559
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
560
+ newPublicKey: users[0].publicKey,
561
+ },
562
+ {
563
+ pollId: 0n,
564
+ voteOptionIndex: 1n,
565
+ salt: (0, crypto_1.generateRandomSalt)(),
566
+ nonce: 2n,
567
+ privateKey: users[0].privateKey,
568
+ stateIndex: 1n,
569
+ voteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
570
+ coordinatorPublicKey: constants_1.coordinatorKeypair.publicKey,
571
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
572
+ newPublicKey: users[0].publicKey,
573
+ },
574
+ {
575
+ pollId: 0n,
576
+ voteOptionIndex: 1n,
577
+ salt: (0, crypto_1.generateRandomSalt)(),
578
+ nonce: 1n,
579
+ privateKey: users[0].privateKey,
580
+ stateIndex: 1n,
581
+ voteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
582
+ coordinatorPublicKey: constants_1.coordinatorKeypair.publicKey,
583
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
584
+ newPublicKey: users[0].publicKey,
585
+ },
586
+ {
587
+ pollId: 0n,
588
+ voteOptionIndex: 1n,
589
+ salt: (0, crypto_1.generateRandomSalt)(),
590
+ nonce: 1n,
591
+ privateKey: users[1].privateKey,
592
+ stateIndex: 2n,
593
+ voteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
594
+ coordinatorPublicKey: constants_1.coordinatorKeypair.publicKey,
595
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
596
+ newPublicKey: users[1].publicKey,
597
+ },
598
+ {
599
+ pollId: 0n,
600
+ voteOptionIndex: 1n,
601
+ salt: (0, crypto_1.generateRandomSalt)(),
602
+ nonce: 1n,
603
+ privateKey: users[2].privateKey,
604
+ stateIndex: 3n,
605
+ voteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
606
+ coordinatorPublicKey: constants_1.coordinatorKeypair.publicKey,
607
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
608
+ newPublicKey: users[2].publicKey,
609
+ },
610
+ {
611
+ pollId: 0n,
612
+ voteOptionIndex: 0n,
613
+ salt: (0, crypto_1.generateRandomSalt)(),
614
+ nonce: 3n,
615
+ privateKey: users[3].privateKey,
616
+ stateIndex: 4n,
617
+ voteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
618
+ coordinatorPublicKey: constants_1.coordinatorKeypair.publicKey,
619
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
620
+ newPublicKey: users[3].publicKey,
621
+ },
622
+ {
623
+ pollId: 0n,
624
+ voteOptionIndex: 0n,
625
+ salt: (0, crypto_1.generateRandomSalt)(),
626
+ nonce: 2n,
627
+ privateKey: users[3].privateKey,
628
+ stateIndex: 4n,
629
+ voteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
630
+ coordinatorPublicKey: constants_1.coordinatorKeypair.publicKey,
631
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
632
+ newPublicKey: users[3].publicKey,
633
+ },
634
+ {
635
+ pollId: 0n,
636
+ voteOptionIndex: 0n,
637
+ salt: (0, crypto_1.generateRandomSalt)(),
638
+ nonce: 1n,
639
+ privateKey: users[3].privateKey,
640
+ stateIndex: 4n,
641
+ voteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
642
+ coordinatorPublicKey: constants_1.coordinatorKeypair.publicKey,
643
+ maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
644
+ newPublicKey: users[3].publicKey,
645
+ },
646
+ ];
647
+ const messages = votes
648
+ .map((vote) => (0, sdk_1.generateVote)(vote))
649
+ .map(({ message, ephemeralKeypair }) => ({
650
+ maciAddress: maciAddresses.maciContractAddress,
651
+ poll: 0,
652
+ data: message.data.map(String),
653
+ publicKey: ephemeralKeypair.publicKey.asArray().map(String),
654
+ hash: message.hash(ephemeralKeypair.publicKey).toString(),
655
+ }));
656
+ await (0, utils_1.relayTestMessages)({ messages, signer, pollId: 0, maciAddress: maciAddresses.maciContractAddress });
657
+ });
658
+ it("should generate zk-SNARK proofs and verify them", async () => {
659
+ const ipfsMessageBackupFiles = await (0, utils_1.getBackupFilenames)();
660
+ await (0, sdk_1.timeTravel)({ seconds: constants_1.pollDuration, signer });
661
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
662
+ const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
663
+ ...generateProofsArgs,
664
+ signer,
665
+ maciAddress: maciAddresses.maciContractAddress,
666
+ ipfsMessageBackupFiles,
667
+ });
668
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
669
+ await (0, sdk_1.verify)({ ...(await (0, constants_1.verifyArgs)(signer)) });
670
+ (0, chai_1.expect)(tallyFileData.totalSpentVoiceCredits.spent.toString()).to.eq((constants_1.DEFAULT_INITIAL_VOICE_CREDITS * users.length).toString());
671
+ (0, chai_1.expect)(tallyFileData.results.tally[0].toString()).to.eq("100");
672
+ (0, chai_1.expect)(tallyFileData.results.tally[1].toString()).to.eq("300");
673
+ tallyFileData.results.tally.forEach((result, index) => {
674
+ if (index > 1) {
675
+ (0, chai_1.expect)(result).to.eq("0");
676
+ }
677
+ });
678
+ });
679
+ });
680
+ describe("30 signups (31 ballots), 30 messages", () => {
681
+ after(async () => {
682
+ await (0, utils_1.clean)();
683
+ });
684
+ const users = Array.from({ length: 30 }, () => new domainobjs_1.Keypair());
685
+ before(async () => {
686
+ // deploy the smart contracts
687
+ maciAddresses = await prepareTest();
688
+ });
689
+ it("should signup thirty users", async () => {
690
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
691
+ for (let i = 0; i < users.length; i += 1) {
692
+ // eslint-disable-next-line no-await-in-loop
693
+ await (0, sdk_1.signup)({
694
+ maciAddress: maciAddresses.maciContractAddress,
695
+ maciPublicKey: users[i].publicKey.serialize(),
696
+ sgData: constants_1.DEFAULT_SG_DATA,
697
+ signer,
698
+ });
699
+ }
700
+ });
701
+ it("should join thirty users", async () => {
702
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
703
+ for (let i = 0; i < users.length; i += 1) {
704
+ // eslint-disable-next-line no-await-in-loop
705
+ await (0, sdk_1.joinPoll)({
706
+ maciAddress: maciAddresses.maciContractAddress,
707
+ privateKey: users[i].privateKey.serialize(),
708
+ pollId: 0n,
709
+ pollJoiningZkey: constants_1.testPollJoiningZkeyPath,
710
+ useWasm,
711
+ pollJoiningWasm: constants_1.testPollJoiningWasmPath,
712
+ pollWitnessGenerator: constants_1.testPollJoiningWitnessPath,
713
+ rapidsnark: constants_1.testRapidsnarkPath,
714
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
715
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
716
+ signer,
717
+ });
718
+ }
719
+ });
720
+ it("should publish 30 messages", async () => {
721
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
722
+ for (let i = 0; i < users.length; i += 1) {
723
+ // eslint-disable-next-line no-await-in-loop
724
+ await (0, sdk_1.publish)({
725
+ maciAddress: maciAddresses.maciContractAddress,
726
+ publicKey: users[i].publicKey.serialize(),
727
+ stateIndex: BigInt(i + 1),
728
+ voteOptionIndex: 0n,
729
+ nonce: 1n,
730
+ pollId: 0n,
731
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
732
+ salt: (0, crypto_1.generateRandomSalt)(),
733
+ privateKey: users[i].privateKey.serialize(),
734
+ signer,
735
+ });
736
+ }
737
+ });
738
+ it("should generate zk-SNARK proofs and verify them", async () => {
739
+ await (0, sdk_1.timeTravel)({ seconds: constants_1.pollDuration, signer });
740
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
741
+ const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
742
+ ...generateProofsArgs,
743
+ maciAddress: maciAddresses.maciContractAddress,
744
+ signer,
745
+ });
746
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
747
+ await (0, sdk_1.verify)({ ...(await (0, constants_1.verifyArgs)(signer)), tallyData: tallyFileData });
748
+ const totalSpent = (constants_1.DEFAULT_INITIAL_VOICE_CREDITS * users.length).toString();
749
+ (0, chai_1.expect)(tallyFileData.totalSpentVoiceCredits.spent.toString()).to.eq(totalSpent);
750
+ (0, chai_1.expect)(tallyFileData.results.tally[0].toString()).to.eq(totalSpent);
751
+ });
752
+ });
753
+ describe("30 signups, 20 invalid and 1 valid messages", () => {
754
+ after(async () => {
755
+ await (0, utils_1.clean)();
756
+ });
757
+ const users = Array.from({ length: 30 }, () => new domainobjs_1.Keypair());
758
+ before(async () => {
759
+ // deploy the smart contracts
760
+ maciAddresses = await prepareTest();
761
+ });
762
+ it("should signup thirty users", async () => {
763
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
764
+ for (let i = 0; i < users.length; i += 1) {
765
+ // eslint-disable-next-line no-await-in-loop
766
+ await (0, sdk_1.signup)({
767
+ maciAddress: maciAddresses.maciContractAddress,
768
+ maciPublicKey: users[i].publicKey.serialize(),
769
+ sgData: constants_1.DEFAULT_SG_DATA,
770
+ signer,
771
+ });
772
+ }
773
+ });
774
+ it("should join thirty users", async () => {
775
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
776
+ for (let i = 0; i < users.length; i += 1) {
777
+ // eslint-disable-next-line no-await-in-loop
778
+ await (0, sdk_1.joinPoll)({
779
+ maciAddress: maciAddresses.maciContractAddress,
780
+ privateKey: users[i].privateKey.serialize(),
781
+ pollId: 0n,
782
+ pollJoiningZkey: constants_1.testPollJoiningZkeyPath,
783
+ useWasm,
784
+ pollJoiningWasm: constants_1.testPollJoiningWasmPath,
785
+ pollWitnessGenerator: constants_1.testPollJoiningWitnessPath,
786
+ rapidsnark: constants_1.testRapidsnarkPath,
787
+ sgDataArg: constants_1.DEFAULT_SG_DATA,
788
+ ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
789
+ signer,
790
+ });
791
+ }
792
+ });
793
+ it("should publish 30 invalid and 1 valid messages", async () => {
794
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
795
+ for (let i = 0; i < users.length; i += 1) {
796
+ // eslint-disable-next-line no-await-in-loop
797
+ await (0, sdk_1.publish)({
798
+ maciAddress: maciAddresses.maciContractAddress,
799
+ publicKey: users[i].publicKey.serialize(),
800
+ stateIndex: BigInt(i + 1),
801
+ voteOptionIndex: 0n,
802
+ nonce: 1n,
803
+ pollId: 0n,
804
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS + 10),
805
+ salt: (0, crypto_1.generateRandomSalt)(),
806
+ privateKey: users[i].privateKey.serialize(),
807
+ signer,
808
+ });
809
+ }
810
+ await (0, sdk_1.publish)({
811
+ maciAddress: maciAddresses.maciContractAddress,
812
+ publicKey: users[0].publicKey.serialize(),
813
+ stateIndex: 1n,
814
+ voteOptionIndex: 0n,
815
+ nonce: 1n,
816
+ pollId: 0n,
817
+ newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
818
+ salt: (0, crypto_1.generateRandomSalt)(),
819
+ privateKey: users[0].privateKey.serialize(),
820
+ signer,
821
+ });
822
+ });
823
+ it("should generate zk-SNARK proofs and verify them", async () => {
824
+ await (0, sdk_1.timeTravel)({ seconds: constants_1.pollDuration, signer });
825
+ await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
826
+ const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
827
+ ...generateProofsArgs,
828
+ maciAddress: maciAddresses.maciContractAddress,
829
+ signer,
830
+ });
831
+ await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
832
+ await (0, sdk_1.verify)({ ...(await (0, constants_1.verifyArgs)(signer)), tallyData: tallyFileData });
833
+ const totalSpent = constants_1.DEFAULT_INITIAL_VOICE_CREDITS.toString();
834
+ (0, chai_1.expect)(tallyFileData.totalSpentVoiceCredits.spent.toString()).to.eq(totalSpent);
835
+ (0, chai_1.expect)(tallyFileData.results.tally[0].toString()).to.eq(totalSpent);
836
+ });
837
+ });
838
+ });
839
+ //# sourceMappingURL=e2e.full.test.js.map