Skip to content

Commit

Permalink
initial tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
GWSzeto committed Sep 25, 2024
1 parent 274c331 commit 643675a
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 21 deletions.
42 changes: 21 additions & 21 deletions dependecies/immutable/test/allowlist/OperatorAllowlist.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright Immutable Pty Ltd 2018 - 2023
// SPDX-License-Identifier: Apache 2.0
pragma solidity 0.8.19;
pragma solidity ^0.8.24;

// Access Control

import {Role} from "../../../Role.sol";
import {Role} from "../../../../src/Role.sol";
import {OwnableRoles} from "@solady/auth/OwnableRoles.sol";

// Interfaces
Expand All @@ -19,7 +19,7 @@ interface IProxy {

}

interface IERC165 {
interface ERC165 {

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

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

contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
contract OperatorAllowlist is ERC165, OwnableRoles, IOperatorAllowlist {

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

/**
* @notice Grants `_MANAGER_ROLE` to the supplied `admin` address
* @param admin the address to grant `_MANAGER_ROLE` to
* @notice Grants `Role._MANAGER_ROLE` to the supplied `admin` address
* @param admin the address to grant `Role._MANAGER_ROLE` to
*/
constructor(address admin) {
_grantRoles(admin, _MANAGER_ROLE);
_grantRoles(admin, Role._MANAGER_ROLE);
}

/// ===== External functions =====
Expand All @@ -67,7 +67,7 @@ contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
* @notice Add a target address to Allowlist
* @param addressTargets the addresses to be added to the allowlist
*/
function addAddressToAllowlist(address[] calldata addressTargets) external onlyRoles(_REGISTRAR_ROLE) {
function addAddressToAllowlist(address[] calldata addressTargets) external onlyRoles(Role._REGISTRAR_ROLE) {
for (uint256 i; i < addressTargets.length; i++) {
addressAllowlist[addressTargets[i]] = true;
emit AddressAllowlistChanged(addressTargets[i], true);
Expand All @@ -78,7 +78,7 @@ contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
* @notice Remove a target address from Allowlist
* @param addressTargets the addresses to be removed from the allowlist
*/
function removeAddressFromAllowlist(address[] calldata addressTargets) external onlyRoles(_REGISTRAR_ROLE) {
function removeAddressFromAllowlist(address[] calldata addressTargets) external onlyRoles(Role._REGISTRAR_ROLE) {
for (uint256 i; i < addressTargets.length; i++) {
delete addressAllowlist[addressTargets[i]];
emit AddressAllowlistChanged(addressTargets[i], false);
Expand All @@ -93,7 +93,7 @@ contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
* implementation address allowlist.
* @param walletAddr the wallet address to be added to the allowlist
*/
function addWalletToAllowlist(address walletAddr) external onlyRoles(_REGISTRAR_ROLE) {
function addWalletToAllowlist(address walletAddr) external onlyRoles(Role._REGISTRAR_ROLE) {
// get bytecode of wallet
bytes32 codeHash;
// solhint-disable-next-line no-inline-assembly
Expand All @@ -113,7 +113,7 @@ contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
* This will remove the proxy bytecode hash and implementation contract address pair from the allowlist
* @param walletAddr the wallet address to be removed from the allowlist
*/
function removeWalletFromAllowlist(address walletAddr) external onlyRoles(_REGISTRAR_ROLE) {
function removeWalletFromAllowlist(address walletAddr) external onlyRoles(Role._REGISTRAR_ROLE) {
// get bytecode of wallet
bytes32 codeHash;
// solhint-disable-next-line no-inline-assembly
Expand All @@ -129,19 +129,19 @@ contract OperatorAllowlist is ERC165, AccessControl, IOperatorAllowlist {
}

/**
* @notice Allows admin to grant `user` `_REGISTRAR_ROLE` role
* @param user the address that `_REGISTRAR_ROLE` will be granted to
* @notice Allows admin to grant `user` `Role._REGISTRAR_ROLE` role
* @param user the address that `Role._REGISTRAR_ROLE` will be granted to
*/
function grantRegistrarRole(address user) external onlyRoles(_MANAGER_ROLE) {
grantRoles(user, _REGISTRAR_ROLE);
function grantRegistrarRole(address user) external onlyRoles(Role._MANAGER_ROLE) {
grantRoles(user, Role._REGISTRAR_ROLE);
}

/**
* @notice Allows admin to revoke `_REGISTRAR_ROLE` role from `user`
* @param user the address that `_REGISTRAR_ROLE` will be revoked from
* @notice Allows admin to revoke `Role._REGISTRAR_ROLE` role from `user`
* @param user the address that `Role._REGISTRAR_ROLE` will be revoked from
*/
function revokeRegistrarRole(address user) external onlyRoles(_MANAGER_ROLE) {
revokeRole(user, _REGISTRAR_ROLE);
function revokeRegistrarRole(address user) external onlyRoles(Role._MANAGER_ROLE) {
revokeRoles(user, Role._REGISTRAR_ROLE);
}

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

}
115 changes: 115 additions & 0 deletions test/module/immutable/ImmutableAllowlistERC721.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "lib/forge-std/src/console.sol";

import {Test} from "forge-std/Test.sol";
import {Role} from "src/Role.sol";

// Target contract

import {Module} from "src/Module.sol";
import {ERC721Core} from "src/core/token/ERC721Core.sol";

import {ICore} from "src/interface/ICore.sol";
import {IModuleConfig} from "src/interface/IModuleConfig.sol";
import {ImmutableAllowlistERC721} from "src/module/token/immutable/ImmutableAllowlistERC721.sol";

import {OperatorAllowlistEnforced} from "dependecies/immutable/allowlist/OperatorAllowlistEnforced.sol";
import {OperatorAllowlistEnforcementErrors} from "dependecies/immutable/errors/Errors.sol";
import {OperatorAllowlist} from "dependecies/immutable/test/allowlist/OperatorAllowlist.sol";

contract Core is ERC721Core {

constructor(
string memory name,
string memory symbol,
string memory contractURI,
address owner,
address[] memory modules,
bytes[] memory moduleInstallData
) ERC721Core(name, symbol, contractURI, owner, modules, moduleInstallData) {}

// disable mint and approve callbacks for these tests
function _beforeMint(address to, uint256 startTokenId, uint256 quantity, bytes calldata data) internal override {}

}

contract TransferableERC721Test is Test {

Core public core;

ImmutableAllowlistERC721 public immutableAllowlistModule;
OperatorAllowlist public operatorAllowlist;

address public owner = address(0x1);
address public actorOne = address(0x2);
address public actorTwo = address(0x3);
address public actorThree = address(0x4);

event OperatorAllowlistRegistryUpdated(address oldRegistry, address newRegistry);

function setUp() public {
address[] memory modules;
bytes[] memory moduleData;

core = new Core("test", "TEST", "", owner, modules, moduleData);
immutableAllowlistModule = new ImmutableAllowlistERC721();
operatorAllowlist = new OperatorAllowlist(owner);

// install module
vm.startPrank(owner);
bytes memory encodedOperatorAllowlist =
immutableAllowlistModule.encodeBytesOnInstall(address(operatorAllowlist));
core.installModule(address(immutableAllowlistModule), encodedOperatorAllowlist);
vm.stopPrank();

// mint tokens
core.mint(actorOne, 1, string(""), ""); // tokenId 0
core.mint(actorTwo, 1, string(""), ""); // tokenId 1
core.mint(actorThree, 1, string(""), ""); // tokenId 2

vm.prank(owner);
core.grantRoles(owner, Role._MANAGER_ROLE);
}

/*///////////////////////////////////////////////////////////////
Unit tests: `setOperatorAllowlistRegistry`
//////////////////////////////////////////////////////////////*/

function test_state_setOperatorAllowlistRegistry() public {
OperatorAllowlist operatorAllowlist2 = new OperatorAllowlist(owner);

vm.prank(owner);
vm.expectEmit(true, true, true, true);
emit OperatorAllowlistRegistryUpdated(address(operatorAllowlist), address(operatorAllowlist2));
ImmutableAllowlistERC721(address(core)).setOperatorAllowlistRegistry(address(operatorAllowlist2));

assertEq(ImmutableAllowlistERC721(address(core)).operatorAllowlist(), address(operatorAllowlist2));
}

function test_revert_setOperatorAllowlistRegistry() public {
vm.prank(owner);
// should revert since the allowlist does not implement the IOperatorAllowlist interface
// and that it doesn't implement supportsInterface
vm.expectRevert();
ImmutableAllowlistERC721(address(core)).setOperatorAllowlistRegistry(address(0x123));
}

/*///////////////////////////////////////////////////////////////
Unit tests: `setTransferable`
//////////////////////////////////////////////////////////////*/

/// @notice Callback function for ERC721.approve
function beforeApproveERC721(address _from, address _to, uint256 _tokenId, bool _approve)
external
returns (bytes memory)
{}

/// @notice Callback function for ERC721.setApprovalForAll
function beforeApproveForAll(address _from, address _to, bool _approved) external returns (bytes memory) {}

/// @notice Callback function for ERC721.transferFrom/safeTransferFrom
function beforeTransferERC721(address _from, address _to, uint256 _tokenId) external returns (bytes memory) {}

}

0 comments on commit 643675a

Please sign in to comment.