diff --git a/src/LockManager.sol b/src/LockManager.sol index a5673e1..d599461 100644 --- a/src/LockManager.sol +++ b/src/LockManager.sol @@ -52,6 +52,12 @@ contract LockManager is ILockManager, DaoAuthorizable { /// @notice Raised when attempting to unlock while active votes are cast in strict mode error LocksStillActive(); + /// @notice Thrown when trying to set an invalid contract as the plugin + error InvalidPlugin(); + + /// @notice Thrown when trying to define the address of the plugin after it already was + error CannotUpdatePlugin(); + constructor(IDAO _dao, LockManagerSettings memory _settings, IERC20 _token, IERC20 _underlyingToken) DaoAuthorizable(_dao) { @@ -134,6 +140,8 @@ contract LockManager is ILockManager, DaoAuthorizable { function setPluginAddress(ILockToVote _plugin) public auth(UPDATE_SETTINGS_PERMISSION_ID) { if (!IERC165(address(_plugin)).supportsInterface(type(ILockToVote).interfaceId)) { revert InvalidPlugin(); + } else if (address(plugin) != address(0)) { + revert CannotUpdatePlugin(); } plugin = _plugin; diff --git a/src/interfaces/ILockManager.sol b/src/interfaces/ILockManager.sol index fa8cf99..a790500 100644 --- a/src/interfaces/ILockManager.sol +++ b/src/interfaces/ILockManager.sol @@ -67,7 +67,4 @@ interface ILockManager { /// @notice Defines the given plugin address as the target for voting function setPluginAddress(ILockToVote _plugin) external; - - /// @notice Thrown then trying to set an invalid contract as the plugin - error InvalidPlugin(); } diff --git a/test/LockManager.t.sol b/test/LockManager.t.sol index 65f9960..421dec1 100644 --- a/test/LockManager.t.sol +++ b/test/LockManager.t.sol @@ -27,6 +27,8 @@ contract LockManagerTest is AragonTest { ) ); + error InvalidUnlockMode(); + function setUp() public { vm.startPrank(alice); vm.warp(1 days); @@ -43,33 +45,94 @@ contract LockManagerTest is AragonTest { function test_RevertWhen_ConstructorHasInvalidUnlockMode() external givenDeployingTheContract { // It Should revert - vm.skip(true); + vm.expectRevert(); + new LockManager( + IDAO(address(0)), LockManagerSettings(UnlockMode(uint8(2))), IERC20(address(0)), IERC20(address(0)) + ); + + vm.expectRevert(); + new LockManager( + IDAO(address(0)), LockManagerSettings(UnlockMode(uint8(0))), IERC20(address(0)), IERC20(address(0)) + ); + + // OK + new LockManager( + 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))); } function test_WhenConstructorWithValidParams() external givenDeployingTheContract { // It Registers the DAO address // It Stores the given settings - // It Stores the given plugin and token addresses - vm.skip(true); - } - - modifier whenCallingUpdateSettings() { + // It Stores the given token addresses + + // 1 + lockManager = new LockManager( + 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)) + ); + assertEq(address(lockManager.dao()), address(5555)); + assertEq(address(lockManager.token()), address(6666)); + assertEq(address(lockManager.underlyingToken()), address(7777)); + } + + modifier whenCallingSetPluginAddress() { _; } - function test_RevertWhen_UpdateSettingsWithoutThePermission() external whenCallingUpdateSettings { + function test_RevertWhen_SetPluginAddressWithoutThePermission() external whenCallingSetPluginAddress { // It should revert - vm.skip(true); - } - function test_WhenUpdateSettingsWithThePermission() external whenCallingUpdateSettings { - // It should update the mode - vm.skip(true); + (, LockToVotePlugin plugin2,,,) = builder.build(); + (, LockToVotePlugin plugin3,,,) = builder.build(); + + lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.STRICT), lockableToken, underlyingToken); + + // 1 + vm.expectRevert(); + lockManager.setPluginAddress(plugin2); + + // 2 + vm.expectRevert(); + lockManager.setPluginAddress(plugin3); + + // OK + + dao.grant(address(lockManager), alice, lockManager.UPDATE_SETTINGS_PERMISSION_ID()); + lockManager.setPluginAddress(plugin2); + + // OK 2 + + lockManager = new LockManager(dao, LockManagerSettings(UnlockMode.STRICT), lockableToken, underlyingToken); + dao.grant(address(lockManager), alice, lockManager.UPDATE_SETTINGS_PERMISSION_ID()); + lockManager.setPluginAddress(plugin3); } - function test_WhenCallingGetSettings() external whenCallingUpdateSettings { - // It Should return the right value - vm.skip(true); + function test_WhenSetPluginAddressWithThePermission() external whenCallingSetPluginAddress { + // It should update the address + + (, LockToVotePlugin plugin2,,,) = builder.build(); + (, LockToVotePlugin plugin3,,,) = builder.build(); + + 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); + dao.grant(address(lockManager), alice, lockManager.UPDATE_SETTINGS_PERMISSION_ID()); + lockManager.setPluginAddress(plugin3); + assertEq(address(lockManager.plugin()), address(plugin3)); } function test_WhenCallingSupportsInterface() external { diff --git a/test/LockManager.t.yaml b/test/LockManager.t.yaml index 0aaaea7..294b00b 100644 --- a/test/LockManager.t.yaml +++ b/test/LockManager.t.yaml @@ -8,19 +8,16 @@ LockManagerTest: then: - it: Registers the DAO address - it: Stores the given settings - - it: Stores the given plugin and token addresses + - it: Stores the given token addresses - - when: calling updateSettings + - when: calling setPluginAddress and: - - when: updateSettings without the permission + - when: setPluginAddress without the permission then: - it: should revert - - when: updateSettings with the permission + - when: setPluginAddress with the permission then: - - it: should update the mode - - when: Calling getSettings - then: - - it: Should return the right value + - it: should update the address - when: calling supportsInterface then: diff --git a/test/util/DaoBuilder.sol b/test/util/DaoBuilder.sol index 298a415..0c7c327 100644 --- a/test/util/DaoBuilder.sol +++ b/test/util/DaoBuilder.sol @@ -107,6 +107,10 @@ contract DaoBuilder is Test { ) ) ); + + dao.grant(address(helper), address(this), helper.UPDATE_SETTINGS_PERMISSION_ID()); + helper.setPluginAddress(plugin); + dao.revoke(address(helper), address(this), helper.UPDATE_SETTINGS_PERMISSION_ID()); } // The plugin can execute on the DAO