Skip to content

Commit

Permalink
Lock to vote tests definnition
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Jan 24, 2025
1 parent 2896418 commit 8f73ec6
Show file tree
Hide file tree
Showing 3 changed files with 484 additions and 30 deletions.
23 changes: 8 additions & 15 deletions src/LockToVotePlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contract LockToVotePlugin is ILockToVote, MajorityVotingBase, LockToVoteBase {
bytes32 public constant LOCK_MANAGER_PERMISSION_ID = keccak256("LOCK_MANAGER_PERMISSION");

event VoteCleared(uint256 proposalId, address voter);
error VoteRemovalForbidden(uint256 proposalId, address voter);

/// @notice Initializes the component.
/// @dev This method is required to support [ERC-1822](https://eips.ethereum.org/EIPS/eip-1822).
Expand Down Expand Up @@ -205,9 +206,13 @@ contract LockToVotePlugin is ILockToVote, MajorityVotingBase, LockToVoteBase {
/// @inheritdoc ILockToVote
function clearVote(uint256 _proposalId, address _voter) external auth(LOCK_MANAGER_PERMISSION_ID) {
Proposal storage proposal_ = proposals[_proposalId];
if (proposal_.votes[_voter].votingPower == 0 || !_isProposalOpen(proposal_)) {
if (proposal_.votes[_voter].votingPower == 0) {
// Nothing to do
return;
} else if (!_isProposalOpen(proposal_)) {
revert VoteRemovalForbidden(_proposalId, _voter);
} else if (proposal_.parameters.votingMode == VotingMode.EarlyExecution) {
revert VoteRemovalForbidden(_proposalId, _voter);
}

// Undo that vote
Expand Down Expand Up @@ -261,7 +266,7 @@ contract LockToVotePlugin is ILockToVote, MajorityVotingBase, LockToVoteBase {
return false;
}
// No voting power or lowering the existing one is not allowed
else if (_newVotingPower == 0 || _newVotingPower < proposal_.votes[_voter].votingPower) {
else if (_newVotingPower == 0 || _newVotingPower <= proposal_.votes[_voter].votingPower) {
return false;
}
// The voter has already voted but vote replacment is not allowed.
Expand All @@ -286,19 +291,7 @@ contract LockToVotePlugin is ILockToVote, MajorityVotingBase, LockToVoteBase {
}

function _execute(uint256 _proposalId) internal override {
Proposal storage proposal_ = proposals[_proposalId];
proposal_.executed = true;

// IProposal's target execution
_execute(
proposal_.targetConfig.target,
bytes32(_proposalId),
proposal_.actions,
proposal_.allowFailureMap,
proposal_.targetConfig.operation
);

emit ProposalExecuted(_proposalId);
super._execute(_proposalId);

// Notify the LockManager to stop tracking this proposal ID
lockManager.proposalEnded(_proposalId);
Expand Down
Loading

0 comments on commit 8f73ec6

Please sign in to comment.