Skip to content

Commit

Permalink
Add VoteCastWithParams event emitted when params are included
Browse files Browse the repository at this point in the history
  • Loading branch information
apbendi committed Feb 10, 2022
1 parent a2b04f6 commit 305211e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
6 changes: 5 additions & 1 deletion contracts/governance/Governor.sol
Expand Up @@ -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;
}
Expand Down
19 changes: 17 additions & 2 deletions contracts/governance/IGovernor.sol
Expand Up @@ -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).
Expand Down
6 changes: 3 additions & 3 deletions test/governance/extensions/GovernorWithParams.test.js
Expand Up @@ -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');

Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit 305211e

Please sign in to comment.