Skip to content

Commit

Permalink
Add Drips protocol upgrade via governance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jferas committed Dec 8, 2023
1 parent 56b21aa commit 098de5e
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion test/RadworksDripsGovernance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@
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";

import {console2} from "forge-std/console2.sol";

/// @dev This contract 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 @@ -41,9 +58,32 @@ abstract contract RadworksDripsGovernance is ProposalTest {
}

function _proposeNewAdminViaGovernance(address _newAdmin) internal {
_proposePassAndExecuteDripsProposal(
(
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 {
Expand Down Expand Up @@ -144,6 +184,14 @@ abstract contract RadworksDripsGovernance is ProposalTest {
// 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

0 comments on commit 098de5e

Please sign in to comment.