Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cancel logic and tests #36

Merged
merged 7 commits into from
Oct 23, 2024
Merged

Conversation

garyghayrat
Copy link
Member

closes #28

contracts/CompoundGovernor.sol Show resolved Hide resolved
}

function _removeDelegateeVotingWeight() private {
vm.prank(COMPOUND_COMPTROLLER);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's going on here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reimplemented #36 (comment)

_randomIndex = bound(_randomIndex, 0, _majorDelegates.length - 1);
address _proposer = _majorDelegates[_randomIndex];
Proposal memory _proposal = _buildAnEmptyProposal();
uint256 _proposalId = governor.hashProposal(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and elsewhere, can you refactor calls to governor.hashProposal so that it reads from an internal method here _getProposalId? in that method, we'll call governor.hashProposal for now, but when @jferas's enumerable proposalIds comes down, we can make a oneline change to support

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, made the changes in e01c34e

);
vm.prank(whitelistGuardian);
governor.setWhitelistAccountExpiration(delegatee, block.timestamp + 2_000_000);
vm.assertTrue(governor.isWhitelisted(delegatee));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't a test for whether setWhitelist... works, so this assertion can be removed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed in 03a8682

_proposal.targets, _proposal.values, _proposal.calldatas, keccak256(bytes(_proposal.description))
);
vm.prank(whitelistGuardian);
governor.setWhitelistAccountExpiration(delegatee, block.timestamp + 2_000_000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we refactor lines 76-77 to internal helper _setWhitelistedProposer(_proposer)?

can we fuzz proposer here? i see the problem with fuzzing proposer -- later, we have to remove the delegatee voting weight. ideally we could do that for any address, not just delegatee. is it difficult?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was not difficult using mockCall cheatcode. Now fuzzing the proposer in 9bd64df

contracts/test/CompoundGovernorCancelTest.t.sol Outdated Show resolved Hide resolved
contracts/test/CompoundGovernorCancelTest.t.sol Outdated Show resolved Hide resolved
);
}

function testFuzz_RevertIf_AnyoneCancelsWhitelistedProposalAboveThreshold(address _caller, uint256 _randomIndex)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function testFuzz_RevertIf_AnyoneCancelsWhitelistedProposalAboveThreshold(address _caller, uint256 _randomIndex)
function testFuzz_RevertIf_NonProposerOrGuardianCancelsWhitelistedProposalAboveThreshold(address _caller, uint256 _randomIndex)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contracts/test/CompoundGovernorCancelTest.t.sol Outdated Show resolved Hide resolved
Copy link
Collaborator

@wildmolasses wildmolasses left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm; docstring nit and reminder for alt cancel method

@@ -116,6 +116,37 @@ contract CompoundGovernor is
_setProposalGuardian(_proposalGuardian);
}

/// @notice Cancels an active proposal.
/// @notice This function can be called by the proposer, the proposal guardian, or anyone if the proposer's voting
/// power has dropped below the proposal threshold. For whitelisted proposers, only the whitelist guardian can
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// power has dropped below the proposal threshold. For whitelisted proposers, only the whitelist guardian can
/// power has dropped below the proposal threshold. For whitelisted proposers, only special actors (proposer, proposer guardian, whitelist guardian) can

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// @param calldatas An array of calldata to be sent to each address when the proposal is executed.
/// @param descriptionHash The hash of the proposal's description string.
/// @return uint256 The ID of the canceled proposal.
function cancel(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this will also have to be reproduced for the cancel(uint proposalId) method in #3.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created an issue so we don't forget #37

@wildmolasses wildmolasses changed the base branch from feat/add-whitelists-and-guardians to main October 23, 2024 15:49
@garyghayrat garyghayrat force-pushed the feat/add-custom-cancel-logic branch from bafcd0f to cc14c23 Compare October 23, 2024 16:10
@coveralls
Copy link

Pull Request Test Coverage Report for Build 11483898126

Details

  • 0 of 8 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-2.0%) to 85.284%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contracts/CompoundGovernor.sol 0 8 0.0%
Totals Coverage Status
Change from base Build 11483831703: -2.0%
Covered Lines: 318
Relevant Lines: 378

💛 - Coveralls

@wildmolasses wildmolasses merged commit 947ccc2 into main Oct 23, 2024
3 checks passed
wildmolasses added a commit that referenced this pull request Nov 1, 2024
* Add cancel logic and tests

* Use `_getProposalId` instead of `hashProposal` to prep for upcoming change

* Rename and cleanup test

* Use helpers to set whitelist accounts and remove voting weight

* Clean up test

* Update natspec

* docstring nit

---------

Co-authored-by: Ed Mazurek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: Anyone is able to cancel a proposal if its proposer falls below threshold
3 participants