Skip to content

Commit

Permalink
Testing primitives ready
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Dec 19, 2024
1 parent 60e2ceb commit 8637272
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 26 deletions.
8 changes: 8 additions & 0 deletions src/LockManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/interfaces/ILockManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
93 changes: 78 additions & 15 deletions test/LockManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ contract LockManagerTest is AragonTest {
)
);

error InvalidUnlockMode();

function setUp() public {
vm.startPrank(alice);
vm.warp(1 days);
Expand All @@ -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 {
Expand Down
13 changes: 5 additions & 8 deletions test/LockManager.t.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions test/util/DaoBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8637272

Please sign in to comment.