Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix set role admin #880

Merged
merged 5 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 5 additions & 0 deletions packages/contracts/src/dollar/facets/AccessControlFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ contract AccessControlFacet is
return _grantRole(role, account);
}

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

/// @inheritdoc IAccessControl
function hasRole(
bytes32 role,
Expand Down
7 changes: 7 additions & 0 deletions packages/contracts/src/dollar/interfaces/IAccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ interface IAccessControl {
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);

/**
* @notice Sets admin role for a given role
* @param role Role to set
* @param adminRole Admin role to set for a provided role
*/
function setRoleAdmin(bytes32 role, bytes32 adminRole) external;

/**
* @notice Assigns role to a given account
* @param role Role to assign
Expand Down
21 changes: 21 additions & 0 deletions packages/contracts/test/diamond/facets/AccessControlFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,25 @@ contract AccessControlFacetTest is DiamondTestSetup {
);
assertEq(adminRole, DEFAULT_ADMIN_ROLE);
}

function testSetRoleAdmin_ShouldRevertWhenNotAdmin() public {
vm.prank(mock_sender);

vm.expectRevert("Manager: Caller is not admin");
accessControlFacet.setRoleAdmin(
DOLLAR_TOKEN_BURNER_ROLE,
DEFAULT_ADMIN_ROLE
);
}

function testSetRoleAdmin_ShouldSetAdminRoleForGivenRole() public {
bytes32 adminRole = accessControlFacet.getRoleAdmin(
DOLLAR_TOKEN_MINTER_ROLE
);
assertEq(adminRole, DEFAULT_ADMIN_ROLE);
vm.prank(admin);
accessControlFacet.setRoleAdmin(DOLLAR_TOKEN_MINTER_ROLE, PAUSER_ROLE);
adminRole = accessControlFacet.getRoleAdmin(DOLLAR_TOKEN_MINTER_ROLE);
assertEq(adminRole, PAUSER_ROLE);
}
}
Loading