Skip to content

Commit

Permalink
Enum case
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Jan 21, 2025
1 parent ccc6500 commit 3f017ba
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
26 changes: 13 additions & 13 deletions src/LockManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ contract LockManager is ILockManager, DaoAuthorizable {
IERC20 _underlyingToken
) DaoAuthorizable(_dao) {
if (
_settings.unlockMode != UnlockMode.STRICT &&
_settings.unlockMode != UnlockMode.EARLY
_settings.unlockMode != UnlockMode.Strict &&
_settings.unlockMode != UnlockMode.Early
) {
revert InvalidUnlockMode();
} else if (
_settings.pluginMode != PluginMode.APPROVAL &&
_settings.pluginMode != PluginMode.VOTING
_settings.pluginMode != PluginMode.Approval &&
_settings.pluginMode != PluginMode.Voting
) {
revert InvalidPluginMode();
}
Expand All @@ -103,7 +103,7 @@ contract LockManager is ILockManager, DaoAuthorizable {

/// @inheritdoc ILockManager
function lockAndApprove(uint256 _proposalId) public {
if (settings.pluginMode != PluginMode.APPROVAL) {
if (settings.pluginMode != PluginMode.Approval) {
revert InvalidPluginMode();
}

Expand All @@ -117,7 +117,7 @@ contract LockManager is ILockManager, DaoAuthorizable {
uint256 _proposalId,
IMajorityVoting.VoteOption _voteOption
) public {
if (settings.pluginMode != PluginMode.VOTING) {
if (settings.pluginMode != PluginMode.Voting) {
revert InvalidPluginMode();
}

Expand All @@ -128,7 +128,7 @@ contract LockManager is ILockManager, DaoAuthorizable {

/// @inheritdoc ILockManager
function approve(uint256 _proposalId) public {
if (settings.pluginMode != PluginMode.APPROVAL) {
if (settings.pluginMode != PluginMode.Approval) {
revert InvalidPluginMode();
}

Expand All @@ -140,7 +140,7 @@ contract LockManager is ILockManager, DaoAuthorizable {
uint256 _proposalId,
IMajorityVoting.VoteOption _voteOption
) public {
if (settings.pluginMode != PluginMode.VOTING) {
if (settings.pluginMode != PluginMode.Voting) {
revert InvalidPluginMode();
}

Expand All @@ -153,7 +153,7 @@ contract LockManager is ILockManager, DaoAuthorizable {
address _voter,
IMajorityVoting.VoteOption _voteOption
) external view returns (bool) {
if (settings.pluginMode == PluginMode.VOTING) {
if (settings.pluginMode == PluginMode.Voting) {
return
ILockToVote(address(plugin)).canVote(
_proposalId,
Expand All @@ -170,7 +170,7 @@ contract LockManager is ILockManager, DaoAuthorizable {
revert NoBalance();
}

if (settings.unlockMode == UnlockMode.STRICT) {
if (settings.unlockMode == UnlockMode.Strict) {
if (_hasActiveLocks()) revert LocksStillActive();
} else {
_withdrawActiveVotingPower();
Expand Down Expand Up @@ -238,14 +238,14 @@ contract LockManager is ILockManager, DaoAuthorizable {
}
// Is it the right plugin type?
else if (
settings.pluginMode == PluginMode.APPROVAL &&
settings.pluginMode == PluginMode.Approval &&
!IERC165(address(_newPluginAddress)).supportsInterface(
type(ILockToApprove).interfaceId
)
) {
revert InvalidPluginMode();
} else if (
settings.pluginMode == PluginMode.VOTING &&
settings.pluginMode == PluginMode.Voting &&
!IERC165(address(_newPluginAddress)).supportsInterface(
type(ILockToVote).interfaceId
)
Expand Down Expand Up @@ -352,7 +352,7 @@ contract LockManager is ILockManager, DaoAuthorizable {
}

if (plugin.usedVotingPower(knownProposalIds[_i], msg.sender) > 0) {
if (settings.pluginMode == PluginMode.VOTING) {
if (settings.pluginMode == PluginMode.Voting) {
ILockToVote(address(plugin)).clearVote(
knownProposalIds[_i],
msg.sender
Expand Down
2 changes: 1 addition & 1 deletion src/LockToApprovePlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ contract LockToApprovePlugin is

// Check if we may execute early
(UnlockMode unlockMode, ) = lockManager.settings();
if (unlockMode == UnlockMode.STRICT) {
if (unlockMode == UnlockMode.Strict) {
if (
_canExecute(proposal_) &&
dao().hasPermission(address(this), _msgSender(), EXECUTE_PROPOSAL_PERMISSION_ID, _msgData())
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/ILockManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/// @notice Defines whether locked funds can be unlocked at any time or not
enum UnlockMode {
STRICT,
EARLY
Strict,
Early
}

/// @notice Defines wether the voting plugin expects approvals or votes
enum PluginMode {
APPROVAL,
VOTING
Approval,
Voting
}

/// @notice The struct containing the LockManager helper settings. They are immutable after deployed.
Expand Down
34 changes: 17 additions & 17 deletions test/LockManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract LockManagerTest is AragonTest {
address immutable LOCK_TO_VOTE_BASE = address(new LockToApprovePlugin());
address immutable LOCK_MANAGER_BASE = address(
new LockManager(
IDAO(address(0)), LockManagerSettings(UnlockMode.STRICT), IERC20(address(0)), IERC20(address(0))
IDAO(address(0)), LockManagerSettings(UnlockMode.Strict), IERC20(address(0)), IERC20(address(0))
)
);

Expand All @@ -45,7 +45,7 @@ contract LockManagerTest is AragonTest {
builder = new DaoBuilder();
(dao, plugin, lockManager, lockableToken, underlyingToken) = builder.withTokenHolder(alice, 1 ether)
.withTokenHolder(bob, 10 ether).withTokenHolder(carol, 10 ether).withTokenHolder(david, 15 ether).withUnlockMode(
UnlockMode.STRICT
UnlockMode.Strict
).build();
}

Expand All @@ -67,9 +67,9 @@ contract LockManagerTest is AragonTest {

// OK
new LockManager(
IDAO(address(0)), LockManagerSettings(UnlockMode.STRICT), IERC20(address(0)), IERC20(address(0))
IDAO(address(0)), LockManagerSettings(UnlockMode.Strict), IERC20(address(0)), IERC20(address(0))
);
new LockManager(IDAO(address(0)), LockManagerSettings(UnlockMode.EARLY), IERC20(address(0)), IERC20(address(0)));
new LockManager(IDAO(address(0)), LockManagerSettings(UnlockMode.Early), IERC20(address(0)), IERC20(address(0)));
}

function test_WhenConstructorWithValidParams() external givenDeployingTheContract {
Expand All @@ -79,15 +79,15 @@ contract LockManagerTest is AragonTest {

// 1
lockManager = new LockManager(
IDAO(address(1234)), LockManagerSettings(UnlockMode.STRICT), IERC20(address(2345)), IERC20(address(3456))
IDAO(address(1234)), LockManagerSettings(UnlockMode.Strict), IERC20(address(2345)), IERC20(address(3456))
);
assertEq(address(lockManager.dao()), address(1234));
assertEq(address(lockManager.token()), address(2345));
assertEq(address(lockManager.underlyingToken()), address(3456));

// 2
lockManager = new LockManager(
IDAO(address(5555)), LockManagerSettings(UnlockMode.EARLY), IERC20(address(6666)), IERC20(address(7777))
IDAO(address(5555)), LockManagerSettings(UnlockMode.Early), IERC20(address(6666)), IERC20(address(7777))
);
assertEq(address(lockManager.dao()), address(5555));
assertEq(address(lockManager.token()), address(6666));
Expand All @@ -101,7 +101,7 @@ contract LockManagerTest is AragonTest {
function test_RevertGiven_InvalidPlugin() external whenCallingSetPluginAddress {
// It should revert

lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.STRICT), lockableToken, underlyingToken);
lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.Strict), lockableToken, underlyingToken);
dao.grant(address(lockManager), alice, lockManager.UPDATE_SETTINGS_PERMISSION_ID());
vm.expectRevert();
lockManager.setPluginAddress(LockToApprovePlugin(address(0x5555)));
Expand All @@ -113,7 +113,7 @@ contract LockManagerTest is AragonTest {
(, LockToApprovePlugin plugin2,,,) = builder.build();
(, LockToApprovePlugin plugin3,,,) = builder.build();

lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.STRICT), lockableToken, underlyingToken);
lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.Strict), lockableToken, underlyingToken);

// 1
vm.expectRevert();
Expand All @@ -130,7 +130,7 @@ contract LockManagerTest is AragonTest {

// OK 2

lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.STRICT), lockableToken, underlyingToken);
lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.Strict), lockableToken, underlyingToken);
dao.grant(address(lockManager), alice, lockManager.UPDATE_SETTINGS_PERMISSION_ID());
lockManager.setPluginAddress(plugin3);
}
Expand All @@ -142,14 +142,14 @@ contract LockManagerTest is AragonTest {
(, LockToApprovePlugin plugin2,,,) = builder.build();
(, LockToApprovePlugin plugin3,,,) = builder.build();

lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.STRICT), lockableToken, underlyingToken);
lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.Strict), lockableToken, underlyingToken);
dao.grant(address(lockManager), alice, lockManager.UPDATE_SETTINGS_PERMISSION_ID());
lockManager.setPluginAddress(plugin2);
assertEq(address(lockManager.plugin()), address(plugin2));

// OK 2

lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.STRICT), lockableToken, underlyingToken);
lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.Strict), lockableToken, underlyingToken);
dao.grant(address(lockManager), alice, lockManager.UPDATE_SETTINGS_PERMISSION_ID());
lockManager.setPluginAddress(plugin3);
assertEq(address(lockManager.plugin()), address(plugin3));
Expand Down Expand Up @@ -519,7 +519,7 @@ contract LockManagerTest is AragonTest {
function test_GivenEmptyPlugin() external givenCallingLockOrLockToVote {
// It Locking and voting should revert

lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.STRICT), lockableToken, underlyingToken);
lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.Strict), lockableToken, underlyingToken);

vm.expectRevert();
lockManager.lockAndVote(proposalId);
Expand All @@ -534,7 +534,7 @@ contract LockManagerTest is AragonTest {
// It Voting should revert

lockManager =
new LockManager(dao, LockManagerSettings(UnlockMode.STRICT), IERC20(address(0x1234)), underlyingToken);
new LockManager(dao, LockManagerSettings(UnlockMode.Strict), IERC20(address(0x1234)), underlyingToken);
lockableToken.approve(address(lockManager), 0.1 ether);
vm.expectRevert();
lockManager.lock();
Expand Down Expand Up @@ -685,7 +685,7 @@ contract LockManagerTest is AragonTest {
// It Should revert

UnlockMode mode = lockManager.settings();
assertEq(uint8(mode), uint8(UnlockMode.STRICT));
assertEq(uint8(mode), uint8(UnlockMode.Strict));

// vm.startPrank(alice);
vm.expectRevert(NoBalance.selector);
Expand Down Expand Up @@ -762,7 +762,7 @@ contract LockManagerTest is AragonTest {
modifier givenFlexibleModeIsSet() {
(dao, plugin, lockManager, lockableToken, underlyingToken) = builder.withTokenHolder(alice, 1 ether)
.withTokenHolder(bob, 10 ether).withTokenHolder(carol, 10 ether).withTokenHolder(david, 15 ether).withUnlockMode(
UnlockMode.EARLY
UnlockMode.Early
).build();

Action[] memory _actions = new Action[](0);
Expand All @@ -779,7 +779,7 @@ contract LockManagerTest is AragonTest {
// It Should revert

UnlockMode mode = lockManager.settings();
assertEq(uint8(mode), uint8(UnlockMode.EARLY));
assertEq(uint8(mode), uint8(UnlockMode.Early));

// vm.startPrank(alice);
vm.expectRevert(NoBalance.selector);
Expand Down Expand Up @@ -883,7 +883,7 @@ contract LockManagerTest is AragonTest {

lockManager = new LockManager(
dao,
LockManagerSettings(UnlockMode.STRICT),
LockManagerSettings(UnlockMode.Strict),
lockableToken,
IERC20(address(0)) // underlying
);
Expand Down
2 changes: 1 addition & 1 deletion test/util/DaoBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract DaoBuilder is Test {
bool onlyListed = true;
uint32 minApprovalRatio = 100_000; // 10%
uint32 proposalDuration = 10 days;
UnlockMode unlockMode = UnlockMode.STRICT;
UnlockMode unlockMode = UnlockMode.Strict;

function withDaoOwner(address newOwner) public returns (DaoBuilder) {
owner = newOwner;
Expand Down

0 comments on commit 3f017ba

Please sign in to comment.