Skip to content

Commit

Permalink
feat: update access control for setRoleAdmin
Browse files Browse the repository at this point in the history
  • Loading branch information
gitcoindev committed Jan 19, 2024
1 parent 2a2a0e3 commit 3185ffd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
12 changes: 12 additions & 0 deletions packages/contracts/src/dollar/access/AccessControlInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ abstract contract AccessControlInternal {
return LibAccessControl.accessControlStorage().roles[role].adminRole;
}

/**
* @notice Set admin role for a given role
* @param role Role to set
* @param adminRole role for the provided role
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
LibAccessControl
.accessControlStorage()
.roles[role]
.adminRole = adminRole;
}

/**
* @notice Assigns role to a given account
* @param role Role to assign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract AccessControlFacet is

/// @inheritdoc IAccessControl
function setRoleAdmin(bytes32 role, bytes32 adminRole) external onlyAdmin {
return setRoleAdmin(role, adminRole);
_setRoleAdmin(role, adminRole);
}

/// @inheritdoc IAccessControl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface IAccessControl {
/**
* @notice Sets admin role for a given role
* @param role Role to set
* @return adminRole Admin role to set for a provided role
* @param adminRole Admin role to set for a provided role
*/
function setRoleAdmin(bytes32 role, bytes32 adminRole) external;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,12 @@ contract AccessControlFacetTest is DiamondTestSetup {
DOLLAR_TOKEN_MINTER_ROLE
);
assertEq(adminRole, DOLLAR_TOKEN_MINTER_ROLE);
vm.prank(admin);
accessControlFacet.setRoleAdmin(
DOLLAR_TOKEN_MINTER_ROLE,
DOLLAR_TOKEN_BURNER_ROLE
);
bytes32 adminRole = accessControlFacet.getRoleAdmin(
DOLLAR_TOKEN_MINTER_ROLE
);
adminRole = accessControlFacet.getRoleAdmin(DOLLAR_TOKEN_MINTER_ROLE);
assertEq(adminRole, DOLLAR_TOKEN_BURNER_ROLE);
}
}

0 comments on commit 3185ffd

Please sign in to comment.