diff --git a/test/AutomatedVoting.t.sol b/test/AutomatedVoting.t.sol index 8648dd38..ebcbd807 100644 --- a/test/AutomatedVoting.t.sol +++ b/test/AutomatedVoting.t.sol @@ -1135,6 +1135,43 @@ contract AutomatedVotingTest is DefaultStakingV2Setup { assertEq(result[4], user4); } + function testSortCandidatesPositionStaysAtIndex4() public { + vm.warp(block.timestamp + 21 weeks); + automatedVotingInternals.startScheduledElection(); + fundAccountAndStakeV2(user1, 1); + fundAccountAndStakeV2(user2, 1); + fundAccountAndStakeV2(user3, 1); + fundAccountAndStakeV2(user4, 1); + fundAccountAndStakeV2(user5, 1); + vm.prank(user1); + automatedVotingInternals.nominateMultipleCandidates(1, council); + vm.warp(block.timestamp + 1 weeks); + + vm.prank(user1); + automatedVotingInternals.vote(1, user1); + vm.prank(user2); + automatedVotingInternals.vote(1, user2); + vm.prank(user3); + automatedVotingInternals.vote(1, user3); + vm.prank(user4); + automatedVotingInternals.vote(1, user4); + + assertEq(automatedVotingInternals.getCandidateAddress(1, 0), user1); + assertEq(automatedVotingInternals.getCandidateAddress(1, 1), user2); + assertEq(automatedVotingInternals.getCandidateAddress(1, 2), user3); + assertEq(automatedVotingInternals.getCandidateAddress(1, 3), user4); + assertEq(automatedVotingInternals.getCandidateAddress(1, 4), user5); + + address[] memory result = automatedVotingInternals.sortCandidates(1, user5, 1); + + /// @dev make sure index 4 doesnt move + assertEq(result[0], user1); + assertEq(result[1], user2); + assertEq(result[2], user3); + assertEq(result[3], user4); + assertEq(result[4], user5); + } + // _cancelOngoingElections() function testCancelOngoingElectionsStepDown() public {