@maci-protocol/testing 0.0.0-ci.cf26211 → 0.0.0-ci.cf2cc5b
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.
- package/LICENSE +1 -2
- package/build/hardhat.config.js +1 -1
- package/build/hardhat.config.js.map +1 -1
- package/build/ts/__tests__/e2e.full.test.d.ts +2 -0
- package/build/ts/__tests__/e2e.full.test.d.ts.map +1 -0
- package/build/ts/__tests__/e2e.full.test.js +842 -0
- package/build/ts/__tests__/e2e.full.test.js.map +1 -0
- package/build/ts/__tests__/e2e.nonQv.test.js +442 -42
- package/build/ts/__tests__/e2e.nonQv.test.js.map +1 -1
- package/build/ts/__tests__/e2e.test.js +337 -326
- package/build/ts/__tests__/e2e.test.js.map +1 -1
- package/build/ts/__tests__/integration.test.js +73 -75
- package/build/ts/__tests__/integration.test.js.map +1 -1
- package/build/ts/__tests__/keyChange.test.js +88 -86
- package/build/ts/__tests__/keyChange.test.js.map +1 -1
- package/build/ts/__tests__/maciKeys.test.js +41 -41
- package/build/ts/__tests__/maciKeys.test.js.map +1 -1
- package/build/ts/__tests__/stress/stress.full.test.d.ts +2 -0
- package/build/ts/__tests__/stress/stress.full.test.d.ts.map +1 -0
- package/build/ts/__tests__/stress/stress.full.test.js +189 -0
- package/build/ts/__tests__/stress/stress.full.test.js.map +1 -0
- package/build/ts/__tests__/unit/joinPoll.test.js +75 -37
- package/build/ts/__tests__/unit/joinPoll.test.js.map +1 -1
- package/build/ts/__tests__/unit/poll.test.js +9 -11
- package/build/ts/__tests__/unit/poll.test.js.map +1 -1
- package/build/ts/__tests__/unit/publish.test.js +12 -14
- package/build/ts/__tests__/unit/publish.test.js.map +1 -1
- package/build/ts/__tests__/unit/setVerifyingKeys.test.d.ts +2 -0
- package/build/ts/__tests__/unit/setVerifyingKeys.test.d.ts.map +1 -0
- package/build/ts/__tests__/unit/setVerifyingKeys.test.js +52 -0
- package/build/ts/__tests__/unit/setVerifyingKeys.test.js.map +1 -0
- package/build/ts/__tests__/unit/signup.test.js +11 -9
- package/build/ts/__tests__/unit/signup.test.js.map +1 -1
- package/build/ts/__tests__/unit/utils.test.js +12 -12
- package/build/ts/__tests__/unit/utils.test.js.map +1 -1
- package/build/ts/constants.d.ts +53 -55
- package/build/ts/constants.d.ts.map +1 -1
- package/build/ts/constants.js +113 -74
- package/build/ts/constants.js.map +1 -1
- package/build/ts/testingClass.d.ts +9 -9
- package/build/ts/testingClass.d.ts.map +1 -1
- package/build/ts/testingClass.js +39 -38
- package/build/ts/testingClass.js.map +1 -1
- package/build/ts/types.d.ts +12 -13
- package/build/ts/types.d.ts.map +1 -1
- package/build/ts/user.d.ts +2 -2
- package/build/ts/user.d.ts.map +1 -1
- package/build/ts/user.js +1 -1
- package/build/ts/user.js.map +1 -1
- package/build/ts/utils.d.ts +3 -3
- package/build/ts/utils.d.ts.map +1 -1
- package/build/ts/utils.js +12 -12
- package/build/ts/utils.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -18
|
@@ -1,60 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const contracts_1 = require("@maci-protocol/contracts");
|
|
3
4
|
const core_1 = require("@maci-protocol/core");
|
|
4
5
|
const crypto_1 = require("@maci-protocol/crypto");
|
|
5
6
|
const domainobjs_1 = require("@maci-protocol/domainobjs");
|
|
6
7
|
const sdk_1 = require("@maci-protocol/sdk");
|
|
8
|
+
const chai_1 = require("chai");
|
|
7
9
|
const constants_1 = require("../constants");
|
|
8
10
|
const utils_1 = require("../utils");
|
|
9
11
|
/**
|
|
10
12
|
Test scenarios:
|
|
11
13
|
1 signup, 1 message with quadratic voting disabled
|
|
12
14
|
1 signup, 1 relayed message
|
|
15
|
+
1 signup, 2 valid messages
|
|
16
|
+
1 signup, 2 valid and 2 invalid messages
|
|
17
|
+
2 signups, 2 different messages
|
|
13
18
|
*/
|
|
14
19
|
describe("e2e tests with non quadratic voting", function test() {
|
|
15
20
|
const useWasm = (0, sdk_1.isArm)();
|
|
16
21
|
this.timeout(900000);
|
|
17
22
|
let maciAddresses;
|
|
18
23
|
let initialVoiceCreditProxyContractAddress;
|
|
19
|
-
let verifierContractAddress;
|
|
20
24
|
let signer;
|
|
21
|
-
let
|
|
25
|
+
let userSigners;
|
|
22
26
|
const generateProofsArgs = {
|
|
23
27
|
outputDir: constants_1.testProofsDirPath,
|
|
24
28
|
tallyFile: constants_1.testTallyFilePath,
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
voteTallyZkey: constants_1.testVoteTallyNonQvZkeyPath,
|
|
30
|
+
messageProcessorZkey: constants_1.testProcessMessageNonQvZkeyPath,
|
|
27
31
|
pollId: 0n,
|
|
28
32
|
rapidsnark: constants_1.testRapidsnarkPath,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
coordinatorPrivateKey: constants_1.
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
messageProcessorWitnessGenerator: constants_1.testProcessMessagesNonQvWitnessPath,
|
|
34
|
+
messageProcessorWitnessDatFile: constants_1.testProcessMessagesNonQvWitnessDatPath,
|
|
35
|
+
voteTallyWitnessGenerator: constants_1.testVoteTallyNonQvWitnessPath,
|
|
36
|
+
voteTallyWitnessDatFile: constants_1.testVoteTallyNonQvWitnessDatPath,
|
|
37
|
+
coordinatorPrivateKey: constants_1.coordinatorPrivateKey,
|
|
38
|
+
messageProcessorWasm: constants_1.testProcessMessagesNonQvWasmPath,
|
|
39
|
+
voteTallyWasm: constants_1.testVoteTallyNonQvWasmPath,
|
|
36
40
|
useWasm,
|
|
37
|
-
|
|
41
|
+
mode: sdk_1.EMode.NON_QV,
|
|
38
42
|
};
|
|
39
|
-
// before all tests we deploy the
|
|
43
|
+
// before all tests we deploy the verifying keys registry contract and set the verifying keys
|
|
40
44
|
before(async () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
+
const signers = await (0, contracts_1.getSigners)();
|
|
46
|
+
[signer, ...userSigners] = signers;
|
|
47
|
+
const constantInitialVoiceCreditProxyFactory = await (0, sdk_1.deployConstantInitialVoiceCreditProxyFactory)(signer, true);
|
|
48
|
+
const initialVoiceCreditProxy = await (0, sdk_1.deployConstantInitialVoiceCreditProxy)({ amount: constants_1.DEFAULT_INITIAL_VOICE_CREDITS }, constantInitialVoiceCreditProxyFactory, signer);
|
|
45
49
|
initialVoiceCreditProxyContractAddress = await initialVoiceCreditProxy.getAddress();
|
|
46
|
-
const verifier = await (0, sdk_1.deployVerifier)(signer, true);
|
|
47
|
-
verifierContractAddress = await verifier.getAddress();
|
|
48
|
-
// we deploy the vk registry contract
|
|
49
|
-
vkRegistryAddress = await (0, sdk_1.deployVkRegistryContract)({ signer });
|
|
50
|
-
// we set the verifying keys
|
|
51
|
-
await (0, sdk_1.setVerifyingKeys)({ ...(await (0, constants_1.verifyingKeysArgs)(signer, sdk_1.EMode.NON_QV)), vkRegistryAddress });
|
|
52
50
|
});
|
|
53
51
|
describe("1 signup, 1 message", () => {
|
|
54
52
|
after(async () => {
|
|
55
53
|
await (0, utils_1.clean)();
|
|
56
54
|
});
|
|
57
55
|
const user = new domainobjs_1.Keypair();
|
|
56
|
+
const voteWeight = 9n;
|
|
58
57
|
before(async () => {
|
|
59
58
|
const [signupPolicy, , signupPolicyFactory, signupCheckerFactory] = await (0, sdk_1.deployFreeForAllSignUpPolicy)({}, signer, true);
|
|
60
59
|
const signupPolicyContractAddress = await signupPolicy.getAddress();
|
|
@@ -66,6 +65,12 @@ describe("e2e tests with non quadratic voting", function test() {
|
|
|
66
65
|
signer,
|
|
67
66
|
signupPolicyAddress: signupPolicyContractAddress,
|
|
68
67
|
});
|
|
68
|
+
// we set the verifying keys
|
|
69
|
+
const { verifyingKeysRegistryContractAddress } = maciAddresses;
|
|
70
|
+
await (0, sdk_1.setVerifyingKeys)({
|
|
71
|
+
...(await (0, constants_1.verifyingKeysArgs)(signer, [sdk_1.EMode.NON_QV])),
|
|
72
|
+
verifyingKeysRegistryAddress: verifyingKeysRegistryContractAddress,
|
|
73
|
+
});
|
|
69
74
|
const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
|
|
70
75
|
// deploy a poll contract
|
|
71
76
|
await (0, sdk_1.deployPoll)({
|
|
@@ -75,8 +80,6 @@ describe("e2e tests with non quadratic voting", function test() {
|
|
|
75
80
|
pollEndTimestamp: startDate + constants_1.pollDuration,
|
|
76
81
|
relayers: [await signer.getAddress()],
|
|
77
82
|
maciAddress: maciAddresses.maciContractAddress,
|
|
78
|
-
verifierContractAddress,
|
|
79
|
-
vkRegistryContractAddress: vkRegistryAddress,
|
|
80
83
|
policyContractAddress: pollPolicyContractAddress,
|
|
81
84
|
initialVoiceCreditProxyContractAddress,
|
|
82
85
|
mode: sdk_1.EMode.NON_QV,
|
|
@@ -85,22 +88,37 @@ describe("e2e tests with non quadratic voting", function test() {
|
|
|
85
88
|
it("should signup one user", async () => {
|
|
86
89
|
await (0, sdk_1.signup)({
|
|
87
90
|
maciAddress: maciAddresses.maciContractAddress,
|
|
88
|
-
|
|
91
|
+
maciPublicKey: user.publicKey.serialize(),
|
|
89
92
|
sgData: constants_1.DEFAULT_SG_DATA,
|
|
90
93
|
signer,
|
|
91
94
|
});
|
|
92
95
|
});
|
|
96
|
+
it("should join one user", async () => {
|
|
97
|
+
await (0, sdk_1.joinPoll)({
|
|
98
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
99
|
+
privateKey: user.privateKey.serialize(),
|
|
100
|
+
pollId: 0n,
|
|
101
|
+
pollJoiningZkey: constants_1.testPollJoiningZkeyPath,
|
|
102
|
+
useWasm,
|
|
103
|
+
pollJoiningWasm: constants_1.testPollJoiningWasmPath,
|
|
104
|
+
pollWitnessGenerator: constants_1.testPollJoiningWitnessPath,
|
|
105
|
+
rapidsnark: constants_1.testRapidsnarkPath,
|
|
106
|
+
sgDataArg: constants_1.DEFAULT_SG_DATA,
|
|
107
|
+
ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
|
|
108
|
+
signer,
|
|
109
|
+
});
|
|
110
|
+
});
|
|
93
111
|
it("should publish one message", async () => {
|
|
94
112
|
await (0, sdk_1.publish)({
|
|
95
|
-
|
|
113
|
+
publicKey: user.publicKey.serialize(),
|
|
96
114
|
stateIndex: 1n,
|
|
97
115
|
voteOptionIndex: 0n,
|
|
98
116
|
nonce: 1n,
|
|
99
117
|
pollId: 0n,
|
|
100
|
-
newVoteWeight:
|
|
118
|
+
newVoteWeight: voteWeight,
|
|
101
119
|
maciAddress: maciAddresses.maciContractAddress,
|
|
102
|
-
salt: (0, crypto_1.
|
|
103
|
-
privateKey: user.
|
|
120
|
+
salt: (0, crypto_1.generateRandomSalt)(),
|
|
121
|
+
privateKey: user.privateKey.serialize(),
|
|
104
122
|
signer,
|
|
105
123
|
});
|
|
106
124
|
});
|
|
@@ -111,7 +129,7 @@ describe("e2e tests with non quadratic voting", function test() {
|
|
|
111
129
|
...generateProofsArgs,
|
|
112
130
|
signer,
|
|
113
131
|
maciAddress: maciAddresses.maciContractAddress,
|
|
114
|
-
|
|
132
|
+
mode: sdk_1.EMode.NON_QV,
|
|
115
133
|
});
|
|
116
134
|
await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
|
|
117
135
|
await (0, sdk_1.verify)({
|
|
@@ -119,6 +137,10 @@ describe("e2e tests with non quadratic voting", function test() {
|
|
|
119
137
|
tallyData: tallyFileData,
|
|
120
138
|
maciAddress: tallyFileData.maci,
|
|
121
139
|
});
|
|
140
|
+
(0, chai_1.expect)(tallyFileData.totalSpentVoiceCredits.spent.toString()).to.eq(voteWeight.toString());
|
|
141
|
+
tallyFileData.results.tally.forEach((result, index) => {
|
|
142
|
+
(0, chai_1.expect)(result.toString()).to.eq(index === 0 ? voteWeight.toString() : "0");
|
|
143
|
+
});
|
|
122
144
|
});
|
|
123
145
|
});
|
|
124
146
|
describe("1 signup, 1 relayed message", () => {
|
|
@@ -126,6 +148,7 @@ describe("e2e tests with non quadratic voting", function test() {
|
|
|
126
148
|
await (0, utils_1.clean)();
|
|
127
149
|
});
|
|
128
150
|
const user = new domainobjs_1.Keypair();
|
|
151
|
+
const voteWeight = 9n;
|
|
129
152
|
before(async () => {
|
|
130
153
|
const [signupPolicy, , signupPolicyFactory, signupCheckerFactory] = await (0, sdk_1.deployFreeForAllSignUpPolicy)({}, signer, true);
|
|
131
154
|
const signupPolicyContractAddress = await signupPolicy.getAddress();
|
|
@@ -137,6 +160,12 @@ describe("e2e tests with non quadratic voting", function test() {
|
|
|
137
160
|
signer,
|
|
138
161
|
signupPolicyAddress: signupPolicyContractAddress,
|
|
139
162
|
});
|
|
163
|
+
// we set the verifying keys
|
|
164
|
+
const { verifyingKeysRegistryContractAddress } = maciAddresses;
|
|
165
|
+
await (0, sdk_1.setVerifyingKeys)({
|
|
166
|
+
...(await (0, constants_1.verifyingKeysArgs)(signer, [sdk_1.EMode.NON_QV])),
|
|
167
|
+
verifyingKeysRegistryAddress: verifyingKeysRegistryContractAddress,
|
|
168
|
+
});
|
|
140
169
|
const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
|
|
141
170
|
// deploy a poll contract
|
|
142
171
|
await (0, sdk_1.deployPoll)({
|
|
@@ -146,8 +175,6 @@ describe("e2e tests with non quadratic voting", function test() {
|
|
|
146
175
|
pollEndTimestamp: startDate + constants_1.pollDuration,
|
|
147
176
|
relayers: [await signer.getAddress()],
|
|
148
177
|
maciAddress: maciAddresses.maciContractAddress,
|
|
149
|
-
verifierContractAddress,
|
|
150
|
-
vkRegistryContractAddress: vkRegistryAddress,
|
|
151
178
|
policyContractAddress: pollPolicyContractAddress,
|
|
152
179
|
initialVoiceCreditProxyContractAddress,
|
|
153
180
|
mode: sdk_1.EMode.NON_QV,
|
|
@@ -156,31 +183,46 @@ describe("e2e tests with non quadratic voting", function test() {
|
|
|
156
183
|
it("should signup one user", async () => {
|
|
157
184
|
await (0, sdk_1.signup)({
|
|
158
185
|
maciAddress: maciAddresses.maciContractAddress,
|
|
159
|
-
|
|
186
|
+
maciPublicKey: user.publicKey.serialize(),
|
|
160
187
|
sgData: constants_1.DEFAULT_SG_DATA,
|
|
161
188
|
signer,
|
|
162
189
|
});
|
|
163
190
|
});
|
|
191
|
+
it("should join one user", async () => {
|
|
192
|
+
await (0, sdk_1.joinPoll)({
|
|
193
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
194
|
+
privateKey: user.privateKey.serialize(),
|
|
195
|
+
pollId: 0n,
|
|
196
|
+
pollJoiningZkey: constants_1.testPollJoiningZkeyPath,
|
|
197
|
+
useWasm,
|
|
198
|
+
pollJoiningWasm: constants_1.testPollJoiningWasmPath,
|
|
199
|
+
pollWitnessGenerator: constants_1.testPollJoiningWitnessPath,
|
|
200
|
+
rapidsnark: constants_1.testRapidsnarkPath,
|
|
201
|
+
sgDataArg: constants_1.DEFAULT_SG_DATA,
|
|
202
|
+
ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
|
|
203
|
+
signer,
|
|
204
|
+
});
|
|
205
|
+
});
|
|
164
206
|
it("should relay one message", async () => {
|
|
165
207
|
const { message, ephemeralKeypair } = (0, sdk_1.generateVote)({
|
|
166
208
|
pollId: 0n,
|
|
167
209
|
voteOptionIndex: 0n,
|
|
168
|
-
salt: (0, crypto_1.
|
|
210
|
+
salt: (0, crypto_1.generateRandomSalt)(),
|
|
169
211
|
nonce: 1n,
|
|
170
|
-
privateKey: user.
|
|
212
|
+
privateKey: user.privateKey,
|
|
171
213
|
stateIndex: 1n,
|
|
172
|
-
voteWeight
|
|
173
|
-
|
|
214
|
+
voteWeight,
|
|
215
|
+
coordinatorPublicKey: constants_1.coordinatorKeypair.publicKey,
|
|
174
216
|
maxVoteOption: BigInt(core_1.VOTE_OPTION_TREE_ARITY ** constants_1.deployPollArgs.voteOptionTreeDepth),
|
|
175
|
-
|
|
217
|
+
newPublicKey: user.publicKey,
|
|
176
218
|
});
|
|
177
219
|
const messages = [
|
|
178
220
|
{
|
|
179
221
|
maciAddress: maciAddresses.maciContractAddress,
|
|
180
222
|
poll: 0,
|
|
181
223
|
data: message.data.map(String),
|
|
182
|
-
publicKey: ephemeralKeypair.
|
|
183
|
-
hash: message.hash(ephemeralKeypair.
|
|
224
|
+
publicKey: ephemeralKeypair.publicKey.asArray().map(String),
|
|
225
|
+
hash: message.hash(ephemeralKeypair.publicKey).toString(),
|
|
184
226
|
},
|
|
185
227
|
];
|
|
186
228
|
await (0, utils_1.relayTestMessages)({ messages, signer, pollId: 0, maciAddress: maciAddresses.maciContractAddress });
|
|
@@ -194,7 +236,244 @@ describe("e2e tests with non quadratic voting", function test() {
|
|
|
194
236
|
signer,
|
|
195
237
|
maciAddress: maciAddresses.maciContractAddress,
|
|
196
238
|
ipfsMessageBackupFiles,
|
|
197
|
-
|
|
239
|
+
mode: sdk_1.EMode.NON_QV,
|
|
240
|
+
});
|
|
241
|
+
await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
|
|
242
|
+
await (0, sdk_1.verify)({
|
|
243
|
+
...(await (0, constants_1.verifyArgs)(signer)),
|
|
244
|
+
tallyData: tallyFileData,
|
|
245
|
+
maciAddress: tallyFileData.maci,
|
|
246
|
+
});
|
|
247
|
+
(0, chai_1.expect)(tallyFileData.totalSpentVoiceCredits.spent.toString()).to.eq(voteWeight.toString());
|
|
248
|
+
tallyFileData.results.tally.forEach((result, index) => {
|
|
249
|
+
(0, chai_1.expect)(result.toString()).to.eq(index === 0 ? voteWeight.toString() : "0");
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
describe("1 signup, 2 valid messages", () => {
|
|
254
|
+
after(async () => {
|
|
255
|
+
await (0, utils_1.clean)();
|
|
256
|
+
});
|
|
257
|
+
const user = new domainobjs_1.Keypair();
|
|
258
|
+
before(async () => {
|
|
259
|
+
const [signupPolicy, , signupPolicyFactory, signupCheckerFactory] = await (0, sdk_1.deployFreeForAllSignUpPolicy)({}, signer, true);
|
|
260
|
+
const signupPolicyContractAddress = await signupPolicy.getAddress();
|
|
261
|
+
const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)({ policy: signupPolicyFactory, checker: signupCheckerFactory }, signer, true);
|
|
262
|
+
const pollPolicyContractAddress = await pollPolicy.getAddress();
|
|
263
|
+
// deploy the smart contracts
|
|
264
|
+
maciAddresses = await (0, sdk_1.deployMaci)({
|
|
265
|
+
...constants_1.deployArgs,
|
|
266
|
+
signer,
|
|
267
|
+
signupPolicyAddress: signupPolicyContractAddress,
|
|
268
|
+
});
|
|
269
|
+
// we set the verifying keys
|
|
270
|
+
const { verifyingKeysRegistryContractAddress } = maciAddresses;
|
|
271
|
+
await (0, sdk_1.setVerifyingKeys)({
|
|
272
|
+
...(await (0, constants_1.verifyingKeysArgs)(signer, [sdk_1.EMode.NON_QV])),
|
|
273
|
+
verifyingKeysRegistryAddress: verifyingKeysRegistryContractAddress,
|
|
274
|
+
});
|
|
275
|
+
const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
|
|
276
|
+
// deploy a poll contract
|
|
277
|
+
await (0, sdk_1.deployPoll)({
|
|
278
|
+
...constants_1.deployPollArgs,
|
|
279
|
+
signer,
|
|
280
|
+
pollStartTimestamp: startDate,
|
|
281
|
+
pollEndTimestamp: startDate + constants_1.pollDuration,
|
|
282
|
+
relayers: [await signer.getAddress()],
|
|
283
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
284
|
+
policyContractAddress: pollPolicyContractAddress,
|
|
285
|
+
initialVoiceCreditProxyContractAddress,
|
|
286
|
+
mode: sdk_1.EMode.NON_QV,
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
it("should signup one user", async () => {
|
|
290
|
+
await (0, sdk_1.signup)({
|
|
291
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
292
|
+
maciPublicKey: user.publicKey.serialize(),
|
|
293
|
+
sgData: constants_1.DEFAULT_SG_DATA,
|
|
294
|
+
signer,
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
it("should join one user", async () => {
|
|
298
|
+
await (0, sdk_1.joinPoll)({
|
|
299
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
300
|
+
privateKey: user.privateKey.serialize(),
|
|
301
|
+
pollId: 0n,
|
|
302
|
+
pollJoiningZkey: constants_1.testPollJoiningZkeyPath,
|
|
303
|
+
useWasm,
|
|
304
|
+
pollJoiningWasm: constants_1.testPollJoiningWasmPath,
|
|
305
|
+
pollWitnessGenerator: constants_1.testPollJoiningWitnessPath,
|
|
306
|
+
rapidsnark: constants_1.testRapidsnarkPath,
|
|
307
|
+
sgDataArg: constants_1.DEFAULT_SG_DATA,
|
|
308
|
+
ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
|
|
309
|
+
signer,
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
it("should publish two messages", async () => {
|
|
313
|
+
await (0, sdk_1.publish)({
|
|
314
|
+
publicKey: user.publicKey.serialize(),
|
|
315
|
+
stateIndex: 1n,
|
|
316
|
+
voteOptionIndex: 0n,
|
|
317
|
+
nonce: 2n,
|
|
318
|
+
pollId: 0n,
|
|
319
|
+
newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
|
|
320
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
321
|
+
salt: (0, crypto_1.generateRandomSalt)(),
|
|
322
|
+
privateKey: user.privateKey.serialize(),
|
|
323
|
+
signer,
|
|
324
|
+
});
|
|
325
|
+
await (0, sdk_1.publish)({
|
|
326
|
+
publicKey: user.publicKey.serialize(),
|
|
327
|
+
stateIndex: 1n,
|
|
328
|
+
voteOptionIndex: 1n,
|
|
329
|
+
nonce: 1n,
|
|
330
|
+
pollId: 0n,
|
|
331
|
+
newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS),
|
|
332
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
333
|
+
salt: (0, crypto_1.generateRandomSalt)(),
|
|
334
|
+
privateKey: user.privateKey.serialize(),
|
|
335
|
+
signer,
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
it("should generate zk-SNARK proofs and verify them", async () => {
|
|
339
|
+
await (0, sdk_1.timeTravel)({ seconds: constants_1.pollDuration, signer });
|
|
340
|
+
await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
|
|
341
|
+
const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
|
|
342
|
+
...generateProofsArgs,
|
|
343
|
+
signer,
|
|
344
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
345
|
+
mode: sdk_1.EMode.NON_QV,
|
|
346
|
+
});
|
|
347
|
+
await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
|
|
348
|
+
await (0, sdk_1.verify)({
|
|
349
|
+
...(await (0, constants_1.verifyArgs)(signer)),
|
|
350
|
+
tallyData: tallyFileData,
|
|
351
|
+
maciAddress: tallyFileData.maci,
|
|
352
|
+
});
|
|
353
|
+
(0, chai_1.expect)(tallyFileData.totalSpentVoiceCredits.spent.toString()).to.eq(constants_1.DEFAULT_INITIAL_VOICE_CREDITS.toString());
|
|
354
|
+
tallyFileData.results.tally.forEach((result, index) => {
|
|
355
|
+
(0, chai_1.expect)(result.toString()).to.eq(index === 1 ? constants_1.DEFAULT_INITIAL_VOICE_CREDITS.toString() : "0");
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
describe("1 signup, 2 valid and 1 invalid message", () => {
|
|
360
|
+
after(async () => {
|
|
361
|
+
await (0, utils_1.clean)();
|
|
362
|
+
});
|
|
363
|
+
const user = new domainobjs_1.Keypair();
|
|
364
|
+
const voteWeight = 9n;
|
|
365
|
+
before(async () => {
|
|
366
|
+
const [signupPolicy, , signupPolicyFactory, signupCheckerFactory] = await (0, sdk_1.deployFreeForAllSignUpPolicy)({}, signer, true);
|
|
367
|
+
const signupPolicyContractAddress = await signupPolicy.getAddress();
|
|
368
|
+
const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)({ policy: signupPolicyFactory, checker: signupCheckerFactory }, signer, true);
|
|
369
|
+
const pollPolicyContractAddress = await pollPolicy.getAddress();
|
|
370
|
+
// deploy the smart contracts
|
|
371
|
+
maciAddresses = await (0, sdk_1.deployMaci)({
|
|
372
|
+
...constants_1.deployArgs,
|
|
373
|
+
signer,
|
|
374
|
+
signupPolicyAddress: signupPolicyContractAddress,
|
|
375
|
+
});
|
|
376
|
+
// we set the verifying keys
|
|
377
|
+
const { verifyingKeysRegistryContractAddress } = maciAddresses;
|
|
378
|
+
await (0, sdk_1.setVerifyingKeys)({
|
|
379
|
+
...(await (0, constants_1.verifyingKeysArgs)(signer, [sdk_1.EMode.NON_QV])),
|
|
380
|
+
verifyingKeysRegistryAddress: verifyingKeysRegistryContractAddress,
|
|
381
|
+
});
|
|
382
|
+
const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
|
|
383
|
+
// deploy a poll contract
|
|
384
|
+
await (0, sdk_1.deployPoll)({
|
|
385
|
+
...constants_1.deployPollArgs,
|
|
386
|
+
signer,
|
|
387
|
+
pollStartTimestamp: startDate,
|
|
388
|
+
pollEndTimestamp: startDate + constants_1.pollDuration,
|
|
389
|
+
relayers: [await signer.getAddress()],
|
|
390
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
391
|
+
policyContractAddress: pollPolicyContractAddress,
|
|
392
|
+
initialVoiceCreditProxyContractAddress,
|
|
393
|
+
mode: sdk_1.EMode.NON_QV,
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
it("should signup one user", async () => {
|
|
397
|
+
await (0, sdk_1.signup)({
|
|
398
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
399
|
+
maciPublicKey: user.publicKey.serialize(),
|
|
400
|
+
sgData: constants_1.DEFAULT_SG_DATA,
|
|
401
|
+
signer,
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
it("should join one user", async () => {
|
|
405
|
+
await (0, sdk_1.joinPoll)({
|
|
406
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
407
|
+
privateKey: user.privateKey.serialize(),
|
|
408
|
+
pollId: 0n,
|
|
409
|
+
pollJoiningZkey: constants_1.testPollJoiningZkeyPath,
|
|
410
|
+
useWasm,
|
|
411
|
+
pollJoiningWasm: constants_1.testPollJoiningWasmPath,
|
|
412
|
+
pollWitnessGenerator: constants_1.testPollJoiningWitnessPath,
|
|
413
|
+
rapidsnark: constants_1.testRapidsnarkPath,
|
|
414
|
+
sgDataArg: constants_1.DEFAULT_SG_DATA,
|
|
415
|
+
ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
|
|
416
|
+
signer,
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
it("should publish two valid and two invalid messages", async () => {
|
|
420
|
+
await (0, sdk_1.publish)({
|
|
421
|
+
publicKey: user.publicKey.serialize(),
|
|
422
|
+
stateIndex: 1n,
|
|
423
|
+
voteOptionIndex: 0n,
|
|
424
|
+
nonce: 1n,
|
|
425
|
+
pollId: 0n,
|
|
426
|
+
newVoteWeight: voteWeight,
|
|
427
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
428
|
+
salt: (0, crypto_1.generateRandomSalt)(),
|
|
429
|
+
privateKey: user.privateKey.serialize(),
|
|
430
|
+
signer,
|
|
431
|
+
});
|
|
432
|
+
await (0, sdk_1.publish)({
|
|
433
|
+
publicKey: user.publicKey.serialize(),
|
|
434
|
+
stateIndex: 1n,
|
|
435
|
+
voteOptionIndex: 1n,
|
|
436
|
+
nonce: 1n,
|
|
437
|
+
pollId: 0n,
|
|
438
|
+
newVoteWeight: BigInt(constants_1.DEFAULT_INITIAL_VOICE_CREDITS + 10),
|
|
439
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
440
|
+
salt: (0, crypto_1.generateRandomSalt)(),
|
|
441
|
+
privateKey: user.privateKey.serialize(),
|
|
442
|
+
signer,
|
|
443
|
+
});
|
|
444
|
+
await (0, sdk_1.publish)({
|
|
445
|
+
publicKey: user.publicKey.serialize(),
|
|
446
|
+
stateIndex: 1n,
|
|
447
|
+
voteOptionIndex: 1n,
|
|
448
|
+
nonce: 1n,
|
|
449
|
+
pollId: 0n,
|
|
450
|
+
newVoteWeight: -voteWeight,
|
|
451
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
452
|
+
salt: (0, crypto_1.generateRandomSalt)(),
|
|
453
|
+
privateKey: user.privateKey.serialize(),
|
|
454
|
+
signer,
|
|
455
|
+
});
|
|
456
|
+
await (0, sdk_1.publish)({
|
|
457
|
+
publicKey: user.publicKey.serialize(),
|
|
458
|
+
stateIndex: 1n,
|
|
459
|
+
voteOptionIndex: 1n,
|
|
460
|
+
nonce: 1n,
|
|
461
|
+
pollId: 0n,
|
|
462
|
+
newVoteWeight: voteWeight,
|
|
463
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
464
|
+
salt: (0, crypto_1.generateRandomSalt)(),
|
|
465
|
+
privateKey: user.privateKey.serialize(),
|
|
466
|
+
signer,
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
it("should generate zk-SNARK proofs and verify them", async () => {
|
|
470
|
+
await (0, sdk_1.timeTravel)({ seconds: constants_1.pollDuration, signer });
|
|
471
|
+
await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
|
|
472
|
+
const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
|
|
473
|
+
...generateProofsArgs,
|
|
474
|
+
signer,
|
|
475
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
476
|
+
mode: sdk_1.EMode.NON_QV,
|
|
198
477
|
});
|
|
199
478
|
await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
|
|
200
479
|
await (0, sdk_1.verify)({
|
|
@@ -202,6 +481,127 @@ describe("e2e tests with non quadratic voting", function test() {
|
|
|
202
481
|
tallyData: tallyFileData,
|
|
203
482
|
maciAddress: tallyFileData.maci,
|
|
204
483
|
});
|
|
484
|
+
(0, chai_1.expect)(tallyFileData.totalSpentVoiceCredits.spent.toString()).to.eq(voteWeight.toString());
|
|
485
|
+
tallyFileData.results.tally.forEach((result, index) => {
|
|
486
|
+
(0, chai_1.expect)(result.toString()).to.eq(index === 1 ? voteWeight.toString() : "0");
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
describe("2 signups, 2 different messages", () => {
|
|
491
|
+
after(async () => {
|
|
492
|
+
await (0, utils_1.clean)();
|
|
493
|
+
});
|
|
494
|
+
const users = [new domainobjs_1.Keypair(), new domainobjs_1.Keypair()];
|
|
495
|
+
const voteWeight = 9n;
|
|
496
|
+
before(async () => {
|
|
497
|
+
const [signupPolicy, , signupPolicyFactory, signupCheckerFactory] = await (0, sdk_1.deployFreeForAllSignUpPolicy)({}, signer, true);
|
|
498
|
+
const signupPolicyContractAddress = await signupPolicy.getAddress();
|
|
499
|
+
const [pollPolicy] = await (0, sdk_1.deployFreeForAllSignUpPolicy)({ policy: signupPolicyFactory, checker: signupCheckerFactory }, signer, true);
|
|
500
|
+
const pollPolicyContractAddress = await pollPolicy.getAddress();
|
|
501
|
+
// deploy the smart contracts
|
|
502
|
+
maciAddresses = await (0, sdk_1.deployMaci)({
|
|
503
|
+
...constants_1.deployArgs,
|
|
504
|
+
signer,
|
|
505
|
+
signupPolicyAddress: signupPolicyContractAddress,
|
|
506
|
+
});
|
|
507
|
+
// we set the verifying keys
|
|
508
|
+
const { verifyingKeysRegistryContractAddress } = maciAddresses;
|
|
509
|
+
await (0, sdk_1.setVerifyingKeys)({
|
|
510
|
+
...(await (0, constants_1.verifyingKeysArgs)(signer, [sdk_1.EMode.NON_QV])),
|
|
511
|
+
verifyingKeysRegistryAddress: verifyingKeysRegistryContractAddress,
|
|
512
|
+
});
|
|
513
|
+
const startDate = await (0, sdk_1.getBlockTimestamp)(signer);
|
|
514
|
+
// deploy a poll contract
|
|
515
|
+
await (0, sdk_1.deployPoll)({
|
|
516
|
+
...constants_1.deployPollArgs,
|
|
517
|
+
signer,
|
|
518
|
+
pollStartTimestamp: startDate,
|
|
519
|
+
pollEndTimestamp: startDate + constants_1.pollDuration,
|
|
520
|
+
relayers: [await signer.getAddress()],
|
|
521
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
522
|
+
policyContractAddress: pollPolicyContractAddress,
|
|
523
|
+
initialVoiceCreditProxyContractAddress,
|
|
524
|
+
mode: sdk_1.EMode.NON_QV,
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
it("should signup two users", async () => {
|
|
528
|
+
await (0, sdk_1.signup)({
|
|
529
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
530
|
+
maciPublicKey: users[0].publicKey.serialize(),
|
|
531
|
+
sgData: constants_1.DEFAULT_SG_DATA,
|
|
532
|
+
signer: userSigners[0],
|
|
533
|
+
});
|
|
534
|
+
await (0, sdk_1.signup)({
|
|
535
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
536
|
+
maciPublicKey: users[1].publicKey.serialize(),
|
|
537
|
+
sgData: constants_1.DEFAULT_SG_DATA,
|
|
538
|
+
signer: userSigners[1],
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
it("should join two users", async () => {
|
|
542
|
+
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
543
|
+
for (let index = 0; index < users.length; index += 1) {
|
|
544
|
+
// eslint-disable-next-line no-await-in-loop
|
|
545
|
+
await (0, sdk_1.joinPoll)({
|
|
546
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
547
|
+
privateKey: users[index].privateKey.serialize(),
|
|
548
|
+
pollId: 0n,
|
|
549
|
+
pollJoiningZkey: constants_1.testPollJoiningZkeyPath,
|
|
550
|
+
useWasm,
|
|
551
|
+
pollJoiningWasm: constants_1.testPollJoiningWasmPath,
|
|
552
|
+
pollWitnessGenerator: constants_1.testPollJoiningWitnessPath,
|
|
553
|
+
rapidsnark: constants_1.testRapidsnarkPath,
|
|
554
|
+
sgDataArg: constants_1.DEFAULT_SG_DATA,
|
|
555
|
+
ivcpDataArg: constants_1.DEFAULT_IVCP_DATA,
|
|
556
|
+
signer: userSigners[index],
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
it("should publish two different messages", async () => {
|
|
561
|
+
await (0, sdk_1.publish)({
|
|
562
|
+
publicKey: users[0].publicKey.serialize(),
|
|
563
|
+
stateIndex: 1n,
|
|
564
|
+
voteOptionIndex: 0n,
|
|
565
|
+
nonce: 1n,
|
|
566
|
+
pollId: 0n,
|
|
567
|
+
newVoteWeight: voteWeight,
|
|
568
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
569
|
+
salt: (0, crypto_1.generateRandomSalt)(),
|
|
570
|
+
privateKey: users[0].privateKey.serialize(),
|
|
571
|
+
signer,
|
|
572
|
+
});
|
|
573
|
+
await (0, sdk_1.publish)({
|
|
574
|
+
publicKey: users[1].publicKey.serialize(),
|
|
575
|
+
stateIndex: 2n,
|
|
576
|
+
voteOptionIndex: 1n,
|
|
577
|
+
nonce: 1n,
|
|
578
|
+
pollId: 0n,
|
|
579
|
+
newVoteWeight: voteWeight,
|
|
580
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
581
|
+
salt: (0, crypto_1.generateRandomSalt)(),
|
|
582
|
+
privateKey: users[1].privateKey.serialize(),
|
|
583
|
+
signer,
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
it("should generate zk-SNARK proofs and verify them", async () => {
|
|
587
|
+
await (0, sdk_1.timeTravel)({ seconds: constants_1.pollDuration, signer });
|
|
588
|
+
await (0, sdk_1.mergeSignups)({ ...constants_1.mergeSignupsArgs, maciAddress: maciAddresses.maciContractAddress, signer });
|
|
589
|
+
const { tallyData: tallyFileData } = await (0, sdk_1.generateProofs)({
|
|
590
|
+
...generateProofsArgs,
|
|
591
|
+
signer,
|
|
592
|
+
maciAddress: maciAddresses.maciContractAddress,
|
|
593
|
+
mode: sdk_1.EMode.NON_QV,
|
|
594
|
+
});
|
|
595
|
+
await (0, sdk_1.proveOnChain)({ ...constants_1.proveOnChainArgs, maciAddress: maciAddresses.maciContractAddress, signer });
|
|
596
|
+
await (0, sdk_1.verify)({
|
|
597
|
+
...(await (0, constants_1.verifyArgs)(signer)),
|
|
598
|
+
tallyData: tallyFileData,
|
|
599
|
+
maciAddress: tallyFileData.maci,
|
|
600
|
+
});
|
|
601
|
+
(0, chai_1.expect)(tallyFileData.totalSpentVoiceCredits.spent.toString()).to.eq((voteWeight * 2n).toString());
|
|
602
|
+
tallyFileData.results.tally.forEach((result, index) => {
|
|
603
|
+
(0, chai_1.expect)(result.toString()).to.eq(index < 2 ? voteWeight.toString() : "0");
|
|
604
|
+
});
|
|
205
605
|
});
|
|
206
606
|
});
|
|
207
607
|
});
|