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

Added tests for changing admin/upgrading protocol via governance #21

Merged
merged 6 commits into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions test/RadworksDripsGovernance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@
pragma solidity ^0.8.20;

import {IGovernor} from "@openzeppelin/contracts/governance/IGovernor.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import {ProposalTest} from "test/helpers/ProposalTest.sol";

/// @dev This contract is used in the testing of using governance to upgrade the Drips protocol
/// It has just enough infrastructure to be installed as a new implementation of the Drips proxy.
contract DripsUpgradeContract is UUPSUpgradeable {
function _authorizeUpgrade(address) internal override {}

function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
return _IMPLEMENTATION_SLOT;
}

function implementation() external view returns (address impl) {
return _getImplementation();
}
}

abstract contract RadworksDripsGovernance is ProposalTest {
function setUp() public virtual override(ProposalTest) {
ProposalTest.setUp();
Expand Down Expand Up @@ -40,6 +55,35 @@ abstract contract RadworksDripsGovernance is ProposalTest {
);
}

function _proposeNewAdminViaGovernance(address _newAdmin) internal {
(
address[] memory _targets,
uint256[] memory _values,
bytes[] memory _calldatas,
string memory _description
) = _buildDripsGovernanceProposal(
"Propose new Admin", _buildProposalData("proposeNewAdmin(address)", abi.encode(_newAdmin))
);
_queueAndVoteAndExecuteProposalWithBravoGovernor(
_targets, _values, _calldatas, _description, FOR
);
}

function _performDripsUpgradeViaGovernance(address _newImplementation) internal {
(
address[] memory _targets,
uint256[] memory _values,
bytes[] memory _calldatas,
string memory _description
) = _buildDripsGovernanceProposal(
"Propose upgrade to new implementation",
_buildProposalData("upgradeTo(address)", abi.encode(_newImplementation))
);
_queueAndVoteAndExecuteProposalWithBravoGovernor(
_targets, _values, _calldatas, _description, FOR
);
}

function testFuzz_grantPauserOnDrips(address _newPauser) public {
_assumeNotTimelock(_newPauser);
vm.assume(!drips.isPauser(_newPauser));
Expand Down Expand Up @@ -119,6 +163,34 @@ abstract contract RadworksDripsGovernance is ProposalTest {
// Ensure the admin role has been renounced
assertEq(drips.admin(), address(0));
}

function testFuzz_proposeNewAdminViaGovernance(address _newAdmin) public {
_assumeNotTimelock(_newAdmin);
_proposeNewAdminViaGovernance(_newAdmin);

// Ensure the new admin has been proposed
assertEq(drips.proposedAdmin(), _newAdmin);

// Ensure the new admin can accept the admin role
vm.prank(_newAdmin);
drips.acceptAdmin();
assertEq(drips.admin(), _newAdmin);

// Ensure the new admin can renounce admin role (which only an admin can do)
vm.prank(_newAdmin);
drips.renounceAdmin();

// Ensure the admin role has been renounced
assertEq(drips.admin(), address(0));
}

function test_UpgradeDripsViaGovernance() public {
DripsUpgradeContract _newImplementation = new DripsUpgradeContract();
_performDripsUpgradeViaGovernance(address(_newImplementation));

// // Ensure the new implementation has been set
assertEq(drips.implementation(), address(_newImplementation));
}
}

contract _ExecuteTestWithDeployScriptGovernor is RadworksDripsGovernance {
Expand Down
Loading