The variable `s_previousVoteEndTimeStamp` is not initialized, having value 0. This does not allow the president to be selected using the `RankedChoice::selectPresident`.
The if condition in the `selectPresident` function will never be satisfied.
https://github.com/Cyfrin/2024-09-president-elector/blob/main/src/RankedChoice.sol#L61C1-L63C34
```
if (
block.timestamp - s_previousVoteEndTimeStamp <=
i_presidentalDuration
) {
revert RankedChoice__NotTimeToVote();
}
```
The contract cannot be used to select the president calling the ` RankedChoice::selectPresident`.
Add an array of addresses and run this test:
POC
```
address[] orderedCandidates2;
function test_presidentselect() public {
orderedCandidates = [candidates[1], candidates[0], candidates[2]];
orderedCandidates2 = [candidates[2], candidates[0], candidates[1]];
vm.startPrank(voters[0]);
rankedChoice.rankCandidates(orderedCandidates);
vm.startPrank(voters[1]);
rankedChoice.rankCandidates(orderedCandidates);
vm.startPrank(voters[2]);
rankedChoice.rankCandidates(orderedCandidates2);
rankedChoice.selectPresident();
vm.stopPrank();
}
```
```
Ran 1 test for test/RankedChoiceTest.t.sol:RankedChoiceTest
[FAIL. Reason: RankedChoice__NotTimeToVote()] test_presidentselect() (gas: 742199)
Traces:
[6138629] RankedChoiceTest::setUp()
├─ [3311456] → new RankedChoice@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
│ └─ ← [Return] 5119 bytes of code
└─ ← [Stop]
:br:br
[742199] RankedChoiceTest::test_presidentselect()
├─ [0] VM::prank(0x0000000000000000000000000000000000000064)
│ └─ ← [Return]
├─ [312448] RankedChoice::rankCandidates([0x00000000000000000000000000000000000000C9, 0x00000000000000000000000000000000000000C8, 0x00000000000000000000000000000000000000ca])
│ └─ ← [Stop]
├─ [0] VM::prank(0x0000000000000000000000000000000000000065)
│ └─ ← [Return]
├─ [108602] RankedChoice::rankCandidates([0x00000000000000000000000000000000000000C9, 0x00000000000000000000000000000000000000C8, 0x00000000000000000000000000000000000000ca])
│ └─ ← [Stop]
├─ [0] VM::prank(0x0000000000000000000000000000000000000066)
│ └─ ← [Return]
├─ [108756] RankedChoice::rankCandidates([0x00000000000000000000000000000000000000ca, 0x00000000000000000000000000000000000000C8, 0x00000000000000000000000000000000000000C9])
│ └─ ← [Stop]
├─ [2451] RankedChoice::selectPresident()
│ └─ ← [Revert] RankedChoice__NotTimeToVote()
└─ ← [Revert] RankedChoice__NotTimeToVote()
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 2.21ms (475.53µs CPU time)
```
Manual review
```diff
- if (block.timestamp - s_previousVoteEndTimeStamp <= i_presidentalDuration)
+ if (s_previousVoteEndTimeStamp != 0 && block.timestamp - s_previousVoteEndTimeStamp <= i_presidentalDuration)
{
revert RankedChoice__NotTimeToVote();
}
```
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.