Commit e7c99dd7 by Nicolás Venturo Committed by Francisco Giordano

Roles now emit events in construction and when renouncing. (#1329)

* release candidate v2.0.0-rc.1

* fix linter error

(cherry picked from commit c12a1c68)

* Roles now emit events in construction and when renouncing.

(cherry picked from commit 21198bf1)
parent dac5bccf
...@@ -12,7 +12,7 @@ contract CapperRole { ...@@ -12,7 +12,7 @@ contract CapperRole {
Roles.Role private cappers; Roles.Role private cappers;
constructor() public { constructor() public {
cappers.add(msg.sender); _addCapper(msg.sender);
} }
modifier onlyCapper() { modifier onlyCapper() {
...@@ -25,12 +25,16 @@ contract CapperRole { ...@@ -25,12 +25,16 @@ contract CapperRole {
} }
function addCapper(address account) public onlyCapper { function addCapper(address account) public onlyCapper {
cappers.add(account); _addCapper(account);
emit CapperAdded(account);
} }
function renounceCapper() public { function renounceCapper() public {
cappers.remove(msg.sender); _removeCapper(msg.sender);
}
function _addCapper(address account) internal {
cappers.add(account);
emit CapperAdded(account);
} }
function _removeCapper(address account) internal { function _removeCapper(address account) internal {
......
...@@ -12,7 +12,7 @@ contract MinterRole { ...@@ -12,7 +12,7 @@ contract MinterRole {
Roles.Role private minters; Roles.Role private minters;
constructor() public { constructor() public {
minters.add(msg.sender); _addMinter(msg.sender);
} }
modifier onlyMinter() { modifier onlyMinter() {
...@@ -25,12 +25,16 @@ contract MinterRole { ...@@ -25,12 +25,16 @@ contract MinterRole {
} }
function addMinter(address account) public onlyMinter { function addMinter(address account) public onlyMinter {
minters.add(account); _addMinter(account);
emit MinterAdded(account);
} }
function renounceMinter() public { function renounceMinter() public {
minters.remove(msg.sender); _removeMinter(msg.sender);
}
function _addMinter(address account) internal {
minters.add(account);
emit MinterAdded(account);
} }
function _removeMinter(address account) internal { function _removeMinter(address account) internal {
......
...@@ -12,7 +12,7 @@ contract PauserRole { ...@@ -12,7 +12,7 @@ contract PauserRole {
Roles.Role private pausers; Roles.Role private pausers;
constructor() public { constructor() public {
pausers.add(msg.sender); _addPauser(msg.sender);
} }
modifier onlyPauser() { modifier onlyPauser() {
...@@ -25,12 +25,16 @@ contract PauserRole { ...@@ -25,12 +25,16 @@ contract PauserRole {
} }
function addPauser(address account) public onlyPauser { function addPauser(address account) public onlyPauser {
pausers.add(account); _addPauser(account);
emit PauserAdded(account);
} }
function renouncePauser() public { function renouncePauser() public {
pausers.remove(msg.sender); _removePauser(msg.sender);
}
function _addPauser(address account) internal {
pausers.add(account);
emit PauserAdded(account);
} }
function _removePauser(address account) internal { function _removePauser(address account) internal {
......
...@@ -12,7 +12,7 @@ contract SignerRole { ...@@ -12,7 +12,7 @@ contract SignerRole {
Roles.Role private signers; Roles.Role private signers;
constructor() public { constructor() public {
signers.add(msg.sender); _addSigner(msg.sender);
} }
modifier onlySigner() { modifier onlySigner() {
...@@ -25,12 +25,16 @@ contract SignerRole { ...@@ -25,12 +25,16 @@ contract SignerRole {
} }
function addSigner(address account) public onlySigner { function addSigner(address account) public onlySigner {
signers.add(account); _addSigner(account);
emit SignerAdded(account);
} }
function renounceSigner() public { function renounceSigner() public {
signers.remove(msg.sender); _removeSigner(msg.sender);
}
function _addSigner(address account) internal {
signers.add(account);
emit SignerAdded(account);
} }
function _removeSigner(address account) internal { function _removeSigner(address account) internal {
......
...@@ -89,6 +89,11 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role ...@@ -89,6 +89,11 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
(await this.contract[`is${rolename}`](authorized)).should.equal(false); (await this.contract[`is${rolename}`](authorized)).should.equal(false);
}); });
it(`emits a ${rolename}Removed event`, async function () {
const { logs } = await this.contract[`renounce${rolename}`]({ from: authorized });
expectEvent.inLogs(logs, `${rolename}Removed`, { account: authorized });
});
it('doesn\'t revert when renouncing unassigned role', async function () { it('doesn\'t revert when renouncing unassigned role', async function () {
await this.contract[`renounce${rolename}`]({ from: anyone }); await this.contract[`renounce${rolename}`]({ from: anyone });
}); });
......
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