Skip to content

Commit

Permalink
Removed mostly-redundant function and made use of proposal builder in…
Browse files Browse the repository at this point in the history
… Drips tests
  • Loading branch information
jferas committed Dec 4, 2023
1 parent 3d870db commit 0d211b9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
74 changes: 27 additions & 47 deletions test/RadworksDripsGovernance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,34 @@ abstract contract RadworksDripsGovernance is ProposalTest {
_upgradeToBravoGovernor();
}

function _proposePassAndExecuteDripsProposal(string memory _description, bytes memory _callData)
internal
{
address[] memory _targets = new address[](1);
uint256[] memory _values = new uint256[](1);
bytes[] memory _calldatas = new bytes[](1);

_targets[0] = DRIPS;
_calldatas[0] = _callData;

// Submit the new proposal
vm.prank(PROPOSER);
uint256 _newProposalId = governorBravo.propose(_targets, _values, _calldatas, _description);

// Ensure proposal is in the expected state
IGovernor.ProposalState _state = governorBravo.state(_newProposalId);
assertEq(_state, IGovernor.ProposalState.Pending);

_jumpToActiveProposal(_newProposalId);

_delegatesCastVoteOnBravoGovernor(_newProposalId, FOR);
_jumpToVotingComplete(_newProposalId);

// Ensure the proposal has succeeded
_state = governorBravo.state(_newProposalId);
assertEq(_state, IGovernor.ProposalState.Succeeded);

// Queue the proposal
governorBravo.queue(_targets, _values, _calldatas, keccak256(bytes(_description)));

// Ensure the proposal is queued
_state = governorBravo.state(_newProposalId);
assertEq(_state, IGovernor.ProposalState.Queued);

_jumpPastProposalEta(_newProposalId);

// Execute the proposal
governorBravo.execute(_targets, _values, _calldatas, keccak256(bytes(_description)));

// Ensure the proposal is executed
_state = governorBravo.state(_newProposalId);
assertEq(_state, IGovernor.ProposalState.Executed);
}

function _grantNewPauserViaGovernance(address _newPauser) internal {
_proposePassAndExecuteDripsProposal(
(
address[] memory _targets,
uint256[] memory _values,
bytes[] memory _calldatas,
string memory _description
) = _buildDripsGovernanceProposal(
"Grant Pauser role to an address",
_buildProposalData("grantPauser(address)", abi.encode(_newPauser))
);
_queueAndVoteAndExecuteProposalWithBravoGovernor(
_targets, _values, _calldatas, _description, FOR
);
}

function _revokePauserViaGovernance(address _newPauser) internal {
_proposePassAndExecuteDripsProposal(
(
address[] memory _targets,
uint256[] memory _values,
bytes[] memory _calldatas,
string memory _description
) = _buildDripsGovernanceProposal(
"Revoke Pauser role from an address",
_buildProposalData("revokePauser(address)", abi.encode(_newPauser))
);
_queueAndVoteAndExecuteProposalWithBravoGovernor(
_targets, _values, _calldatas, _description, FOR
);
}

function testFuzz_grantPauserOnDrips(address _newPauser) public {
Expand Down Expand Up @@ -110,9 +82,17 @@ abstract contract RadworksDripsGovernance is ProposalTest {
}

function test_renounceAdminViaGovernance() public {
_proposePassAndExecuteDripsProposal(
(
address[] memory _targets,
uint256[] memory _values,
bytes[] memory _calldatas,
string memory _description
) = _buildDripsGovernanceProposal(
"Renounce Admin role", _buildProposalData("renounceAdmin()", abi.encode())
);
_queueAndVoteAndExecuteProposalWithBravoGovernor(
_targets, _values, _calldatas, _description, FOR
);

// Ensure the admin role has been renounced
assertEq(drips.admin(), address(0));
Expand Down
20 changes: 20 additions & 0 deletions test/helpers/ProposalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ abstract contract ProposalTest is RadworksGovernorTest {
return abi.encodePacked(bytes4(keccak256(bytes(_signature))), _calldata);
}

function _buildDripsGovernanceProposal(string memory _description, bytes memory _callData)
internal
pure
returns (
address[] memory _targets,
uint256[] memory _values,
bytes[] memory _calldata,
string memory _returnedDescription
)
{
// Craft a new proposal to peform a Drips governance operation.
_targets = new address[](1);
_values = new uint256[](1);
_calldata = new bytes[](1);

_targets[0] = DRIPS;
_calldata[0] = _callData;
_returnedDescription = _description;
}

function _jumpToActiveProposal(uint256 _proposalId) internal {
uint256 _snapshot = governorBravo.proposalSnapshot(_proposalId);
vm.roll(_snapshot + 1);
Expand Down

0 comments on commit 0d211b9

Please sign in to comment.