Skip to content

Commit

Permalink
test(integrationtests): verify spent voice credit
Browse files Browse the repository at this point in the history
  • Loading branch information
baumstern committed Oct 7, 2022
1 parent e5ccfe9 commit 796c3fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
8 changes: 4 additions & 4 deletions integrationTests/ts/__tests__/suites.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"numVotesPerUser": 1,
"numUsers": 15,
"expectedTally": [15, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"expectedSpentVoiceCredits": [15, 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": 15
},
{
Expand All @@ -15,7 +15,7 @@
"numVotesPerUser": 1,
"numUsers": 16,
"expectedTally": [16, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
"expectedSpentVoiceCredits": [16, 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": 16
},
{
Expand All @@ -24,7 +24,7 @@
"numUsers": 4,
"numVotesPerUser": 1,
"expectedTally": [4, 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, 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": [4, 0, 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": 4
},
{
Expand Down Expand Up @@ -63,7 +63,7 @@
}
},
"expectedTally": [0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"expectedSpentVoiceCredits": [4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"expectedSpentVoiceCredits": [0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"expectedTotalSpentVoiceCredits": 8
},
{
Expand Down
4 changes: 2 additions & 2 deletions integrationTests/ts/__tests__/suites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const executeSuite = async (data: any, expect: any) => {
const userKeypair = users[i].keypair
userKeypairs.push(userKeypair)
// Run the signup command
const signupCommand = `node ../cli/build/index.js signup` +
const signupCommand = `node build/index.js signup` +
` -p ${userKeypair.pubKey.serialize()}` +
` -x ${maciAddress}`
execute(signupCommand)
Expand Down Expand Up @@ -257,7 +257,7 @@ const executeSuite = async (data: any, expect: any) => {
data.expectedTotalSpentVoiceCredits,
tally
)
if (data.subsidy) {
if (subsidyEnabled) {
const subsidy = JSON.parse(fs.readFileSync(path.join(__dirname, '../../../cli/subsidy.json')).toString())
// Validate generated proof file
expect(JSON.stringify(subsidy.pollId)).toEqual(pollId)
Expand Down
15 changes: 11 additions & 4 deletions integrationTests/ts/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,26 @@ interface Subsidy {
const expectTally = (
maxMessages: number,
expectedTally: number[],
expectedSpentVoiceCredits: number[],
expectedPerVOSpentVoiceCredits: number[],
expectedTotalSpentVoiceCredits: number,
tallyFile: Tally
) => {
let genTally: string[] = Array(maxMessages).fill('0')
let genPerVOSpentVoiceCredits: string[] = Array(maxMessages).fill('0')
const calculateTally =
expectedTally.map((voteOption, index) => {
if (voteOption != 0) {
genTally[index] = voteOption.toString()
expectedTally.map((voteWeight, voteOption) => {
if (voteWeight != 0) {
genTally[voteOption] = voteWeight.toString()
}
})
expectedPerVOSpentVoiceCredits.map((spentCredit, index) => {
if (spentCredit != 0) {
genPerVOSpentVoiceCredits[index] = spentCredit.toString()
}
})

expect(tallyFile.results.tally).toEqual(genTally)
expect(tallyFile.perVOSpentVoiceCredits.tally).toEqual(genPerVOSpentVoiceCredits)
expect(tallyFile.totalSpentVoiceCredits.spent).toEqual(expectedTotalSpentVoiceCredits.toString())
}

Expand Down

0 comments on commit 796c3fa

Please sign in to comment.