Skip to content

Commit 62c9bd1

Browse files
committed
Importing existing mock contracts for testing
1 parent 4ce6b8b commit 62c9bd1

File tree

5 files changed

+275
-0
lines changed

5 files changed

+275
-0
lines changed

test/mocks/CustomExecutorMock.sol

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
3+
pragma solidity ^0.8.8;
4+
5+
import {Action} from "@aragon/osx-commons-contracts/src/executors/IExecutor.sol";
6+
7+
/// @dev DO NOT USE IN PRODUCTION!
8+
contract CustomExecutorMock {
9+
error FailedCustom();
10+
11+
event ExecutedCustom();
12+
13+
function execute(bytes32 callId, Action[] memory, uint256)
14+
external
15+
returns (bytes[] memory execResults, uint256 failureMap)
16+
{
17+
(execResults, failureMap);
18+
19+
if (callId == bytes32(0)) {
20+
revert FailedCustom();
21+
} else {
22+
emit ExecutedCustom();
23+
}
24+
}
25+
}

test/mocks/DAOMock.sol

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
3+
pragma solidity ^0.8.8;
4+
5+
import {IDAO} from "@aragon/osx-commons-contracts/src/dao/IDAO.sol";
6+
import {IPermissionCondition} from "@aragon/osx-commons-contracts/src/permission/condition/IPermissionCondition.sol";
7+
import {PermissionLib} from "@aragon/osx-commons-contracts/src/permission/PermissionLib.sol";
8+
import {IExecutor, Action} from "@aragon/osx-commons-contracts/src/executors/IExecutor.sol";
9+
10+
contract DAOMock is IDAO, IExecutor {
11+
address internal constant NO_CONDITION = address(0);
12+
13+
event Granted(
14+
bytes32 indexed permissionId, address indexed here, address where, address indexed who, address condition
15+
);
16+
17+
event Revoked(bytes32 indexed permissionId, address indexed here, address where, address indexed who);
18+
19+
bool public hasPermissionReturnValueMock;
20+
21+
function setHasPermissionReturnValueMock(bool _hasPermissionReturnValueMock) external {
22+
hasPermissionReturnValueMock = _hasPermissionReturnValueMock;
23+
}
24+
25+
function hasPermission(address _where, address _who, bytes32 _permissionId, bytes memory _data)
26+
external
27+
view
28+
override
29+
returns (bool)
30+
{
31+
(_where, _who, _permissionId, _data);
32+
return hasPermissionReturnValueMock;
33+
}
34+
35+
function applyMultiTargetPermissions(PermissionLib.MultiTargetPermission[] calldata _items) external {
36+
for (uint256 i; i < _items.length;) {
37+
PermissionLib.MultiTargetPermission memory item = _items[i];
38+
39+
if (item.operation == PermissionLib.Operation.Grant) {
40+
grant({_where: item.where, _who: item.who, _permissionId: item.permissionId});
41+
} else if (item.operation == PermissionLib.Operation.Revoke) {
42+
revoke({_where: item.where, _who: item.who, _permissionId: item.permissionId});
43+
} else if (item.operation == PermissionLib.Operation.GrantWithCondition) {
44+
grantWithCondition({
45+
_where: item.where,
46+
_who: item.who,
47+
_permissionId: item.permissionId,
48+
_condition: IPermissionCondition(item.condition)
49+
});
50+
}
51+
52+
unchecked {
53+
++i;
54+
}
55+
}
56+
}
57+
58+
function grant(address _where, address _who, bytes32 _permissionId) public {
59+
(_where, _who, _permissionId);
60+
61+
emit Granted({permissionId: _permissionId, here: msg.sender, where: _where, who: _who, condition: NO_CONDITION});
62+
}
63+
64+
function revoke(address _where, address _who, bytes32 _permissionId) public {
65+
(_where, _who, _permissionId);
66+
67+
emit Revoked({permissionId: _permissionId, here: msg.sender, where: _where, who: _who});
68+
}
69+
70+
function grantWithCondition(address _where, address _who, bytes32 _permissionId, IPermissionCondition _condition)
71+
public
72+
{
73+
emit Granted({
74+
permissionId: _permissionId,
75+
here: msg.sender,
76+
where: _where,
77+
who: _who,
78+
condition: address(_condition)
79+
});
80+
}
81+
82+
function getTrustedForwarder() public pure override returns (address) {
83+
return address(0);
84+
}
85+
86+
function setTrustedForwarder(address _trustedForwarder) external pure override {
87+
(_trustedForwarder);
88+
}
89+
90+
function setMetadata(bytes calldata _metadata) external pure override {
91+
(_metadata);
92+
}
93+
94+
function execute(bytes32 callId, Action[] memory _actions, uint256 allowFailureMap)
95+
external
96+
override
97+
returns (bytes[] memory execResults, uint256 failureMap)
98+
{
99+
emit Executed(msg.sender, callId, _actions, allowFailureMap, failureMap, execResults);
100+
}
101+
102+
function deposit(address _token, uint256 _amount, string calldata _reference) external payable override {
103+
(_token, _amount, _reference);
104+
}
105+
106+
function setSignatureValidator(address _signatureValidator) external pure override {
107+
(_signatureValidator);
108+
}
109+
110+
function isValidSignature(bytes32 _hash, bytes memory _signature) external pure override returns (bytes4) {
111+
(_hash, _signature);
112+
return 0x0;
113+
}
114+
115+
function registerStandardCallback(bytes4 _interfaceId, bytes4 _callbackSelector, bytes4 _magicNumber)
116+
external
117+
pure
118+
override
119+
{
120+
(_interfaceId, _callbackSelector, _magicNumber);
121+
}
122+
}

test/mocks/ERC20Mock.sol

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
3+
pragma solidity ^0.8.8;
4+
5+
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
6+
7+
/// @notice A mock [ERC-20](https://eips.ethereum.org/EIPS/eip-20) token that can be minted and burned by everyone.
8+
/// @dev DO NOT USE IN PRODUCTION!
9+
contract ERC20Mock is ERC20 {
10+
uint8 public decimals_ = 18;
11+
12+
constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {}
13+
14+
function setDecimals(uint8 _decimals) public {
15+
decimals_ = _decimals;
16+
}
17+
18+
function decimals() public view override returns (uint8) {
19+
return decimals_;
20+
}
21+
22+
// sets the balance of the address
23+
// this mints/burns the amount depending on the current balance
24+
function setBalance(address to, uint256 amount) public {
25+
uint256 old = balanceOf(to);
26+
if (old < amount) {
27+
_mint(to, amount - old);
28+
} else if (old > amount) {
29+
_burn(to, old - amount);
30+
}
31+
}
32+
}

test/mocks/MajorityVotingMock.sol

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
3+
pragma solidity ^0.8.8;
4+
5+
import {Action} from "@aragon/osx-commons-contracts/src/executors/IExecutor.sol";
6+
7+
import {MajorityVotingBase, IDAO} from "../../src/base/MajorityVotingBase.sol";
8+
9+
contract MajorityVotingMock is MajorityVotingBase {
10+
function initializeMock(
11+
IDAO _dao,
12+
VotingSettings calldata _votingSettings,
13+
TargetConfig calldata _targetConfig,
14+
uint256 _minApprovals,
15+
bytes calldata _metadata
16+
) public initializer {
17+
__MajorityVotingBase_init(_dao, _votingSettings, _targetConfig, _minApprovals, _metadata);
18+
}
19+
20+
function createProposal(
21+
bytes calldata, /* _metadata */
22+
Action[] calldata, /* _actions */
23+
uint256, /* _allowFailureMap */
24+
uint64, /* _startDate */
25+
uint64, /* _endDate */
26+
VoteOption, /* _voteOption */
27+
bool /* _tryEarlyExecution */
28+
) public pure override returns (uint256 proposalId) {
29+
return 0;
30+
}
31+
32+
function createProposal(
33+
bytes calldata _metadata,
34+
Action[] calldata _actions,
35+
uint64 _startDate,
36+
uint64 _endDate,
37+
bytes memory
38+
) external pure override returns (uint256 proposalId) {
39+
// Calls public function for permission check.
40+
proposalId = createProposal(_metadata, _actions, 0, _startDate, _endDate, VoteOption.None, false);
41+
}
42+
43+
function customProposalParamsABI() external pure override returns (string memory) {
44+
return "[uint256 allowFailureMap, uint8 voteOption, bool tryEarlyExecution]";
45+
}
46+
47+
function totalVotingPower(uint256 /* _blockNumber */ ) public pure override returns (uint256) {
48+
return 0;
49+
}
50+
51+
/* solhint-disable no-empty-blocks */
52+
function _vote(
53+
uint256, /* _proposalId */
54+
VoteOption, /* _voteOption */
55+
address, /* _voter */
56+
bool /* _tryEarlyExecution */
57+
) internal pure override {}
58+
59+
function _canVote(
60+
uint256,
61+
/* _proposalId */
62+
address,
63+
/* _voter */
64+
VoteOption /* _voteOption */
65+
) internal pure override returns (bool) {
66+
return true;
67+
}
68+
}

test/mocks/TestGovernanceERC20.sol

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: AGPL-3.0-or-later
2+
3+
pragma solidity ^0.8.8;
4+
5+
import {IDAO} from "@aragon/osx-commons-contracts/src/dao/IDAO.sol";
6+
7+
import {GovernanceERC20} from "../../src/erc20/GovernanceERC20.sol";
8+
9+
/// @title TestGovernanceERC20
10+
/// @author Aragon X - 2022-2023
11+
/// @notice A test GovernanceERC20 that can be minted and burned by everyone.
12+
/// @dev DO NOT USE IN PRODUCTION!
13+
contract TestGovernanceERC20 is GovernanceERC20 {
14+
constructor(IDAO _dao, string memory _name, string memory _symbol, MintSettings memory _mintSettings)
15+
GovernanceERC20(_dao, _name, _symbol, _mintSettings)
16+
{}
17+
18+
// sets the balance of the address
19+
// this mints/burns the amount depending on the current balance
20+
function setBalance(address to, uint256 amount) public {
21+
uint256 old = balanceOf(to);
22+
if (old < amount) {
23+
_mint(to, amount - old);
24+
} else if (old > amount) {
25+
_burn(to, old - amount);
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)