From 73baf0b635ea1103500bae1a8ca59af1f013fbc9 Mon Sep 17 00:00:00 2001 From: "Julian M. Rodriguez" <56316686+julianmrodri@users.noreply.github.com> Date: Wed, 6 May 2020 17:21:39 -0300 Subject: [PATCH] Feature/Adding RoleAdminChanged event in AccessControl (#2214) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Emit new event RoleAdminChanged * Adding new RoleAdminChanged event in Tests * Update suggested comments on new Event Co-authored-by: Nicolás Venturo * Adding PreviousAdminRole to event * Update AccessControl.test.js * Update CHANGELOG.md Co-authored-by: Nicolás Venturo --- CHANGELOG.md | 5 +++++ contracts/access/AccessControl.sol | 11 +++++++++++ test/access/AccessControl.test.js | 8 +++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d69cf231..5bccb32b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/contracts/access/AccessControl.sol b/contracts/access/AccessControl.sol index e5913be8a..8c169d959 100644 --- a/contracts/access/AccessControl.sol +++ b/contracts/access/AccessControl.sol @@ -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`. * @@ -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; } diff --git a/test/access/AccessControl.test.js b/test/access/AccessControl.test.js index c49276f92..4e4424e0c 100644 --- a/test/access/AccessControl.test.js +++ b/test/access/AccessControl.test.js @@ -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 }); });