Skip to content

Commit

Permalink
Add more context for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
corydickson committed Jun 23, 2021
1 parent 9aeb5ce commit d64aac9
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 80 deletions.
11 changes: 3 additions & 8 deletions integrationTests/integrations.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
42 changes: 42 additions & 0 deletions integrationTests/ts/__tests__/suites.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
37 changes: 8 additions & 29 deletions integrationTests/ts/__tests__/suites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}
})
5 changes: 3 additions & 2 deletions integrationTests/ts/__tests__/suites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions integrationTests/ts/__tests__/suites/suite0_happy.json

This file was deleted.

9 changes: 0 additions & 9 deletions integrationTests/ts/__tests__/suites/suite1_small.json

This file was deleted.

10 changes: 0 additions & 10 deletions integrationTests/ts/__tests__/suites/suite2_bribe.json

This file was deleted.

11 changes: 0 additions & 11 deletions integrationTests/ts/__tests__/suites/suite3_keychange.json

This file was deleted.

4 changes: 2 additions & 2 deletions integrationTests/ts/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d64aac9

Please sign in to comment.