Skip to content

Commit

Permalink
bug fix for cancel - must calculate end time
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 authored Sep 30, 2022
1 parent 6728dee commit a90658f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1,379 deletions.
9 changes: 6 additions & 3 deletions contracts/GovernanceStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ contract GovernanceStorage is Storage, ERC165, Ownable {
/// @notice test if proposal is cancelled
/// @param _proposalId the id of the proposal
/// @return bool true if the proposal is marked cancelled
function isCancel(uint256 _proposalId) external view returns (bool) {
function isCancel(uint256 _proposalId) public view returns (bool) {
revertNotValid(_proposalId);
Proposal storage proposal = proposalMap[_proposalId];
return proposal.status == Status.CANCELLED;
Expand Down Expand Up @@ -453,8 +453,11 @@ contract GovernanceStorage is Storage, ERC165, Ownable {
uint256 latestProposalId = _latestProposalId[_sender];
if (latestProposalId != 0) {
Proposal storage lastProposal = proposalMap[latestProposalId];
// solhint-disable-next-line not-rely-on-time
require(isFinal(latestProposalId) && block.timestamp >= lastProposal.endTime, "Too many proposals");
require(
// solhint-disable-next-line not-rely-on-time
isCancel(latestProposalId) || (isFinal(latestProposalId) && block.timestamp >= lastProposal.endTime),
"Too many proposals"
);
}
_proposalCount++;
uint256 proposalId = _proposalCount;
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
},
"scripts": {
"build": "~mr/.cargo/bin/forge build --sizes",
"lint": "solium -d contracts",
"lint:fix": "solium -d contracts --fix",
"hint": "solhint contracts/**/*.sol test/**/*.sol",
"test": "~mr/.cargo/bin/forge test -vvv",
"clean": "~mr/.cargo/bin/forge clean"
Expand All @@ -21,7 +19,6 @@
"url": "git+https://github.com/momentranks/collective-governance-v1.git"
},
"devDependencies": {
"ethlint": "1.2.5",
"prettier": "2.7.1",
"prettier-plugin-solidity": "1.0.0-beta.24",
"solhint": "3.3.7",
Expand Down
10 changes: 9 additions & 1 deletion test/GovernanceStorage.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,15 @@ contract GovernanceStorageTest is Test {
_storage.registerSupervisor(PROPOSAL_ID, _SUPERVISOR, _OWNER);
_storage.makeFinal(PROPOSAL_ID, _SUPERVISOR);
vm.warp(block.timestamp + Constant.MINIMUM_VOTE_DURATION + 1);
_storage.initializeProposal(_OWNER);
uint256 nextProposalId = _storage.initializeProposal(_OWNER);
assertTrue(nextProposalId > PROPOSAL_ID);
}

function testExemptFromDelayIfCancel() public {
_storage.registerSupervisor(PROPOSAL_ID, _SUPERVISOR, _OWNER);
_storage.cancel(PROPOSAL_ID, _SUPERVISOR);
uint256 nextProposalId = _storage.initializeProposal(_OWNER);
assertTrue(nextProposalId > PROPOSAL_ID);
}

function testRevertOnSecondProposal() public {
Expand Down
Loading

0 comments on commit a90658f

Please sign in to comment.