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