From 9e66e2f9f5567e20e76cf84b95929327485a7807 Mon Sep 17 00:00:00 2001 From: planetBoy <140164174+Guayaba221@users.noreply.github.com> Date: Wed, 22 Jan 2025 20:38:10 +0100 Subject: [PATCH] Replace `overriden` with `overridden` in GovernorCountingOverridable.sol (#5446) Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com> Co-authored-by: ernestognw --- CHANGELOG.md | 8 +++++ .../GovernorCountingOverridable.sol | 34 +++++++++---------- .../GovernorCountingOverridable.test.js | 2 +- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 392b882ce..8b582d2fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +### Breaking Changes + +- Replace `GovernorCountingOverridable.VoteReceipt` struct parameter member names `hasOverriden` and `overridenWeight` for `hasOverridden` and `overriddenWeight` respectively. + +#### Custom error changes + +- Replace `GovernorAlreadyOverridenVote` with `GovernorAlreadyOverriddenVote`. + ## 5.2.0 (2025-01-08) ### Breaking Changes diff --git a/contracts/governance/extensions/GovernorCountingOverridable.sol b/contracts/governance/extensions/GovernorCountingOverridable.sol index 2ed6c1cc5..43d1401db 100644 --- a/contracts/governance/extensions/GovernorCountingOverridable.sol +++ b/contracts/governance/extensions/GovernorCountingOverridable.sol @@ -27,8 +27,8 @@ abstract contract GovernorCountingOverridable is GovernorVotes { struct VoteReceipt { uint8 casted; // 0 if vote was not casted. Otherwise: support + 1 - bool hasOverriden; - uint208 overridenWeight; + bool hasOverridden; + uint208 overriddenWeight; } struct ProposalVote { @@ -42,7 +42,7 @@ abstract contract GovernorCountingOverridable is GovernorVotes { /// @dev A delegated vote on `proposalId` was overridden by `weight` event OverrideVoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 weight, string reason); - error GovernorAlreadyOverridenVote(address account); + error GovernorAlreadyOverriddenVote(address account); mapping(uint256 proposalId => ProposalVote) private _proposalVotes; @@ -70,7 +70,7 @@ abstract contract GovernorCountingOverridable is GovernorVotes { * @dev Check if an `account` has overridden their delegate for a proposal. */ function hasVotedOverride(uint256 proposalId, address account) public view virtual returns (bool) { - return _proposalVotes[proposalId].voteReceipt[account].hasOverriden; + return _proposalVotes[proposalId].voteReceipt[account].hasOverridden; } /** @@ -122,7 +122,7 @@ abstract contract GovernorCountingOverridable is GovernorVotes { revert GovernorAlreadyCastVote(account); } - totalWeight -= proposalVote.voteReceipt[account].overridenWeight; + totalWeight -= proposalVote.voteReceipt[account].overriddenWeight; proposalVote.votes[support] += totalWeight; proposalVote.voteReceipt[account].casted = support + 1; @@ -141,26 +141,26 @@ abstract contract GovernorCountingOverridable is GovernorVotes { revert GovernorInvalidVoteType(); } - if (proposalVote.voteReceipt[account].hasOverriden) { - revert GovernorAlreadyOverridenVote(account); + if (proposalVote.voteReceipt[account].hasOverridden) { + revert GovernorAlreadyOverriddenVote(account); } uint256 snapshot = proposalSnapshot(proposalId); - uint256 overridenWeight = VotesExtended(address(token())).getPastBalanceOf(account, snapshot); + uint256 overriddenWeight = VotesExtended(address(token())).getPastBalanceOf(account, snapshot); address delegate = VotesExtended(address(token())).getPastDelegate(account, snapshot); uint8 delegateCasted = proposalVote.voteReceipt[delegate].casted; - proposalVote.voteReceipt[account].hasOverriden = true; - proposalVote.votes[support] += overridenWeight; + proposalVote.voteReceipt[account].hasOverridden = true; + proposalVote.votes[support] += overriddenWeight; if (delegateCasted == 0) { - proposalVote.voteReceipt[delegate].overridenWeight += SafeCast.toUint208(overridenWeight); + proposalVote.voteReceipt[delegate].overriddenWeight += SafeCast.toUint208(overriddenWeight); } else { uint8 delegateSupport = delegateCasted - 1; - proposalVote.votes[delegateSupport] -= overridenWeight; - emit VoteReduced(delegate, proposalId, delegateSupport, overridenWeight); + proposalVote.votes[delegateSupport] -= overriddenWeight; + emit VoteReduced(delegate, proposalId, delegateSupport, overriddenWeight); } - return overridenWeight; + return overriddenWeight; } /// @dev Variant of {Governor-_castVote} that deals with vote overrides. Returns the overridden weight. @@ -172,13 +172,13 @@ abstract contract GovernorCountingOverridable is GovernorVotes { ) internal virtual returns (uint256) { _validateStateBitmap(proposalId, _encodeStateBitmap(ProposalState.Active)); - uint256 overridenWeight = _countOverride(proposalId, account, support); + uint256 overriddenWeight = _countOverride(proposalId, account, support); - emit OverrideVoteCast(account, proposalId, support, overridenWeight, reason); + emit OverrideVoteCast(account, proposalId, support, overriddenWeight, reason); _tallyUpdated(proposalId); - return overridenWeight; + return overriddenWeight; } /// @dev Public function for casting an override vote. Returns the overridden weight. diff --git a/test/governance/extensions/GovernorCountingOverridable.test.js b/test/governance/extensions/GovernorCountingOverridable.test.js index 32ee47439..fd1032b9e 100644 --- a/test/governance/extensions/GovernorCountingOverridable.test.js +++ b/test/governance/extensions/GovernorCountingOverridable.test.js @@ -264,7 +264,7 @@ describe('GovernorCountingOverridable', function () { .to.emit(this.mock, 'OverrideVoteCast') .withArgs(this.voter1, this.helper.id, VoteType.Against, ethers.parseEther('10'), ''); await expect(this.mock.connect(this.voter1).castOverrideVote(this.helper.id, VoteType.Abstain, '')) - .to.be.revertedWithCustomError(this.mock, 'GovernorAlreadyOverridenVote') + .to.be.revertedWithCustomError(this.mock, 'GovernorAlreadyOverriddenVote') .withArgs(this.voter1.address); });