Skip to content

Commit

Permalink
♻️ Sets DEFAULT_ADMIN_ROLE as the roleAdmin for BURNER_ROLE
Browse files Browse the repository at this point in the history
  • Loading branch information
has5aan committed Dec 14, 2023
1 parent 618f00e commit e8ae3d6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
8 changes: 1 addition & 7 deletions src/L1/L1LiskToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ contract L1LiskToken is ERC20Burnable, AccessControl, ERC20Permit {
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");

constructor() ERC20(NAME, SYMBOL) ERC20Permit(NAME) {
bytes32 admin = bytes32(uint256(uint160(msg.sender)));
_setRoleAdmin(DEFAULT_ADMIN_ROLE, admin);
_setRoleAdmin(BURNER_ROLE, admin);
_setRoleAdmin(BURNER_ROLE, DEFAULT_ADMIN_ROLE);
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_mint(msg.sender, TOTAL_SUPPLY);
}

function transferOwnership(address account) public onlyRole(DEFAULT_ADMIN_ROLE) {
bytes32 admin = bytes32(uint256(uint160(account)));
_setRoleAdmin(DEFAULT_ADMIN_ROLE, admin);
_setRoleAdmin(BURNER_ROLE, admin);

_grantRole(DEFAULT_ADMIN_ROLE, account);
_revokeRole(DEFAULT_ADMIN_ROLE, msg.sender);
}
Expand Down
12 changes: 2 additions & 10 deletions test/L1/L1LiskToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,12 @@ contract L1LiskTokenTest is Test {
function test_onlyOwnerTransfersTheOwnership() public {
address alice = address(0x1);
address bob = address(0x2);
bytes32 aliceAsRoleAdmin = bytes32(uint256(uint160(alice)));
vm.prank(alice);
vm.expectRevert(
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, defaultAdminRole)
);
l1LiskToken.transferOwnership(bob);

vm.expectEmit(true, true, true, true, address(l1LiskToken));
emit RoleAdminChanged(defaultAdminRole, bytes32(uint256(uint160(address(this)))), aliceAsRoleAdmin);
vm.expectEmit(true, true, true, true, address(l1LiskToken));
emit RoleGranted(defaultAdminRole, alice, address(this));
vm.expectEmit(true, true, true, true, address(l1LiskToken));
Expand All @@ -176,14 +173,9 @@ contract L1LiskTokenTest is Test {

assertFalse(l1LiskToken.hasRole(defaultAdminRole, address(this)));
assertTrue(l1LiskToken.hasRole(defaultAdminRole, alice));

assertEq(aliceAsRoleAdmin, l1LiskToken.getRoleAdmin(defaultAdminRole));
assertEq(aliceAsRoleAdmin, l1LiskToken.getRoleAdmin(l1LiskToken.getBurnerRole()));
}

function test_ownerIsAdminForOwnerAndBurnerRole() public {
bytes32 roleAdmin = bytes32(uint256(uint160(address(this))));
assertEq(roleAdmin, l1LiskToken.getRoleAdmin(defaultAdminRole));
assertEq(roleAdmin, l1LiskToken.getRoleAdmin(l1LiskToken.getBurnerRole()));
function test_defaultRoleIsRoleAdminForBurnerRole() public {
assertEq(defaultAdminRole, l1LiskToken.getRoleAdmin(l1LiskToken.getBurnerRole()));
}
}

0 comments on commit e8ae3d6

Please sign in to comment.