Skip to content

Commit

Permalink
Merge pull request #2 from aragon/f/testing-suite
Browse files Browse the repository at this point in the history
Expanding the testing suite
  • Loading branch information
brickpop committed Nov 21, 2023
2 parents 31d7365 + 2ee7759 commit f25ea1d
Show file tree
Hide file tree
Showing 6 changed files with 1,030 additions and 137 deletions.
10 changes: 0 additions & 10 deletions src/OptimisticTokenVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,6 @@ contract OptimisticTokenVotingPlugin is
});
}

if (
totalVotingPower(block.number - 1) <
_governanceSettings.minProposerVotingPower
) {
revert MinProposerVotingPowerOutOfBounds({
limit: totalVotingPower(block.number - 1),
actual: _governanceSettings.minProposerVotingPower
});
}

governanceSettings = _governanceSettings;

emit OptimisticGovernanceSettingsUpdated({
Expand Down
7 changes: 7 additions & 0 deletions src/OptimisticTokenVotingPluginSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
/// @param length The array length of passed helpers.
error WrongHelpersArrayLength(uint256 length);

/// @notice Thrown when trying to prepare an installation with no proposers.
error NoProposers();

/// @notice The contract constructor deploying the plugin implementation contract and receiving the governance token base contracts to clone from.
/// @param _governanceERC20Base The base `GovernanceERC20` contract to create clones from.
/// @param _governanceWrappedERC20Base The base `GovernanceWrappedERC20` contract to create clones from.
Expand Down Expand Up @@ -89,6 +92,10 @@ contract OptimisticTokenVotingPluginSetup is PluginSetup {
address[] memory proposers
) = decodeInstallationParams(_installParameters);

if (proposers.length == 0) {
revert NoProposers();
}

address token = tokenSettings.addr;

// Prepare helpers.
Expand Down
102 changes: 19 additions & 83 deletions test/OptimisticTokenVotingPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import {IProposal} from "@aragon/osx/core/plugin/proposal/IProposal.sol";
import {IMembership} from "@aragon/osx/core/plugin/membership/IMembership.sol";
import {RATIO_BASE, RatioOutOfBounds} from "@aragon/osx/plugins/utils/Ratio.sol";
import {DaoUnauthorized} from "@aragon/osx/core/utils/auth.sol";
import {ERC20Mock} from "./mocks/ERC20Mock.sol";
import {ERC20VotesMock} from "./mocks/ERC20VotesMock.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {IERC165Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol";

contract OptimisticTokenVotingPluginTest is Test {
address immutable daoBase = address(new DAO());
address immutable pluginBase = address(new OptimisticTokenVotingPlugin());
address immutable votingTokenBase = address(new ERC20Mock());
address immutable votingTokenBase = address(new ERC20VotesMock());

DAO public dao;
OptimisticTokenVotingPlugin public plugin;
ERC20Mock votingToken;
ERC20VotesMock votingToken;

address alice = address(0xa11ce);
address bob = address(0xB0B);
Expand Down Expand Up @@ -51,8 +51,6 @@ contract OptimisticTokenVotingPluginTest is Test {
);
event Upgraded(address indexed implementation);

error Unimplemented();

function setUp() public {
vm.startPrank(alice);

Expand All @@ -73,10 +71,10 @@ contract OptimisticTokenVotingPluginTest is Test {
);

// Deploy ERC20 token
votingToken = ERC20Mock(
votingToken = ERC20VotesMock(
createProxyAndCall(
address(votingTokenBase),
abi.encodeWithSelector(ERC20Mock.initialize.selector)
abi.encodeWithSelector(ERC20VotesMock.initialize.selector)
)
);
votingToken.mint(alice, 10 ether);
Expand Down Expand Up @@ -199,10 +197,10 @@ contract OptimisticTokenVotingPluginTest is Test {
assertEq(plugin.minDuration(), 25 days, "Incorrect minDuration");

// A token with 10 eth supply
votingToken = ERC20Mock(
votingToken = ERC20VotesMock(
createProxyAndCall(
address(votingTokenBase),
abi.encodeWithSelector(ERC20Mock.initialize.selector)
abi.encodeWithSelector(ERC20VotesMock.initialize.selector)
)
);
votingToken.mint(alice, 10 ether);
Expand Down Expand Up @@ -331,10 +329,10 @@ contract OptimisticTokenVotingPluginTest is Test {
address oldToken = address(plugin.getVotingToken());

// New token
votingToken = ERC20Mock(
votingToken = ERC20VotesMock(
createProxyAndCall(
address(votingTokenBase),
abi.encodeWithSelector(ERC20Mock.initialize.selector)
abi.encodeWithSelector(ERC20VotesMock.initialize.selector)
)
);

Expand Down Expand Up @@ -384,10 +382,10 @@ contract OptimisticTokenVotingPluginTest is Test {
);

// New token
votingToken = ERC20Mock(
votingToken = ERC20VotesMock(
createProxyAndCall(
address(votingTokenBase),
abi.encodeWithSelector(ERC20Mock.initialize.selector)
abi.encodeWithSelector(ERC20VotesMock.initialize.selector)
)
);
votingToken.mint(alice, 15 ether);
Expand Down Expand Up @@ -496,10 +494,10 @@ contract OptimisticTokenVotingPluginTest is Test {
);

// New token
votingToken = ERC20Mock(
votingToken = ERC20VotesMock(
createProxyAndCall(
address(votingTokenBase),
abi.encodeWithSelector(ERC20Mock.initialize.selector)
abi.encodeWithSelector(ERC20VotesMock.initialize.selector)
)
);
votingToken.mint(alice, 10 ether);
Expand Down Expand Up @@ -543,10 +541,10 @@ contract OptimisticTokenVotingPluginTest is Test {
);

// New token
votingToken = ERC20Mock(
votingToken = ERC20VotesMock(
createProxyAndCall(
address(votingTokenBase),
abi.encodeWithSelector(ERC20Mock.initialize.selector)
abi.encodeWithSelector(ERC20VotesMock.initialize.selector)
)
);
votingToken.mint(alice, 10 ether);
Expand Down Expand Up @@ -659,10 +657,10 @@ contract OptimisticTokenVotingPluginTest is Test {
vm.startPrank(alice);

// Deploy ERC20 token (0 supply)
votingToken = ERC20Mock(
votingToken = ERC20VotesMock(
createProxyAndCall(
address(votingTokenBase),
abi.encodeWithSelector(ERC20Mock.initialize.selector)
abi.encodeWithSelector(ERC20VotesMock.initialize.selector)
)
);

Expand Down Expand Up @@ -1484,10 +1482,10 @@ contract OptimisticTokenVotingPluginTest is Test {
// Veto threshold reached
function test_IsMinVetoRatioReachedReturnsTheAppropriateValues() public {
// Deploy ERC20 token
votingToken = ERC20Mock(
votingToken = ERC20VotesMock(
createProxyAndCall(
address(votingTokenBase),
abi.encodeWithSelector(ERC20Mock.initialize.selector)
abi.encodeWithSelector(ERC20VotesMock.initialize.selector)
)
);
votingToken.mint(alice, 24 ether);
Expand Down Expand Up @@ -1954,68 +1952,6 @@ contract OptimisticTokenVotingPluginTest is Test {
plugin.updateOptimisticGovernanceSettings(newSettings);
}

function test_UpdateOptimisticGovernanceSettingsRevertsWhenMinProposerVotingPowerIsMoreThanTheTokenSupply()
public
{
dao.grant(
address(plugin),
alice,
plugin.UPDATE_OPTIMISTIC_GOVERNANCE_SETTINGS_PERMISSION_ID()
);

OptimisticTokenVotingPlugin.OptimisticGovernanceSettings
memory newSettings = OptimisticTokenVotingPlugin
.OptimisticGovernanceSettings({
minVetoRatio: uint32(RATIO_BASE / 10),
minDuration: 10 days,
minProposerVotingPower: 10 ether + 1
});
vm.expectRevert(
abi.encodeWithSelector(
OptimisticTokenVotingPlugin
.MinProposerVotingPowerOutOfBounds
.selector,
10 ether,
10 ether + 1
)
);
plugin.updateOptimisticGovernanceSettings(newSettings);

// 2
newSettings = OptimisticTokenVotingPlugin.OptimisticGovernanceSettings({
minVetoRatio: uint32(RATIO_BASE / 10),
minDuration: 10 days,
minProposerVotingPower: 50 ether
});
vm.expectRevert(
abi.encodeWithSelector(
OptimisticTokenVotingPlugin
.MinProposerVotingPowerOutOfBounds
.selector,
10 ether,
50 ether
)
);
plugin.updateOptimisticGovernanceSettings(newSettings);

// 3
newSettings = OptimisticTokenVotingPlugin.OptimisticGovernanceSettings({
minVetoRatio: uint32(RATIO_BASE / 10),
minDuration: 10 days,
minProposerVotingPower: 200 ether
});
vm.expectRevert(
abi.encodeWithSelector(
OptimisticTokenVotingPlugin
.MinProposerVotingPowerOutOfBounds
.selector,
10 ether,
200 ether
)
);
plugin.updateOptimisticGovernanceSettings(newSettings);
}

function test_UpdateOptimisticGovernanceSettingsEmitsAnEventWhenSuccessful()
public
{
Expand Down
Loading

0 comments on commit f25ea1d

Please sign in to comment.