From 305211e0a4a10996899770c7e2716a933f29f2cf Mon Sep 17 00:00:00 2001 From: Ben DiFrancesco Date: Thu, 10 Feb 2022 11:17:54 -0500 Subject: [PATCH] Add VoteCastWithParams event emitted when params are included --- contracts/governance/Governor.sol | 6 +++++- contracts/governance/IGovernor.sol | 19 +++++++++++++++++-- .../extensions/GovernorWithParams.test.js | 6 +++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/contracts/governance/Governor.sol b/contracts/governance/Governor.sol index 1f5fb5fa63d..fe701863f18 100644 --- a/contracts/governance/Governor.sol +++ b/contracts/governance/Governor.sol @@ -438,7 +438,11 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor { uint256 weight = _getVotes(account, proposal.voteStart.getDeadline(), params); _countVote(proposalId, account, support, weight, params); - emit VoteCast(account, proposalId, support, weight, reason); + if (params.length == 0) { + emit VoteCast(account, proposalId, support, weight, reason); + } else { + emit VoteCastWithParams(account, proposalId, support, weight, reason, params); + } return weight; } diff --git a/contracts/governance/IGovernor.sol b/contracts/governance/IGovernor.sol index d975d2c99e3..5eb08d9848b 100644 --- a/contracts/governance/IGovernor.sol +++ b/contracts/governance/IGovernor.sol @@ -48,12 +48,27 @@ abstract contract IGovernor is IERC165 { event ProposalExecuted(uint256 proposalId); /** - * @dev Emitted when a vote is cast. + * @dev Emitted when a vote is cast without params. * - * Note: `support` values should be seen as buckets. There interpretation depends on the voting module used. + * Note: `support` values should be seen as buckets. Their interpretation depends on the voting module used. */ event VoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason); + /** + * @dev Emitted when a vote is cast with params. + * + * Note: `support` values should be seen as buckets. Their interpretation depends on the voting module used. + * `params` are additional encoded parameters. Their intepepretation also depends on the voting module used. + */ + event VoteCastWithParams( + address indexed voter, + uint256 proposalId, + uint8 support, + uint256 weight, + string reason, + bytes params + ); + /** * @notice module:core * @dev Name of the governor instance (used in building the ERC712 domain separator). diff --git a/test/governance/extensions/GovernorWithParams.test.js b/test/governance/extensions/GovernorWithParams.test.js index 6afb7dd5ed5..eca66a28ec1 100644 --- a/test/governance/extensions/GovernorWithParams.test.js +++ b/test/governance/extensions/GovernorWithParams.test.js @@ -141,12 +141,12 @@ contract('GovernorWithParams', function (accounts) { const tx = await this.mock.castVoteWithReasonAndParams(this.id, Enums.VoteType.For, '', params, { from: voter2 }); expectEvent(tx, 'CountParams', { uintParam, strParam }); - expectEvent(tx, 'VoteCast', { voter: voter2, weight: reducedWeight }); + expectEvent(tx, 'VoteCastWithParams', { voter: voter2, weight: reducedWeight, params }); }); runGovernorWorkflow(); }); - describe('Voting with params by signature is propoerly supported', function () { + describe('Voting with params by signature is properly supported', function () { const voterBySig = Wallet.generate(); // generate voter by signature wallet const sigVoterWeight = web3.utils.toWei('1.0'); @@ -226,7 +226,7 @@ contract('GovernorWithParams', function (accounts) { const tx = await this.mock.castVoteWithReasonAndParamsBySig(this.id, Enums.VoteType.For, reason, params, v, r, s); expectEvent(tx, 'CountParams', { uintParam, strParam }); - expectEvent(tx, 'VoteCast', { voter: this.voter, weight: reducedWeight }); + expectEvent(tx, 'VoteCastWithParams', { voter: this.voter, weight: reducedWeight, params }); }); runGovernorWorkflow(); });