Skip to content

Commit 5012443

Browse files
committed
Roles now emit events in construction and when renouncing.
1 parent 735996e commit 5012443

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

contracts/access/roles/CapperRole.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contract CapperRole {
1212
Roles.Role private cappers;
1313

1414
constructor() public {
15-
cappers.add(msg.sender);
15+
_addCapper(msg.sender);
1616
}
1717

1818
modifier onlyCapper() {
@@ -25,12 +25,16 @@ contract CapperRole {
2525
}
2626

2727
function addCapper(address account) public onlyCapper {
28-
cappers.add(account);
29-
emit CapperAdded(account);
28+
_addCapper(account);
3029
}
3130

3231
function renounceCapper() public {
33-
cappers.remove(msg.sender);
32+
_removeCapper(msg.sender);
33+
}
34+
35+
function _addCapper(address account) internal {
36+
cappers.add(account);
37+
emit CapperAdded(account);
3438
}
3539

3640
function _removeCapper(address account) internal {

contracts/access/roles/MinterRole.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contract MinterRole {
1212
Roles.Role private minters;
1313

1414
constructor() public {
15-
minters.add(msg.sender);
15+
_addMinter(msg.sender);
1616
}
1717

1818
modifier onlyMinter() {
@@ -25,12 +25,16 @@ contract MinterRole {
2525
}
2626

2727
function addMinter(address account) public onlyMinter {
28-
minters.add(account);
29-
emit MinterAdded(account);
28+
_addMinter(account);
3029
}
3130

3231
function renounceMinter() public {
33-
minters.remove(msg.sender);
32+
_removeMinter(msg.sender);
33+
}
34+
35+
function _addMinter(address account) internal {
36+
minters.add(account);
37+
emit MinterAdded(account);
3438
}
3539

3640
function _removeMinter(address account) internal {

contracts/access/roles/PauserRole.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contract PauserRole {
1212
Roles.Role private pausers;
1313

1414
constructor() public {
15-
pausers.add(msg.sender);
15+
_addPauser(msg.sender);
1616
}
1717

1818
modifier onlyPauser() {
@@ -25,12 +25,16 @@ contract PauserRole {
2525
}
2626

2727
function addPauser(address account) public onlyPauser {
28-
pausers.add(account);
29-
emit PauserAdded(account);
28+
_addPauser(account);
3029
}
3130

3231
function renouncePauser() public {
33-
pausers.remove(msg.sender);
32+
_removePauser(msg.sender);
33+
}
34+
35+
function _addPauser(address account) internal {
36+
pausers.add(account);
37+
emit PauserAdded(account);
3438
}
3539

3640
function _removePauser(address account) internal {

contracts/access/roles/SignerRole.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contract SignerRole {
1212
Roles.Role private signers;
1313

1414
constructor() public {
15-
signers.add(msg.sender);
15+
_addSigner(msg.sender);
1616
}
1717

1818
modifier onlySigner() {
@@ -25,12 +25,16 @@ contract SignerRole {
2525
}
2626

2727
function addSigner(address account) public onlySigner {
28-
signers.add(account);
29-
emit SignerAdded(account);
28+
_addSigner(account);
3029
}
3130

3231
function renounceSigner() public {
33-
signers.remove(msg.sender);
32+
_removeSigner(msg.sender);
33+
}
34+
35+
function _addSigner(address account) internal {
36+
signers.add(account);
37+
emit SignerAdded(account);
3438
}
3539

3640
function _removeSigner(address account) internal {

test/access/roles/PublicRole.behavior.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
8989
(await this.contract[`is${rolename}`](authorized)).should.equal(false);
9090
});
9191

92+
it(`emits a ${rolename}Removed event`, async function () {
93+
const { logs } = await this.contract[`renounce${rolename}`]({ from: authorized });
94+
expectEvent.inLogs(logs, `${rolename}Removed`, { account: authorized });
95+
});
96+
9297
it('doesn\'t revert when renouncing unassigned role', async function () {
9398
await this.contract[`renounce${rolename}`]({ from: anyone });
9499
});

0 commit comments

Comments
 (0)