Skip to content

Commit

Permalink
fix: check for pauser role
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomariscal committed Dec 4, 2024
1 parent d9b3dba commit 1cfbef7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
25 changes: 16 additions & 9 deletions l2-contracts/test/ZkCappedMinterV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,18 @@ contract Pause is ZkCappedMinterV2Test {
cappedMinter.mint(_receiver, _amount);
}

function testFuzz_RevertIf_NonAdminAttemptsToPause(address _admin, address _nonAdmin, uint256 _cap) public {
function testFuzz_RevertIf_NotPauserRole(address _admin, uint256 _cap) public {
_cap = bound(_cap, 0, MAX_MINT_SUPPLY);
vm.assume(_admin != address(0));
vm.assume(_nonAdmin != address(0) && _nonAdmin != _admin);

ZkCappedMinterV2 cappedMinter = createCappedMinter(_admin, _cap);

vm.expectRevert(abi.encodeWithSelector(ZkCappedMinterV2.ZkCappedMinterV2__Unauthorized.selector, _nonAdmin));
vm.prank(_nonAdmin);
// Remove PAUSER_ROLE from admin
vm.prank(_admin);
cappedMinter.revokeRole(PAUSER_ROLE, _admin);

vm.expectRevert(abi.encodeWithSelector(ZkCappedMinterV2.ZkCappedMinterV2__Unauthorized.selector, _admin));
vm.prank(_admin);
cappedMinter.pause();
}
}
Expand Down Expand Up @@ -222,18 +225,22 @@ contract Unpause is ZkCappedMinterV2Test {
assertEq(token.balanceOf(_receiver), _amount);
}

function testFuzz_RevertIf_NonAdminAttemptsToUnpause(address _admin, address _nonAdmin, uint256 _cap) public {
_cap = bound(_cap, 1, MAX_MINT_SUPPLY);
function testFuzz_RevertIf_NotPauserRole(address _admin, uint256 _cap) public {
_cap = bound(_cap, 0, MAX_MINT_SUPPLY);
vm.assume(_admin != address(0));
vm.assume(_nonAdmin != address(0) && _nonAdmin != _admin);

ZkCappedMinterV2 cappedMinter = createCappedMinter(_admin, _cap);

// Pause first (while admin still has PAUSER_ROLE)
vm.prank(_admin);
cappedMinter.pause();

vm.expectRevert(abi.encodeWithSelector(ZkCappedMinterV2.ZkCappedMinterV2__Unauthorized.selector, _nonAdmin));
vm.prank(_nonAdmin);
// Remove PAUSER_ROLE from admin
vm.prank(_admin);
cappedMinter.revokeRole(PAUSER_ROLE, _admin);

vm.expectRevert(abi.encodeWithSelector(ZkCappedMinterV2.ZkCappedMinterV2__Unauthorized.selector, _admin));
vm.prank(_admin);
cappedMinter.unpause();
}
}
1 change: 1 addition & 0 deletions l2-contracts/test/utils/ZkTokenTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ contract ZkTokenTest is Test {
// Placed here for convenience in tests. Must match the constants in the implementation.
bytes32 public DEFAULT_ADMIN_ROLE = 0x00;
bytes32 public MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public BURNER_ROLE = keccak256("BURNER_ROLE");
bytes32 public MINTER_ADMIN_ROLE = keccak256("MINTER_ADMIN_ROLE");
bytes32 public BURNER_ADMIN_ROLE = keccak256("BURNER_ADMIN_ROLE");
Expand Down

0 comments on commit 1cfbef7

Please sign in to comment.