Unverified Commit 73baf0b6 by Julian M. Rodriguez Committed by GitHub

Feature/Adding RoleAdminChanged event in AccessControl (#2214)

* Emit new event RoleAdminChanged

* Adding new RoleAdminChanged event in Tests

* Update suggested comments on new Event

Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>

* Adding PreviousAdminRole to event

* Update AccessControl.test.js

* Update CHANGELOG.md

Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
parent 78dc3773
# Changelog # 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) ## 3.0.1 (2020-04-27)
### Bugfixes ### Bugfixes
......
...@@ -53,6 +53,14 @@ abstract contract AccessControl is Context { ...@@ -53,6 +53,14 @@ abstract contract AccessControl is Context {
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; 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`. * @dev Emitted when `account` is granted `role`.
* *
* `sender` is the account that originated the contract call, an admin role * `sender` is the account that originated the contract call, an admin role
...@@ -183,8 +191,11 @@ abstract contract AccessControl is Context { ...@@ -183,8 +191,11 @@ abstract contract AccessControl is Context {
/** /**
* @dev Sets `adminRole` as ``role``'s admin role. * @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/ */
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
emit RoleAdminChanged(role, _roles[role].adminRole, adminRole);
_roles[role].adminRole = adminRole; _roles[role].adminRole = adminRole;
} }
......
...@@ -142,7 +142,13 @@ describe('AccessControl', function () { ...@@ -142,7 +142,13 @@ describe('AccessControl', function () {
describe('setting role admin', function () { describe('setting role admin', function () {
beforeEach(async 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 }); await this.accessControl.grantRole(OTHER_ROLE, otherAdmin, { from: admin });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment