diff --git a/integrationTests/integrations.yml b/integrationTests/integrations.yml index 192b604227..0031f948bf 100644 --- a/integrationTests/integrations.yml +++ b/integrationTests/integrations.yml @@ -1,12 +1,7 @@ libraries: - - name: cli - - name: contracts - - name: crypto -startPoll: -submitVote: -tallyVotes: -processStateTree: - + - "cli" + - "contracts" + - "crypto" user: [index, voteOptionIndex, voteWeight, nonce, commandType] defaultVote: diff --git a/integrationTests/ts/__tests__/suites.json b/integrationTests/ts/__tests__/suites.json new file mode 100644 index 0000000000..6b87615382 --- /dev/null +++ b/integrationTests/ts/__tests__/suites.json @@ -0,0 +1,42 @@ +{ + "suites": [ + { + "name": "Happy path", + "description": "Full tree, 4 batches, no bribers", + "numVotesPerUser": 1, + "numUsers": 15, + "expectedTally": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], + "expectedSpentVoiceCredits": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], + "expectedTotalSpentVoiceCredits": 15 + }, + { + "name": "Happy path 2", + "description": "Quarter tree, 1 batch, no bribers", + "numUsers": 4, + "numVotesPerUser": 1, + "expectedTally": [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "expectedSpentVoiceCredits": [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "expectedTotalSpentVoiceCredits": 4 + }, + { + "name": "Reverse processing", + "description": "2 batches, 1 briber", + "numUsers": 3, + "numVotesPerUser": 2, + "bribers": { "0": { "voteOptionIndices": [0,1] }, "1": { "voteOptionIndices": [0,1]}}, + "expectedTally": [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "expectedSpentVoiceCredits": [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "expectedTotalSpentVoiceCredits": 2 + }, + { + "name": "Happy path for user key change", + "description": "Single user vote with new keys", + "numUsers": 1, + "numVotesPerUser": 2, + "changeUsersKeys": { "0": {"1":{ "voteOptionIndex": 1, "voteWeight": 9}}}, + "expectedTally": [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "expectedSpentVoiceCredits": [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "expectedTotalSpentVoiceCredits": 1 + } + ] +} diff --git a/integrationTests/ts/__tests__/suites.test.ts b/integrationTests/ts/__tests__/suites.test.ts index b4e7ab1936..e8c9eb30fc 100644 --- a/integrationTests/ts/__tests__/suites.test.ts +++ b/integrationTests/ts/__tests__/suites.test.ts @@ -6,35 +6,14 @@ import { } from './suites' describe('Test suites', () => { - it('Suite 0 - happy path, full tree', async () => { - const data = loadData('suite0_happy.json') - const result = await executeSuite(data, expect) + const data = loadData('suites.json') - expect(result).toBeTruthy() - }) + for (const test of data.suites) { + it(test.description, async () => { + const result = await executeSuite(test, expect) + console.log(result) - it('Suite 1 - happy path, partial tree', async () => { - const data = loadData('suite1_small.json') - const result = await executeSuite(data, expect) - - console.log(result) - - expect(result).toBeTruthy() - }) - - it('Suite 2 - 1 briber, two batches', async () => { - const data = loadData('suite2_bribe.json') - const result = await executeSuite(data, expect) - console.log(result) - - expect(result).toBeTruthy() - }) - - it('Suite 3 - happy path, user key change', async () => { - const data = loadData('suite3_keychange.json') - const result = await executeSuite(data, expect) - console.log(result) - - expect(result).toBeTruthy() - }) + expect(result).toBeTruthy() + }) + } }) diff --git a/integrationTests/ts/__tests__/suites.ts b/integrationTests/ts/__tests__/suites.ts index a3e880f5f0..64d3eee109 100644 --- a/integrationTests/ts/__tests__/suites.ts +++ b/integrationTests/ts/__tests__/suites.ts @@ -25,7 +25,7 @@ import { genPubKey } from 'maci-crypto' import { exec, loadYaml, genTestUserCommands } from './utils' const loadData = (name: string) => { - return require('@maci-integrationTests/ts/__tests__/suites/' + name) + return require('@maci-integrationTests/ts/__tests__/' + name) } const executeSuite = async (data: any, expect: any) => { @@ -163,7 +163,8 @@ const executeSuite = async (data: any, expect: any) => { } for (let j = 0; j < users[i].votes.length; j++ ) { - const isKeyChange = (j in data.changeUsersKeys[i]) + // find which vote index the user should change keys + const isKeyChange = (data.changeUsersKeys && j in data.changeUsersKeys[i]) const stateIndex = i + 1 const voteOptionIndex = isKeyChange ? data.changeUsersKeys[i][j].voteOptionIndex : users[i].votes[j].voteOptionIndex diff --git a/integrationTests/ts/__tests__/suites/suite0_happy.json b/integrationTests/ts/__tests__/suites/suite0_happy.json deleted file mode 100644 index 121c75f88d..0000000000 --- a/integrationTests/ts/__tests__/suites/suite0_happy.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "Happy path", - "description": "Full tree, 4 batches, no bribers", - "numVotesPerUser": 1, - "numUsers": 15, - "expectedTally": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], - "expectedSpentVoiceCredits": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], - "expectedTotalSpentVoiceCredits": 15 -} diff --git a/integrationTests/ts/__tests__/suites/suite1_small.json b/integrationTests/ts/__tests__/suites/suite1_small.json deleted file mode 100644 index 846c688d1d..0000000000 --- a/integrationTests/ts/__tests__/suites/suite1_small.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "Happy path 2", - "description": "Quarter tree, 1 batch, no bribers", - "numUsers": 4, - "numVotesPerUser": 1, - "expectedTally": [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - "expectedSpentVoiceCredits": [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - "expectedTotalSpentVoiceCredits": 4 -} diff --git a/integrationTests/ts/__tests__/suites/suite2_bribe.json b/integrationTests/ts/__tests__/suites/suite2_bribe.json deleted file mode 100644 index cfe2bdd7c9..0000000000 --- a/integrationTests/ts/__tests__/suites/suite2_bribe.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "Reverse processing", - "description": "2 batches, 1 briber", - "numUsers": 3, - "numVotesPerUser": 2, - "bribers": {"0": [0,1], "1": [0,1]}, - "expectedTally": [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - "expectedSpentVoiceCredits": [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - "expectedTotalSpentVoiceCredits": 2 -} diff --git a/integrationTests/ts/__tests__/suites/suite3_keychange.json b/integrationTests/ts/__tests__/suites/suite3_keychange.json deleted file mode 100644 index 58641886dd..0000000000 --- a/integrationTests/ts/__tests__/suites/suite3_keychange.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "Happy path for user key change", - "description": "Single user vote with new keys", - "numUsers": 1, - "numVotesPerUser": 2, - "changeUsersKeys": { "0": {"1":{ "voteOptionIndex": 1, "voteWeight": 9}}}, - "expectedTally": [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - "expectedSpentVoiceCredits": [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - "expectedTotalSpentVoiceCredits": 1 -} - diff --git a/integrationTests/ts/__tests__/utils.ts b/integrationTests/ts/__tests__/utils.ts index dfd5b93507..029d4cf234 100644 --- a/integrationTests/ts/__tests__/utils.ts +++ b/integrationTests/ts/__tests__/utils.ts @@ -61,10 +61,10 @@ const genTestUserCommands = ( let voteOptionIndex = config.defaultVote.voteOptionIndex if (bribers && i in bribers) { - if (!(bribers[i].length == numVotesPerUser)) { + if (!(bribers[i].voteOptionIndices.length == numVotesPerUser)) { throw new Error("failed: more bribes than votes set per user") } - voteOptionIndex = bribers[i][j] + voteOptionIndex = bribers[i].voteOptionIndices[j] } const vote: Vote = { voteOptionIndex: voteOptionIndex,