-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1aded7e
commit 158201f
Showing
9 changed files
with
420 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/contracts/src/test/plugin/Cloneable/PluginCloneableMock.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
/* solhint-disable one-contract-per-file */ | ||
pragma solidity ^0.8.8; | ||
|
||
// TODO move back to OSX | ||
|
||
import {PluginCloneable} from "@aragon/osx-commons-contracts/src/plugin/PluginCloneable.sol"; | ||
import {IDAO} from "@aragon/osx-commons-contracts/src/dao/IDAO.sol"; | ||
|
||
contract PluginCloneableV1Mock is PluginCloneable { | ||
uint256 public state1; | ||
|
||
function initialize(IDAO _dao) external initializer { | ||
__PluginCloneable_init(_dao); | ||
state1 = 1; | ||
} | ||
} | ||
|
||
// Doesn't support IPlugin Interface. // TODO revisit tests | ||
contract PluginCloneableV1MockBad { | ||
uint256 public state1; | ||
|
||
function initialize(IDAO _dao) external { | ||
(_dao); | ||
state1 = 1; | ||
} | ||
} | ||
|
||
contract PluginCloneableV2Mock is PluginCloneable { | ||
uint256 public state1; | ||
uint256 public state2; | ||
|
||
function initialize(IDAO _dao) external initializer { | ||
__PluginCloneable_init(_dao); | ||
state1 = 1; | ||
state2 = 2; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
packages/contracts/src/test/plugin/Cloneable/PluginCloneableSetupMock.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
/* solhint-disable one-contract-per-file */ | ||
pragma solidity ^0.8.8; | ||
|
||
import {PermissionLib} from "@aragon/osx-commons-contracts/src/permission/PermissionLib.sol"; | ||
import {IPluginSetup} from "@aragon/osx-commons-contracts/src/plugin/setup/IPluginSetup.sol"; | ||
import {PluginSetup} from "@aragon/osx-commons-contracts/src/plugin/setup/PluginSetup.sol"; | ||
|
||
import {mockPermissions, mockHelpers, mockPluginProxy} from "../PluginMockData.sol"; | ||
import {PluginCloneableV1Mock, PluginCloneableV1MockBad, PluginCloneableV2Mock} from "./PluginCloneableMock.sol"; | ||
|
||
contract PluginCloneableSetupV1Mock is PluginSetup { | ||
address internal pluginBase; | ||
|
||
constructor() { | ||
pluginBase = address(new PluginCloneableV1Mock()); | ||
} | ||
|
||
/// @inheritdoc IPluginSetup | ||
function prepareInstallation( | ||
address _dao, | ||
bytes memory | ||
) public virtual override returns (address plugin, PreparedSetupData memory preparedSetupData) { | ||
plugin = mockPluginProxy(pluginBase, _dao); | ||
preparedSetupData.helpers = mockHelpers(1); | ||
preparedSetupData.permissions = mockPermissions(5, 6, PermissionLib.Operation.Grant); | ||
} | ||
|
||
/// @inheritdoc IPluginSetup | ||
function prepareUninstallation( | ||
address _dao, | ||
SetupPayload calldata _payload | ||
) external virtual override returns (PermissionLib.MultiTargetPermission[] memory permissions) { | ||
(_dao, _payload); | ||
permissions = mockPermissions(5, 6, PermissionLib.Operation.Revoke); | ||
} | ||
|
||
/// @inheritdoc IPluginSetup | ||
function implementation() external view virtual override returns (address) { | ||
return address(pluginBase); | ||
} | ||
} | ||
|
||
contract PluginCloneableSetupV1MockBad is PluginCloneableSetupV1Mock { | ||
constructor() { | ||
pluginBase = address(new PluginCloneableV1MockBad()); | ||
} | ||
} | ||
|
||
contract PluginCloneableSetupV2Mock is PluginCloneableSetupV1Mock { | ||
constructor() { | ||
pluginBase = address(new PluginCloneableV2Mock()); | ||
} | ||
|
||
/// @inheritdoc IPluginSetup | ||
function prepareInstallation( | ||
address _dao, | ||
bytes memory | ||
) public virtual override returns (address plugin, PreparedSetupData memory preparedSetupData) { | ||
plugin = mockPluginProxy(pluginBase, _dao); | ||
preparedSetupData.helpers = mockHelpers(1); | ||
preparedSetupData.permissions = mockPermissions(5, 7, PermissionLib.Operation.Grant); | ||
} | ||
|
||
/// @inheritdoc IPluginSetup | ||
function prepareUninstallation( | ||
address _dao, | ||
SetupPayload calldata _payload | ||
) external virtual override returns (PermissionLib.MultiTargetPermission[] memory permissions) { | ||
(_dao, _payload); | ||
permissions = mockPermissions(5, 7, PermissionLib.Operation.Revoke); | ||
} | ||
|
||
/// @inheritdoc IPluginSetup | ||
function implementation() external view virtual override returns (address) { | ||
return address(pluginBase); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/contracts/src/test/plugin/Constructable/PluginMock.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
pragma solidity ^0.8.8; | ||
|
||
import {Plugin} from "@aragon/osx-commons-contracts/src/plugin/Plugin.sol"; | ||
import {IDAO} from "@aragon/osx-commons-contracts/src/dao/IDAO.sol"; | ||
|
||
contract PluginV1Mock is Plugin { | ||
uint256 public state1; | ||
|
||
constructor(IDAO _dao) Plugin(_dao) { | ||
state1 = 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
pragma solidity ^0.8.8; | ||
|
||
import {PermissionLib} from "@aragon/osx-commons-contracts/src/permission/PermissionLib.sol"; | ||
import {createERC1967Proxy} from "@aragon/osx-commons-contracts/src/utils/deployment/Proxy.sol"; | ||
|
||
address constant NO_CONDITION = address(0); | ||
|
||
error ConflictingValues(); | ||
|
||
function mockPermissions( | ||
uint160 start, | ||
uint160 end, | ||
PermissionLib.Operation op | ||
) pure returns (PermissionLib.MultiTargetPermission[] memory permissions) { | ||
if (start > end) revert ConflictingValues(); | ||
|
||
permissions = new PermissionLib.MultiTargetPermission[](end - start); | ||
|
||
for (uint160 i = start; i < end; i++) { | ||
permissions[i - start] = PermissionLib.MultiTargetPermission({ | ||
operation: op, | ||
where: address(i), | ||
who: address(i), | ||
condition: PermissionLib.NO_CONDITION, | ||
permissionId: keccak256("MOCK_PERMISSION") | ||
}); | ||
} | ||
} | ||
|
||
function mockHelpers(uint160 amount) pure returns (address[] memory helpers) { | ||
helpers = new address[](amount); | ||
|
||
for (uint160 i = 0; i < amount; i++) { | ||
helpers[i] = address(i); | ||
} | ||
} | ||
|
||
function mockPluginProxy(address _pluginBase, address _dao) returns (address) { | ||
return | ||
createERC1967Proxy( | ||
_pluginBase, | ||
abi.encodeWithSelector(bytes4(keccak256("initialize(address)")), _dao) | ||
); | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/contracts/src/test/plugin/UUPSUpgradeable/PluginUUPSUpgradeableMock.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
/* solhint-disable one-contract-per-file */ | ||
pragma solidity ^0.8.8; | ||
|
||
import {PluginUUPSUpgradeable} from "@aragon/osx-commons-contracts/src/plugin/PluginUUPSUpgradeable.sol"; | ||
import {IDAO} from "@aragon/osx-commons-contracts/src/dao/IDAO.sol"; | ||
|
||
contract PluginUUPSUpgradeableV1Mock is PluginUUPSUpgradeable { | ||
uint256 public state1; | ||
|
||
function initialize(IDAO _dao) external initializer { | ||
__PluginUUPSUpgradeable_init(_dao); | ||
state1 = 1; | ||
} | ||
} | ||
|
||
contract PluginUUPSUpgradeableV2Mock is PluginUUPSUpgradeable { | ||
uint256 public state1; | ||
uint256 public state2; | ||
|
||
function initialize(IDAO _dao) external reinitializer(2) { | ||
__PluginUUPSUpgradeable_init(_dao); | ||
state1 = 1; | ||
state2 = 2; | ||
} | ||
|
||
function initializeV1toV2() external reinitializer(2) { | ||
state2 = 2; | ||
} | ||
} | ||
|
||
contract PluginUUPSUpgradeableV3Mock is PluginUUPSUpgradeable { | ||
uint256 public state1; | ||
uint256 public state2; | ||
uint256 public state3; | ||
|
||
function initialize(IDAO _dao) external reinitializer(3) { | ||
__PluginUUPSUpgradeable_init(_dao); | ||
state1 = 1; | ||
state2 = 2; | ||
state3 = 3; | ||
} | ||
|
||
function initializeV1toV3() external reinitializer(3) { | ||
state2 = 2; | ||
state3 = 3; | ||
} | ||
|
||
function initializeV2toV3() external reinitializer(3) { | ||
state3 = 3; | ||
} | ||
} |
Oops, something went wrong.