Skip to content

Commit

Permalink
fix() Increase gas limit to make transaction work
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu committed Sep 8, 2023
1 parent 331eec9 commit 260d973
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 39 deletions.
9 changes: 4 additions & 5 deletions contracts/Governor/GovernorZama.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
79 changes: 45 additions & 34 deletions test/governor/GovernorZama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -70,33 +71,37 @@ 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);

// 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])];
Expand All @@ -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);
Expand All @@ -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 () {
Expand All @@ -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);
Expand Down

0 comments on commit 260d973

Please sign in to comment.