Skip to content

Commit 643675a

Browse files
committed
initial tests pass
1 parent 274c331 commit 643675a

File tree

2 files changed

+136
-21
lines changed

2 files changed

+136
-21
lines changed

dependecies/immutable/test/allowlist/OperatorAllowlist.sol

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright Immutable Pty Ltd 2018 - 2023
22
// SPDX-License-Identifier: Apache 2.0
3-
pragma solidity 0.8.19;
3+
pragma solidity ^0.8.24;
44

55
// Access Control
66

7-
import {Role} from "../../../Role.sol";
7+
import {Role} from "../../../../src/Role.sol";
88
import {OwnableRoles} from "@solady/auth/OwnableRoles.sol";
99

1010
// Interfaces
@@ -19,7 +19,7 @@ interface IProxy {
1919

2020
}
2121

22-
interface IERC165 {
22+
interface ERC165 {
2323

2424
function supportsInterface(bytes4 interfaceId) external view returns (bool);
2525

@@ -32,7 +32,7 @@ interface IERC165 {
3232
OperatorAllowlist is not designed to be upgradeable or extended.
3333
*/
3434

35-
contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
35+
contract OperatorAllowlist is ERC165, OwnableRoles, IOperatorAllowlist {
3636

3737
/// @notice Mapping of Allowlisted addresses
3838
mapping(address aContract => bool allowed) private addressAllowlist;
@@ -54,11 +54,11 @@ contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
5454
/// ===== Constructor =====
5555

5656
/**
57-
* @notice Grants `_MANAGER_ROLE` to the supplied `admin` address
58-
* @param admin the address to grant `_MANAGER_ROLE` to
57+
* @notice Grants `Role._MANAGER_ROLE` to the supplied `admin` address
58+
* @param admin the address to grant `Role._MANAGER_ROLE` to
5959
*/
6060
constructor(address admin) {
61-
_grantRoles(admin, _MANAGER_ROLE);
61+
_grantRoles(admin, Role._MANAGER_ROLE);
6262
}
6363

6464
/// ===== External functions =====
@@ -67,7 +67,7 @@ contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
6767
* @notice Add a target address to Allowlist
6868
* @param addressTargets the addresses to be added to the allowlist
6969
*/
70-
function addAddressToAllowlist(address[] calldata addressTargets) external onlyRoles(_REGISTRAR_ROLE) {
70+
function addAddressToAllowlist(address[] calldata addressTargets) external onlyRoles(Role._REGISTRAR_ROLE) {
7171
for (uint256 i; i < addressTargets.length; i++) {
7272
addressAllowlist[addressTargets[i]] = true;
7373
emit AddressAllowlistChanged(addressTargets[i], true);
@@ -78,7 +78,7 @@ contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
7878
* @notice Remove a target address from Allowlist
7979
* @param addressTargets the addresses to be removed from the allowlist
8080
*/
81-
function removeAddressFromAllowlist(address[] calldata addressTargets) external onlyRoles(_REGISTRAR_ROLE) {
81+
function removeAddressFromAllowlist(address[] calldata addressTargets) external onlyRoles(Role._REGISTRAR_ROLE) {
8282
for (uint256 i; i < addressTargets.length; i++) {
8383
delete addressAllowlist[addressTargets[i]];
8484
emit AddressAllowlistChanged(addressTargets[i], false);
@@ -93,7 +93,7 @@ contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
9393
* implementation address allowlist.
9494
* @param walletAddr the wallet address to be added to the allowlist
9595
*/
96-
function addWalletToAllowlist(address walletAddr) external onlyRoles(_REGISTRAR_ROLE) {
96+
function addWalletToAllowlist(address walletAddr) external onlyRoles(Role._REGISTRAR_ROLE) {
9797
// get bytecode of wallet
9898
bytes32 codeHash;
9999
// solhint-disable-next-line no-inline-assembly
@@ -113,7 +113,7 @@ contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
113113
* This will remove the proxy bytecode hash and implementation contract address pair from the allowlist
114114
* @param walletAddr the wallet address to be removed from the allowlist
115115
*/
116-
function removeWalletFromAllowlist(address walletAddr) external onlyRoles(_REGISTRAR_ROLE) {
116+
function removeWalletFromAllowlist(address walletAddr) external onlyRoles(Role._REGISTRAR_ROLE) {
117117
// get bytecode of wallet
118118
bytes32 codeHash;
119119
// solhint-disable-next-line no-inline-assembly
@@ -129,19 +129,19 @@ contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
129129
}
130130

131131
/**
132-
* @notice Allows admin to grant `user` `_REGISTRAR_ROLE` role
133-
* @param user the address that `_REGISTRAR_ROLE` will be granted to
132+
* @notice Allows admin to grant `user` `Role._REGISTRAR_ROLE` role
133+
* @param user the address that `Role._REGISTRAR_ROLE` will be granted to
134134
*/
135-
function grantRegistrarRole(address user) external onlyRoles(_MANAGER_ROLE) {
136-
grantRoles(user, _REGISTRAR_ROLE);
135+
function grantRegistrarRole(address user) external onlyRoles(Role._MANAGER_ROLE) {
136+
grantRoles(user, Role._REGISTRAR_ROLE);
137137
}
138138

139139
/**
140-
* @notice Allows admin to revoke `_REGISTRAR_ROLE` role from `user`
141-
* @param user the address that `_REGISTRAR_ROLE` will be revoked from
140+
* @notice Allows admin to revoke `Role._REGISTRAR_ROLE` role from `user`
141+
* @param user the address that `Role._REGISTRAR_ROLE` will be revoked from
142142
*/
143-
function revokeRegistrarRole(address user) external onlyRoles(_MANAGER_ROLE) {
144-
revokeRole(user, _REGISTRAR_ROLE);
143+
function revokeRegistrarRole(address user) external onlyRoles(Role._MANAGER_ROLE) {
144+
revokeRoles(user, Role._REGISTRAR_ROLE);
145145
}
146146

147147
/// ===== View functions =====
@@ -175,8 +175,8 @@ contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
175175
* @notice ERC-165 interface support
176176
* @param interfaceId The interface identifier, which is a 4-byte selector.
177177
*/
178-
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, AccessControl) returns (bool) {
179-
return interfaceId == type(IOperatorAllowlist).interfaceId || super.supportsInterface(interfaceId);
178+
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165) returns (bool) {
179+
return interfaceId == type(IOperatorAllowlist).interfaceId;
180180
}
181181

182182
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.20;
3+
4+
import "lib/forge-std/src/console.sol";
5+
6+
import {Test} from "forge-std/Test.sol";
7+
import {Role} from "src/Role.sol";
8+
9+
// Target contract
10+
11+
import {Module} from "src/Module.sol";
12+
import {ERC721Core} from "src/core/token/ERC721Core.sol";
13+
14+
import {ICore} from "src/interface/ICore.sol";
15+
import {IModuleConfig} from "src/interface/IModuleConfig.sol";
16+
import {ImmutableAllowlistERC721} from "src/module/token/immutable/ImmutableAllowlistERC721.sol";
17+
18+
import {OperatorAllowlistEnforced} from "dependecies/immutable/allowlist/OperatorAllowlistEnforced.sol";
19+
import {OperatorAllowlistEnforcementErrors} from "dependecies/immutable/errors/Errors.sol";
20+
import {OperatorAllowlist} from "dependecies/immutable/test/allowlist/OperatorAllowlist.sol";
21+
22+
contract Core is ERC721Core {
23+
24+
constructor(
25+
string memory name,
26+
string memory symbol,
27+
string memory contractURI,
28+
address owner,
29+
address[] memory modules,
30+
bytes[] memory moduleInstallData
31+
) ERC721Core(name, symbol, contractURI, owner, modules, moduleInstallData) {}
32+
33+
// disable mint and approve callbacks for these tests
34+
function _beforeMint(address to, uint256 startTokenId, uint256 quantity, bytes calldata data) internal override {}
35+
36+
}
37+
38+
contract TransferableERC721Test is Test {
39+
40+
Core public core;
41+
42+
ImmutableAllowlistERC721 public immutableAllowlistModule;
43+
OperatorAllowlist public operatorAllowlist;
44+
45+
address public owner = address(0x1);
46+
address public actorOne = address(0x2);
47+
address public actorTwo = address(0x3);
48+
address public actorThree = address(0x4);
49+
50+
event OperatorAllowlistRegistryUpdated(address oldRegistry, address newRegistry);
51+
52+
function setUp() public {
53+
address[] memory modules;
54+
bytes[] memory moduleData;
55+
56+
core = new Core("test", "TEST", "", owner, modules, moduleData);
57+
immutableAllowlistModule = new ImmutableAllowlistERC721();
58+
operatorAllowlist = new OperatorAllowlist(owner);
59+
60+
// install module
61+
vm.startPrank(owner);
62+
bytes memory encodedOperatorAllowlist =
63+
immutableAllowlistModule.encodeBytesOnInstall(address(operatorAllowlist));
64+
core.installModule(address(immutableAllowlistModule), encodedOperatorAllowlist);
65+
vm.stopPrank();
66+
67+
// mint tokens
68+
core.mint(actorOne, 1, string(""), ""); // tokenId 0
69+
core.mint(actorTwo, 1, string(""), ""); // tokenId 1
70+
core.mint(actorThree, 1, string(""), ""); // tokenId 2
71+
72+
vm.prank(owner);
73+
core.grantRoles(owner, Role._MANAGER_ROLE);
74+
}
75+
76+
/*///////////////////////////////////////////////////////////////
77+
Unit tests: `setOperatorAllowlistRegistry`
78+
//////////////////////////////////////////////////////////////*/
79+
80+
function test_state_setOperatorAllowlistRegistry() public {
81+
OperatorAllowlist operatorAllowlist2 = new OperatorAllowlist(owner);
82+
83+
vm.prank(owner);
84+
vm.expectEmit(true, true, true, true);
85+
emit OperatorAllowlistRegistryUpdated(address(operatorAllowlist), address(operatorAllowlist2));
86+
ImmutableAllowlistERC721(address(core)).setOperatorAllowlistRegistry(address(operatorAllowlist2));
87+
88+
assertEq(ImmutableAllowlistERC721(address(core)).operatorAllowlist(), address(operatorAllowlist2));
89+
}
90+
91+
function test_revert_setOperatorAllowlistRegistry() public {
92+
vm.prank(owner);
93+
// should revert since the allowlist does not implement the IOperatorAllowlist interface
94+
// and that it doesn't implement supportsInterface
95+
vm.expectRevert();
96+
ImmutableAllowlistERC721(address(core)).setOperatorAllowlistRegistry(address(0x123));
97+
}
98+
99+
/*///////////////////////////////////////////////////////////////
100+
Unit tests: `setTransferable`
101+
//////////////////////////////////////////////////////////////*/
102+
103+
/// @notice Callback function for ERC721.approve
104+
function beforeApproveERC721(address _from, address _to, uint256 _tokenId, bool _approve)
105+
external
106+
returns (bytes memory)
107+
{}
108+
109+
/// @notice Callback function for ERC721.setApprovalForAll
110+
function beforeApproveForAll(address _from, address _to, bool _approved) external returns (bytes memory) {}
111+
112+
/// @notice Callback function for ERC721.transferFrom/safeTransferFrom
113+
function beforeTransferERC721(address _from, address _to, uint256 _tokenId) external returns (bytes memory) {}
114+
115+
}

0 commit comments

Comments
 (0)