Skip to content

Commit

Permalink
smoke test passing - bug fix active voting
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed Aug 22, 2022
1 parent 154ba72 commit 8b93518
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion contracts/CollectiveGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ contract CollectiveGovernance is Governance, VoteStrategy {

function isOpen(uint256 _proposalId) public view requireStrategyVersion(_proposalId) returns (bool) {
_storage._validOrRevert(_proposalId);
return isVoteOpenByProposalId[_proposalId];
uint256 endBlock = _storage.endBlock(_proposalId);
return isVoteOpenByProposalId[_proposalId] && block.number < endBlock;
}

/// @notice forbid any further voting
Expand All @@ -137,6 +138,9 @@ contract CollectiveGovernance is Governance, VoteStrategy {
requireVoteOpen(_proposalId)
{
_storage._validOrRevert(_proposalId);
if (!_storage.isReady(_proposalId)) {
_storage.makeReady(_proposalId);
}
uint256 _endBlock = _storage.endBlock(_proposalId);
require(_endBlock < block.number, "Voting remains active");
isVoteOpenByProposalId[_proposalId] = false;
Expand Down
2 changes: 1 addition & 1 deletion contracts/GovernanceStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ contract GovernanceStorage is Storage {

modifier requireVotingActive(uint256 _proposalId) {
Proposal storage proposal = proposalMap[_proposalId];
require(proposal.startBlock >= block.number && proposal.endBlock > block.number, "Vote not active");
require(proposal.startBlock <= block.number && proposal.endBlock > block.number, "Vote not active");
_;
}

Expand Down
14 changes: 13 additions & 1 deletion test/CollectiveGovernance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ contract CollectiveGovernanceTest is Test {
vm.stopPrank();
vm.prank(voter);
governance.voteFor(PROPOSAL_ID);
assertEq(_storage.forVotes(PROPOSAL_ID), 1);
}

function testCastSimpleVoteWhileActive() public {
vm.startPrank(owner, owner);
governance.configure(PROPOSAL_ID, 2, address(erc721), 10);
vm.stopPrank();
vm.prank(voter);
vm.roll(block.number + 2);
governance.voteFor(PROPOSAL_ID);
assertEq(_storage.forVotes(PROPOSAL_ID), 1);
}

function testFailNonVoter() public {
Expand All @@ -95,6 +106,7 @@ contract CollectiveGovernanceTest is Test {
vm.stopPrank();
vm.prank(voter);
governance.voteAgainst(PROPOSAL_ID);
assertEq(_storage.againstVotes(PROPOSAL_ID), 1);
}

function testFailVoteAgainstNonVoter() public {
Expand All @@ -111,6 +123,7 @@ contract CollectiveGovernanceTest is Test {
vm.stopPrank();
vm.prank(voter);
governance.abstainFromVote(PROPOSAL_ID);
assertEq(_storage.abstentionCount(PROPOSAL_ID), 1);
}

function testFailAbstentionNonVoter() public {
Expand Down Expand Up @@ -660,5 +673,4 @@ contract CollectiveGovernanceTest is Test {
function testFailDirectStorageAccessToVeto() public {
_storage._veto(PROPOSAL_ID);
}

}

0 comments on commit 8b93518

Please sign in to comment.