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

Feature/Adding RoleAdminChanged event in AccessControl #2214

Merged
merged 8 commits into from
May 6, 2020
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.1.0 (unreleased)

### Improvements
* `AccessControl`: added a `RoleAdminChanged` event to `_setAdminRole`. ([#2214](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2214))

## 3.0.1 (2020-04-27)

### Bugfixes
Expand Down
11 changes: 11 additions & 0 deletions contracts/access/AccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ abstract contract AccessControl is Context {

bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

/**
* @dev Emitted when `account` is granted `role`.
*
Expand Down Expand Up @@ -183,8 +191,11 @@ abstract contract AccessControl is Context {

/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
emit RoleAdminChanged(role, _roles[role].adminRole, adminRole);
_roles[role].adminRole = adminRole;
}

Expand Down
8 changes: 7 additions & 1 deletion test/access/AccessControl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ describe('AccessControl', function () {

describe('setting role admin', function () {
beforeEach(async function () {
await this.accessControl.setRoleAdmin(ROLE, OTHER_ROLE);
const receipt = await this.accessControl.setRoleAdmin(ROLE, OTHER_ROLE);
expectEvent(receipt, 'RoleAdminChanged', {
role: ROLE,
previousAdminRole: DEFAULT_ADMIN_ROLE,
newAdminRole: OTHER_ROLE
});

await this.accessControl.grantRole(OTHER_ROLE, otherAdmin, { from: admin });
});

Expand Down