Skip to content

Commit

Permalink
fix(maci): final fix to the tests
Browse files Browse the repository at this point in the history
Merged Chao fixes for correct enqueuing of the NOTHING_UP_MY_SLEEVE hash and amended Contract tests to fix the final issue.
  • Loading branch information
ctrlc03 committed Nov 11, 2022
1 parent 21340c9 commit 51e84f8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
4 changes: 2 additions & 2 deletions contracts/contracts/Poll.sol
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ contract Poll is
return secondsPassed > duration;
}

// should be call immediately after Poll creation and messageAq ownership transferred
// should be called immediately after Poll creation and messageAq ownership transferred
function init() public {
require(isInit == false, "Poll contract already init");
require(!isInit, "Poll contract already init");
isInit = true;
numMessages++;
// init messageAq here by inserting placeholderLeaf
Expand Down
43 changes: 38 additions & 5 deletions contracts/ts/__tests__/MACI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
PCommand,
VerifyingKey,
Keypair,
PubKey,
Message,
} from 'maci-domainobjs'

import {
Expand Down Expand Up @@ -292,9 +294,39 @@ describe('MACI', () => {
)
expect(p.toString()).toEqual(pollId.toString())

// insert/enqueue NOTHING_UP_MY_SLEEVE
maciState.polls[pollId].messageTree.insert(NOTHING_UP_MY_SLEEVE)
maciState.polls[pollId].messageAq.enqueue(NOTHING_UP_MY_SLEEVE)
// publish the NOTHING_UP_MY_SLEEVE message
const messageData = [
NOTHING_UP_MY_SLEEVE,
BigInt(0)
]
for (let i = 2; i < 10; i++) {
messageData.push(BigInt(0))
}
const message = new Message(
BigInt(1),
messageData
)
const padKey = new PubKey([
BigInt('10457101036533406547632367118273992217979173478358440826365724437999023779287'),
BigInt('19824078218392094440610104313265183977899662750282163392862422243483260492317'),
])
maciState.polls[pollId].publishMessage(message, padKey)

})

it('should fail when attempting to init twice a Poll', async () => {
const pollContractAddress = await maciContract.getPoll(pollId)
const pollContract = new ethers.Contract(
pollContractAddress,
pollAbi,
signer,
)

try {
await pollContract.init()
} catch (error) {
expect(error).not.toBe(null)
}
})

it('should set correct storage values', async () => {
Expand All @@ -320,8 +352,9 @@ describe('MACI', () => {
// There are 3 signups via the MACI instance
expect(Number(sm[0])).toEqual(3)

// There are 0 messages until a user publishes a message
expect(Number(sm[1])).toEqual(0)
// There are 1 messages until a user publishes a message
// As we enqueue the NOTHING_UP_MY_SLEEVE hash
expect(Number(sm[1])).toEqual(1)

const onChainMaxValues = await pollContract.maxValues()

Expand Down
1 change: 0 additions & 1 deletion contracts/ts/genMaciState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Keypair,
PubKey,
Message,
VerifyingKey,
} from 'maci-domainobjs'

import {
Expand Down

0 comments on commit 51e84f8

Please sign in to comment.