Skip to content

Commit

Permalink
(Q-2) Inconsistency between Token contracts regarding pause/unpause f…
Browse files Browse the repository at this point in the history
…unctionality
  • Loading branch information
kumaryash90 committed Sep 20, 2022
1 parent e92cfed commit 280668c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 72 deletions.
34 changes: 1 addition & 33 deletions contracts/token/TokenERC20.sol
Expand Up @@ -10,7 +10,6 @@ import "../extension/interface/IPrimarySale.sol";

// Token
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol";

// Security
Expand Down Expand Up @@ -38,7 +37,6 @@ contract TokenERC20 is
ERC2771ContextUpgradeable,
MulticallUpgradeable,
ERC20BurnableUpgradeable,
ERC20PausableUpgradeable,
ERC20VotesUpgradeable,
ITokenERC20,
AccessControlEnumerableUpgradeable
Expand All @@ -54,7 +52,6 @@ contract TokenERC20 is
);

bytes32 internal constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 internal constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 internal constant TRANSFER_ROLE = keccak256("TRANSFER_ROLE");

/// @dev Returns the URI for the storefront-level metadata of the contract.
Expand Down Expand Up @@ -103,7 +100,6 @@ contract TokenERC20 is
_setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin);
_setupRole(TRANSFER_ROLE, _defaultAdmin);
_setupRole(MINTER_ROLE, _defaultAdmin);
_setupRole(PAUSER_ROLE, _defaultAdmin);
_setupRole(TRANSFER_ROLE, address(0));
}

Expand All @@ -130,7 +126,7 @@ contract TokenERC20 is
address from,
address to,
uint256 amount
) internal override(ERC20Upgradeable, ERC20PausableUpgradeable) {
) internal override {
super._beforeTokenTransfer(from, to, amount);

if (!hasRole(TRANSFER_ROLE, address(0)) && from != address(0) && to != address(0)) {
Expand Down Expand Up @@ -268,34 +264,6 @@ contract TokenERC20 is
);
}

/**
* @dev Pauses all token transfers.
*
* See {ERC20Pausable} and {Pausable-_pause}.
*
* Requirements:
*
* - the caller must have the `PAUSER_ROLE`.
*/
function pause() public virtual {
require(hasRole(PAUSER_ROLE, _msgSender()), "not pauser.");
_pause();
}

/**
* @dev Unpauses all token transfers.
*
* See {ERC20Pausable} and {Pausable-_unpause}.
*
* Requirements:
*
* - the caller must have the `PAUSER_ROLE`.
*/
function unpause() public virtual {
require(hasRole(PAUSER_ROLE, _msgSender()), "not pauser.");
_unpause();
}

/// @dev Sets contract URI for the storefront-level metadata of the contract.
function setContractURI(string calldata _uri) external onlyRole(DEFAULT_ADMIN_ROLE) {
contractURI = _uri;
Expand Down
39 changes: 0 additions & 39 deletions src/test/token/TokenERC20.t.sol
Expand Up @@ -422,43 +422,4 @@ contract TokenERC20Test is BaseTest {
vm.prank(address(0x1));
tokenContract.setContractURI("");
}

/*///////////////////////////////////////////////////////////////
Unit tests: pause/unpause
//////////////////////////////////////////////////////////////*/

function test_state_pause() public {
vm.prank(deployerSigner);
tokenContract.pause();

assertEq(tokenContract.paused(), true);

vm.expectRevert("Pausable: paused");
vm.prank(deployerSigner);
tokenContract.pause();
}

function test_revert_pause_NotAuthorized() public {
vm.expectRevert("not pauser.");
vm.prank(address(0x1));
tokenContract.pause();
}

function test_state_unpause() public {
vm.prank(deployerSigner);
tokenContract.pause();

assertEq(tokenContract.paused(), true);

vm.prank(deployerSigner);
tokenContract.unpause();

assertFalse(tokenContract.paused());
}

function test_revert_unpause_NotAuthorized() public {
vm.expectRevert("not pauser.");
vm.prank(address(0x1));
tokenContract.unpause();
}
}

0 comments on commit 280668c

Please sign in to comment.