Skip to content

Commit

Permalink
👷 change single to replacement election
Browse files Browse the repository at this point in the history
  • Loading branch information
cmontecoding committed Sep 26, 2023
1 parent 2d5f7bb commit a2f34d7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions src/AutomatedVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ contract AutomatedVoting is IAutomatedVoting {
delete council[i];
}
}
_startElection(Enums.electionType.single);
_startElection(Enums.electionType.replacement);
}

/// @notice starts a community election
Expand Down Expand Up @@ -316,7 +316,7 @@ contract AutomatedVoting is IAutomatedVoting {
}
}
// start election state
_startElection(Enums.electionType.single);
_startElection(Enums.electionType.replacement);
}

/// @notice finalizes an election
Expand Down Expand Up @@ -368,9 +368,9 @@ contract AutomatedVoting is IAutomatedVoting {
if (elections[election].isNominated[candidate]) {
revert CandidateAlreadyNominated();
}
/// @dev this prevent a council member from being nominated in a single election (becoming member twice)
/// @dev this prevent a council member from being nominated in a replacement election (becoming member twice)
if (
elections[election].theElectionType == Enums.electionType.single &&
elections[election].theElectionType == Enums.electionType.replacement &&
isCouncilMember(candidate)
) {
revert CandidateIsAlreadyCouncilMember();
Expand All @@ -379,7 +379,7 @@ contract AutomatedVoting is IAutomatedVoting {
elections[election].isNominated[candidate] = true;
}

/// @notice votes for a candidate in a single election
/// @notice votes for a candidate in a replacement election
/// @param _election the election to vote in
/// @param candidate the candidate to vote for
function vote(
Expand Down Expand Up @@ -501,9 +501,9 @@ contract AutomatedVoting is IAutomatedVoting {
//todo: maybe emit an event that quorum was not reached
}
} else if (
elections[_election].theElectionType == Enums.electionType.single
elections[_election].theElectionType == Enums.electionType.replacement
) {
/// @dev this is for a single election
/// @dev this is for a replacement election
address winner = elections[_election].candidateAddresses[0];
for (uint i = 0; i < council.length; i++) {
if (council[i] == address(0)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Enums.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ contract Enums {
enum electionType {
scheduled,
community,
single //todo: make replacement election
replacement
}
}
26 changes: 13 additions & 13 deletions test/AutomatedVoting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ contract AutomatedVotingTest is DefaultStakingV2Setup {
) = automatedVoting.elections(1);
assertEq(electionStartTime, block.timestamp);
assertEq(isFinalized, false);
assertTrue(theElectionType == Enums.electionType.single);
assertTrue(theElectionType == Enums.electionType.replacement);
assertEq(stakedAmountsForQuorum, 0);

council = automatedVoting.getCouncil();
Expand Down Expand Up @@ -639,7 +639,7 @@ contract AutomatedVotingTest is DefaultStakingV2Setup {

// nominateCandidate()

function testNominateInSingleElectionSuccess() public {
function testNominateInReplacementElectionSuccess() public {
fundAccountAndStakeV2(user1, 1);
vm.prank(user2);
automatedVoting.stepDown();
Expand All @@ -652,7 +652,7 @@ contract AutomatedVotingTest is DefaultStakingV2Setup {
assertEq(automatedVoting.getIsNominated(1, user1), false);
}

function testNominateInSingleElectionNotStaked() public {
function testNominateInReplacementElectionNotStaked() public {
vm.warp(block.timestamp + 21 weeks);
vm.prank(user2);
automatedVoting.stepDown();
Expand All @@ -664,7 +664,7 @@ contract AutomatedVotingTest is DefaultStakingV2Setup {
automatedVoting.nominateCandidate(1, user1);
}

function testNominateInSingleElectionNotDuringNomination() public {
function testNominateInReplacementElectionNotDuringNomination() public {
vm.warp(block.timestamp + 21 weeks);
fundAccountAndStakeV2(user1, 1);
vm.prank(user2);
Expand All @@ -679,7 +679,7 @@ contract AutomatedVotingTest is DefaultStakingV2Setup {
automatedVoting.nominateCandidate(1, user1);
}

function testNominateInSingleElectionAlreadyMember() public {
function testNominateInReplacementElectionAlreadyMember() public {
fundAccountAndStakeV2(user1, 1);
vm.prank(user2);
automatedVoting.stepDown();
Expand All @@ -693,9 +693,9 @@ contract AutomatedVotingTest is DefaultStakingV2Setup {
automatedVoting.nominateCandidate(1, user1);
}

// voteInSingleElection()
// voteInReplacementElection()

function testVoteInSingleElectionSuccess() public {
function testVoteInReplacementElectionSuccess() public {
vm.warp(block.timestamp + 21 weeks);
fundAccountAndStakeV2(user1, 1);
vm.prank(user2);
Expand All @@ -714,7 +714,7 @@ contract AutomatedVotingTest is DefaultStakingV2Setup {
assertFalse(automatedVoting.getHasVoted(1, user6));
}

function testVoteInSingleElectionNotStaked() public {
function testVoteInReplacementElectionNotStaked() public {
vm.warp(block.timestamp + 21 weeks);
vm.prank(user2);
automatedVoting.stepDown();
Expand All @@ -726,7 +726,7 @@ contract AutomatedVotingTest is DefaultStakingV2Setup {
automatedVoting.vote(1, user1);
}

function testVoteInSingleElectionNotDuringVoting() public {
function testVoteInReplacementElectionNotDuringVoting() public {
vm.warp(block.timestamp + 21 weeks);
fundAccountAndStakeV2(user1, 1);
vm.prank(user2);
Expand All @@ -741,7 +741,7 @@ contract AutomatedVotingTest is DefaultStakingV2Setup {
automatedVoting.vote(1, user1);
}

function testVoteInSingleElectionAlreadyEnded() public {
function testVoteInReplacementElectionAlreadyEnded() public {
vm.warp(block.timestamp + 21 weeks);
automatedVoting.startScheduledElection();
fundAccountAndStakeV2(user1, 1);
Expand All @@ -755,7 +755,7 @@ contract AutomatedVotingTest is DefaultStakingV2Setup {
automatedVoting.vote(1, user1);
}

function testVoteInSingleElectionAlreadyVoted() public {
function testVoteInReplacementElectionAlreadyVoted() public {
vm.warp(block.timestamp + 21 weeks);
fundAccountAndStakeV2(user1, 1);
vm.prank(user2);
Expand All @@ -772,7 +772,7 @@ contract AutomatedVotingTest is DefaultStakingV2Setup {
automatedVoting.vote(1, user6);
}

function testVoteInSingleElectionCandidateNotNominated() public {
function testVoteInReplacementElectionCandidateNotNominated() public {
vm.warp(block.timestamp + 21 weeks);
fundAccountAndStakeV2(user1, 1);
vm.prank(user2);
Expand Down Expand Up @@ -1284,7 +1284,7 @@ contract AutomatedVotingTest is DefaultStakingV2Setup {
assertEq(automatedVotingInternals.isElectionFinalized(2), false);
(, , , Enums.electionType theElectionType) = automatedVotingInternals
.elections(1);
assertTrue(theElectionType == Enums.electionType.single);
assertTrue(theElectionType == Enums.electionType.replacement);
automatedVotingInternals.cancelOngoingElectionsInternal();
assertEq(automatedVotingInternals.isElectionFinalized(1), true);
assertEq(automatedVotingInternals.isElectionFinalized(2), true);
Expand Down

0 comments on commit a2f34d7

Please sign in to comment.