From defaea081801b9fcb4f9b311985e473e3c4236e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8r=E2=88=82=C2=A1?= <4456749+brickpop@users.noreply.github.com> Date: Wed, 13 Sep 2023 09:33:13 +0200 Subject: [PATCH] fix: plugin tests (#462) * Amending some plugin tests - createProposal().value contains the amount of ether sent, not the proposalId - an await is missing, which makes tests fail elsewhere - an event type is missing * Testing the emitted proposalId event value on majority voting plugins --- .../addresslist/addresslist-voting.ts | 192 +++++++-------- .../majority-voting/token/token-voting.ts | 221 +++++++++--------- 2 files changed, 217 insertions(+), 196 deletions(-) diff --git a/packages/contracts/test/plugins/governance/majority-voting/addresslist/addresslist-voting.ts b/packages/contracts/test/plugins/governance/majority-voting/addresslist/addresslist-voting.ts index 3be84438f..292944597 100644 --- a/packages/contracts/test/plugins/governance/majority-voting/addresslist/addresslist-voting.ts +++ b/packages/contracts/test/plugins/governance/majority-voting/addresslist/addresslist-voting.ts @@ -58,6 +58,7 @@ import { CURRENT_PROTOCOL_VERSION, IMPLICIT_INITIAL_PROTOCOL_VERSION, } from '../../../../test-utils/protocol-version'; +import {ExecutedEvent} from '../../../../../typechain/DAO'; export const addresslistVotingInterface = new ethers.utils.Interface([ 'function initialize(address,tuple(uint8,uint32,uint32,uint64,uint256),address[])', @@ -569,19 +570,20 @@ describe('AddresslistVoting', function () { signers.slice(0, 10).map(s => s.address) ); - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); expect((await voting.getProposal(id)).parameters.minVotingPower).to.eq(4); // 4 out of 10 votes must be casted for the proposal to pass }); @@ -595,19 +597,20 @@ describe('AddresslistVoting', function () { signers.slice(0, 10).map(s => s.address) ); - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); expect((await voting.getProposal(id)).parameters.minVotingPower).to.eq(3); // 3 out of 10 votes must be casted for the proposal to pass }); @@ -767,19 +770,20 @@ describe('AddresslistVoting', function () { .withArgs(id, signers[0].address, VoteOption.Yes); // Works if the vote option is 'None' - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); }); }); @@ -794,19 +798,20 @@ describe('AddresslistVoting', function () { signers.slice(0, 10).map(s => s.address) ); - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); }); it('reverts on voting None', async () => { @@ -925,19 +930,20 @@ describe('AddresslistVoting', function () { signers.slice(0, 10).map(s => s.address) ); - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); }); it('does not allow voting, when the vote has not started yet', async () => { @@ -1127,19 +1133,20 @@ describe('AddresslistVoting', function () { signers.slice(0, 10).map(s => s.address) ); - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); }); it('reverts on voting None', async () => { @@ -1370,19 +1377,20 @@ describe('AddresslistVoting', function () { votingSettings, signers.slice(0, 10).map(s => s.address) ); - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); }); it('does not execute if support is high enough but participation is too low', async () => { @@ -1580,7 +1588,7 @@ describe('AddresslistVoting', function () { it('does not execute with 9 votes', async () => { // does not execute early - advanceIntoVoteTime(startDate, endDate); + await advanceIntoVoteTime(startDate, endDate); await voteWithSigners(voting, id, signers, { yes: [0, 1, 2, 3, 4, 5, 6, 7, 8], // 9 votes diff --git a/packages/contracts/test/plugins/governance/majority-voting/token/token-voting.ts b/packages/contracts/test/plugins/governance/majority-voting/token/token-voting.ts index 71d854eea..0093f916b 100644 --- a/packages/contracts/test/plugins/governance/majority-voting/token/token-voting.ts +++ b/packages/contracts/test/plugins/governance/majority-voting/token/token-voting.ts @@ -59,6 +59,7 @@ import { CURRENT_PROTOCOL_VERSION, IMPLICIT_INITIAL_PROTOCOL_VERSION, } from '../../../../test-utils/protocol-version'; +import {ExecutedEvent} from '../../../../../typechain/DAO'; export const tokenVotingInterface = new ethers.utils.Interface([ 'function initialize(address,tuple(uint8,uint32,uint32,uint64,uint256),address)', @@ -371,19 +372,22 @@ describe('TokenVoting', function () { }, ]); - await expect( - voting - .connect(signers[1]) - .createProposal( - dummyMetadata, - [], - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).to.not.be.reverted; + const tx = await voting + .connect(signers[1]) + .createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); }); }); @@ -598,19 +602,22 @@ describe('TokenVoting', function () { .to.be.revertedWithCustomError(voting, 'ProposalCreationForbidden') .withArgs(signers[2].address); - await expect( - voting - .connect(signers[0]) - .createProposal( - dummyMetadata, - [], - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).to.not.be.reverted; + const tx = await voting + .connect(signers[0]) + .createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); }); it('creates a proposal if `_msgSender` owns no tokens but has enough tokens delegated to her/him in the current block', async () => { @@ -878,19 +885,20 @@ describe('TokenVoting', function () { governanceErc20Mock.address ); - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); expect((await voting.getProposal(id)).parameters.minVotingPower).to.eq(4); // 4 out of 10 votes must be casted for the proposal to pass }); @@ -906,19 +914,20 @@ describe('TokenVoting', function () { governanceErc20Mock.address ); - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); expect((await voting.getProposal(id)).parameters.minVotingPower).to.eq(3); // 3 out of 10 votes must be casted for the proposal to pass }); @@ -1084,19 +1093,20 @@ describe('TokenVoting', function () { .withArgs(id, signers[0].address, VoteOption.Yes); // Works if the vote option is 'None' - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); }); }); @@ -1126,19 +1136,20 @@ describe('TokenVoting', function () { governanceErc20Mock.address ); - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); }); it('reverts on voting None', async () => { @@ -1253,19 +1264,20 @@ describe('TokenVoting', function () { governanceErc20Mock.address ); - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); }); it('does not allow voting, when the vote has not started yet', async () => { @@ -1483,19 +1495,20 @@ describe('TokenVoting', function () { governanceErc20Mock.address ); - expect( - ( - await voting.createProposal( - dummyMetadata, - dummyActions, - 0, - startDate, - endDate, - VoteOption.None, - false - ) - ).value - ).to.equal(id); + const tx = await voting.createProposal( + dummyMetadata, + dummyActions, + 0, + startDate, + endDate, + VoteOption.None, + false + ); + const event = await findEvent( + tx, + 'ProposalCreated' + ); + expect(event.args.proposalId).to.equal(id); }); it('reverts on voting None', async () => {