diff --git a/contracts/Governor/GovernorZama.sol b/contracts/Governor/GovernorZama.sol index 7b667f1d..37e0fb46 100644 --- a/contracts/Governor/GovernorZama.sol +++ b/contracts/Governor/GovernorZama.sol @@ -194,8 +194,8 @@ contract GovernorZama { newProposal.targets = targets; newProposal.values = values; newProposal.signatures = signatures; - newProposal.forVotes = euint32.wrap(0); - newProposal.againstVotes = euint32.wrap(0); + newProposal.forVotes = TFHE.asEuint32(0); + newProposal.againstVotes = TFHE.asEuint32(0); newProposal.calldatas = calldatas; newProposal.startBlock = startBlock; newProposal.endBlock = endBlock; @@ -374,9 +374,8 @@ contract GovernorZama { euint32 ctOne = TFHE.asEuint32(1); - // TOFIX These 2 lines fails: - proposal.forVotes = TFHE.add(TFHE.asEuint32(0), TFHE.mul(votes, support)); - proposal.againstVotes = TFHE.add(TFHE.asEuint32(0), TFHE.mul(votes, TFHE.sub(ctOne, support))); + proposal.forVotes = TFHE.add(proposal.forVotes, TFHE.mul(votes, support)); + proposal.againstVotes = TFHE.add(proposal.againstVotes, TFHE.mul(votes, TFHE.sub(ctOne, support))); receipt.hasVoted = true; receipt.votes = votes; diff --git a/test/governor/GovernorZama.ts b/test/governor/GovernorZama.ts index 5e64cf42..e02be02a 100644 --- a/test/governor/GovernorZama.ts +++ b/test/governor/GovernorZama.ts @@ -52,9 +52,10 @@ describe('GovernorZama', function () { callDatas, 0, 'do nothing', - { gasLimit: 500000 }, + { gasLimit: 1000000 }, ); - await tx.wait(); + const proposal = await tx.wait(); + expect(proposal?.status).to.equal(1); const proposalId = await this.governor.latestProposalIds(this.signers.alice.address); const proposals = await this.governor.proposals(proposalId); expect(proposals.id).to.equal(proposalId); @@ -70,9 +71,11 @@ describe('GovernorZama', function () { callDatas, 4, 'do nothing', - { gasLimit: 500000 }, + { gasLimit: 1000000 }, ); - await tx.wait(); + const proposal = await tx.wait(); + expect(proposal?.status).to.equal(1); + const proposalId = await this.governor.latestProposalIds(this.signers.alice.address); const proposals = await this.governor.proposals(proposalId); await waitForBlock(proposals.startBlock + 1n); @@ -80,23 +83,25 @@ describe('GovernorZama', function () { // TOFIX: Votes are not casted. See _castVotes function in GovernorZama.sol // Cast some votes - // const encryptedSupportBob = this.instances.bob.encrypt32(1); - // const txVoteBob = await this.governor - // .connect(this.signers.bob) - // ['castVote(uint256,bytes)'](proposalId, encryptedSupportBob, { gasLimit: 500000 }); + const encryptedSupportBob = this.instances.bob.encrypt32(1); + const txVoteBob = await this.governor + .connect(this.signers.bob) + ['castVote(uint256,bytes)'](proposalId, encryptedSupportBob, { gasLimit: 5000000 }); - // const encryptedSupportCarol = this.instances.carol.encrypt32(1); - // const txVoteCarol = await this.governor - // .connect(this.signers.carol) - // ['castVote(uint256,bytes)'](proposalId, encryptedSupportCarol, { gasLimit: 500000 }); + const encryptedSupportCarol = this.instances.carol.encrypt32(1); + const txVoteCarol = await this.governor + .connect(this.signers.carol) + ['castVote(uint256,bytes)'](proposalId, encryptedSupportCarol, { gasLimit: 5000000 }); - // await Promise.all([txVoteBob.wait(), txVoteCarol.wait()]); + const [bobResults, aliceResults] = await Promise.all([txVoteBob.wait(), txVoteCarol.wait()]); + expect(bobResults?.status).to.equal(1); + expect(aliceResults?.status).to.equal(1); - // await waitForBlock(proposals.endBlock + 1n); + await waitForBlock(proposals.endBlock + 1n); - // const state = await this.governor.state(proposalId); - // expect(state).to.equal(4n); - }).timeout(300000); + const state = await this.governor.state(proposalId); + expect(state).to.equal(4n); + }).timeout(120000); it('should vote and return a Defeated ', async function () { const callDatas = [ethers.AbiCoder.defaultAbiCoder().encode(['address'], [this.signers.alice.address])]; @@ -107,9 +112,10 @@ describe('GovernorZama', function () { callDatas, 4, 'do nothing', - { gasLimit: 500000 }, + { gasLimit: 1000000 }, ); - await tx.wait(); + const proposal = await tx.wait(); + expect(proposal?.status).to.equal(1); const proposalId = await this.governor.latestProposalIds(this.signers.alice.address); const proposals = await this.governor.proposals(proposalId); console.log(proposals); @@ -118,20 +124,24 @@ describe('GovernorZama', function () { // TOFIX: Votes are not casted. See _castVotes function in GovernorZama.sol // Cast some votes - // const encryptedSupportBob = this.instances.bob.encrypt32(0); - // const txVoteBob = await this.governor - // .connect(this.signers.bob) - // ['castVote(uint256,bytes)'](proposalId, encryptedSupportBob, { gasLimit: 500000 }); - // const encryptedSupportCarol = this.instances.bob.encrypt32(1); - // const txVoteCarol = await this.governor - // .connect(this.signers.bob) - // ['castVote(uint256,bytes)'](proposalId, encryptedSupportCarol, { gasLimit: 500000 }); - // await Promise.all([txVoteAlice.wait(), txVoteBob.wait(), txVoteCarol.wait()]); - - // await waitForBlock(proposals.endBlock + 1n); - - // const state = await this.governor.state(proposalId); - // expect(state).to.equal(3n); + const encryptedSupportBob = this.instances.bob.encrypt32(0); + const txVoteBob = await this.governor + .connect(this.signers.bob) + ['castVote(uint256,bytes)'](proposalId, encryptedSupportBob, { gasLimit: 5000000 }); + + const encryptedSupportCarol = this.instances.carol.encrypt32(0); + const txVoteCarol = await this.governor + .connect(this.signers.carol) + ['castVote(uint256,bytes)'](proposalId, encryptedSupportCarol, { gasLimit: 5000000 }); + + const [bobResults, aliceResults] = await Promise.all([txVoteBob.wait(), txVoteCarol.wait()]); + expect(bobResults?.status).to.equal(1); + expect(aliceResults?.status).to.equal(1); + + await waitForBlock(proposals.endBlock + 1n); + + const state = await this.governor.state(proposalId); + expect(state).to.equal(3n); }).timeout(120000); it('should cancel', async function () { @@ -146,7 +156,8 @@ describe('GovernorZama', function () { 'do nothing', { gasLimit: 500000 }, ); - await tx.wait(); + const proposal = await tx.wait(); + expect(proposal?.status).to.equal(1); const proposalId = await this.governor.latestProposalIds(this.signers.alice.address); const proposals = await this.governor.proposals(proposalId); await waitForBlock(proposals.startBlock + 1n);