Skip to content

Commit

Permalink
electionModule test ok
Browse files Browse the repository at this point in the history
  • Loading branch information
0xclem committed Nov 1, 2023
1 parent 2e90a51 commit 5d974b6
Show file tree
Hide file tree
Showing 4 changed files with 480 additions and 293 deletions.
5 changes: 5 additions & 0 deletions src/CouncilGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ contract CouncilGovernor {
}
}

function _addMemberToCouncil(address _winner) internal {
if (safeProxy.getOwners().length == COUNCIL_SEATS_NUMBER) revert Error.NoSeatAvailableInCouncil();
_addOwnerWithThreshold(_winner, THRESHOLD);
}

function _removeMemberFromCouncil(address _member) internal {
address[] memory currentOwners = safeProxy.getOwners();
if (currentOwners.length < COUNCIL_SEATS_NUMBER) revert Error.NotEnoughMembersInCouncil();
Expand Down
17 changes: 11 additions & 6 deletions src/ElectionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,23 +240,28 @@ contract ElectionModule is CouncilGovernor, IElectionModule {
if (isElectionFinalized()) revert Error.ElectionFinalizedOrInvalid();
if (block.timestamp < getElectionEndTime(currentElection)) revert Error.ElectionNotReadyToBeFinalized();

Election storage election = elections[currentElection];

/// @dev if there are no votes, or if quorum isn't met for a Community Election then the election is invalid and needs to be canceled
uint256 seatsNumber = getAvailableSeatsForElection(elections[currentElection].electionType);
uint256 seatsNumber = getAvailableSeatsForElection(election.electionType);
if (
elections[currentElection].winners.length() < seatsNumber ||
(elections[currentElection].electionType == ElectionType.Community &&
elections[currentElection].totalVotes < getQuorum(elections[currentElection].startTime))
election.winners.length() < seatsNumber ||
(election.electionType == ElectionType.Community && election.totalVotes < getQuorum(election.startTime))
) {
_cancelElection();
return;
}

emit ElectionFinalized(currentElection);

elections[currentElection].status = ElectionStatus.Finalized;
election.status = ElectionStatus.Finalized;
lastFinalizedScheduledElection = currentElection;

_initiateNewCouncil(elections[currentElection].winners);
if (election.electionType == ElectionType.Replacement) {
_addMemberToCouncil(election.winners.at(0));
} else {
_initiateNewCouncil(election.winners);
}
}

function cancelElection() external {
Expand Down
Loading

0 comments on commit 5d974b6

Please sign in to comment.