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;
|
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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|||||||
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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|||||||
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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|||||||
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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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
|
|||||||
(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 });
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user