From c55f6f46636801f7d1f0abcd1e06a4c0d2492627 Mon Sep 17 00:00:00 2001 From: malteish Date: Tue, 6 Jun 2023 12:40:56 +0200 Subject: [PATCH] check for requirements == 0 --- contracts/Token.sol | 4 +++- test/Token.t.sol | 52 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/contracts/Token.sol b/contracts/Token.sol index 4ba47c8b..94af8cbf 100644 --- a/contracts/Token.sol +++ b/contracts/Token.sol @@ -269,7 +269,9 @@ contract Token is ERC2771Context, ERC20Permit, Pausable, AccessControl { */ function _checkIfAllowedToTransact(address _address) internal view { require( - hasRole(TRANSFERER_ROLE, _address) || allowList.map(_address) & requirements == requirements, + requirements == 0 || + hasRole(TRANSFERER_ROLE, _address) || + allowList.map(_address) & requirements == requirements, "Sender or Receiver is not allowed to transact. Either locally issue the role as a TRANSFERER or they must meet requirements as defined in the allowList" ); } diff --git a/test/Token.t.sol b/test/Token.t.sol index aa34eff2..52b32570 100644 --- a/test/Token.t.sol +++ b/test/Token.t.sol @@ -30,7 +30,6 @@ contract tokenTest is Test { Fees memory fees = Fees(100, 100, 100, 0); feeSettings = new FeeSettings(fees, admin); token = new Token(trustedForwarder, feeSettings, admin, allowList, 0x0, "testToken", "TEST"); - console.log(msg.sender); // set up roles vm.startPrank(admin); @@ -175,12 +174,6 @@ contract tokenTest is Test { assertTrue(token.hasRole(role, pauser)); } - // function testFailRemoveLastDefaultAdmin() public { - // bytes32 role = token.DEFAULT_ADMIN_ROLE(); - // vm.prank(admin); - // token.revokeRole(role, admin); - // } - function testSetRequirements(uint256 newRequirements) public { bytes32 role = token.REQUIREMENT_ROLE(); vm.prank(admin); @@ -811,6 +804,51 @@ contract tokenTest is Test { assertTrue(token.balanceOf(burner) == 40); } + function testTransferWith0Requirements() public { + uint256 mintAmount = 200; + uint256 transferAmount = 82; + address receiver = address(0x123); + vm.assume(mintAmount >= transferAmount); + vm.assume(mintAmount < type(uint256).max / 2); // avoid overflow due to fees + vm.assume(receiver != address(0)); + vm.assume(receiver != pauser); + + // create tokens + bytes32 roleMintAllower = token.MINTALLOWER_ROLE(); + + vm.prank(admin); + token.grantRole(roleMintAllower, mintAllower); + vm.prank(mintAllower); + token.increaseMintingAllowance(minter, mintAmount); + assertTrue(token.mintingAllowance(minter) == mintAmount); + + // set requirements to 0 + bytes32 role = token.REQUIREMENT_ROLE(); + vm.prank(admin); + token.grantRole(role, requirer); + vm.prank(requirer); + token.setRequirements(0); + assertTrue(token.requirements() == 0); + + // mint some tokens + vm.prank(minter); + token.mint(pauser, mintAmount); + + assertTrue(token.balanceOf(pauser) == mintAmount); + + // transfer token + vm.prank(pauser); + uint256 gasAfter = gasleft(); + uint256 gasBefore = gasleft(); + token.transfer(receiver, transferAmount); + gasAfter = gasleft(); + + console.log("gas used: ", gasBefore - gasAfter); + + assertTrue(token.balanceOf(pauser) == mintAmount - transferAmount); + assertTrue(token.balanceOf(receiver) == transferAmount); + } + function testLoseAndGainRequirements() public { address person1 = vm.addr(1); address person2 = vm.addr(2);