Roles now emit events in construction and when renouncing. (#1329)
* release candidate v2.0.0-rc.1 * fix linter error (cherry picked from commitc12a1c6898) * Roles now emit events in construction and when renouncing. (cherry picked from commit21198bf1c1)
This commit is contained in:
committed by
Francisco Giordano
parent
dac5bccf80
commit
e7c99dd7dd
@ -12,7 +12,7 @@ contract CapperRole {
|
||||
Roles.Role private cappers;
|
||||
|
||||
constructor() public {
|
||||
cappers.add(msg.sender);
|
||||
_addCapper(msg.sender);
|
||||
}
|
||||
|
||||
modifier onlyCapper() {
|
||||
@ -25,12 +25,16 @@ contract CapperRole {
|
||||
}
|
||||
|
||||
function addCapper(address account) public onlyCapper {
|
||||
cappers.add(account);
|
||||
emit CapperAdded(account);
|
||||
_addCapper(account);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@ -12,7 +12,7 @@ contract MinterRole {
|
||||
Roles.Role private minters;
|
||||
|
||||
constructor() public {
|
||||
minters.add(msg.sender);
|
||||
_addMinter(msg.sender);
|
||||
}
|
||||
|
||||
modifier onlyMinter() {
|
||||
@ -25,12 +25,16 @@ contract MinterRole {
|
||||
}
|
||||
|
||||
function addMinter(address account) public onlyMinter {
|
||||
minters.add(account);
|
||||
emit MinterAdded(account);
|
||||
_addMinter(account);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@ -12,7 +12,7 @@ contract PauserRole {
|
||||
Roles.Role private pausers;
|
||||
|
||||
constructor() public {
|
||||
pausers.add(msg.sender);
|
||||
_addPauser(msg.sender);
|
||||
}
|
||||
|
||||
modifier onlyPauser() {
|
||||
@ -25,12 +25,16 @@ contract PauserRole {
|
||||
}
|
||||
|
||||
function addPauser(address account) public onlyPauser {
|
||||
pausers.add(account);
|
||||
emit PauserAdded(account);
|
||||
_addPauser(account);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@ -12,7 +12,7 @@ contract SignerRole {
|
||||
Roles.Role private signers;
|
||||
|
||||
constructor() public {
|
||||
signers.add(msg.sender);
|
||||
_addSigner(msg.sender);
|
||||
}
|
||||
|
||||
modifier onlySigner() {
|
||||
@ -25,12 +25,16 @@ contract SignerRole {
|
||||
}
|
||||
|
||||
function addSigner(address account) public onlySigner {
|
||||
signers.add(account);
|
||||
emit SignerAdded(account);
|
||||
_addSigner(account);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@ -89,6 +89,11 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
|
||||
(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 () {
|
||||
await this.contract[`renounce${rolename}`]({ from: anyone });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user