Roles now emit events in construction and when renouncing. (#1329)
* release candidate v2.0.0-rc.1
* fix linter error
(cherry picked from commit c12a1c6898)
* Roles now emit events in construction and when renouncing.
This commit is contained in:
committed by
Francisco Giordano
parent
9b37104655
commit
21198bf1c1
@ -11,7 +11,7 @@ contract CapperRole {
|
||||
Roles.Role private cappers;
|
||||
|
||||
constructor() public {
|
||||
cappers.add(msg.sender);
|
||||
_addCapper(msg.sender);
|
||||
}
|
||||
|
||||
modifier onlyCapper() {
|
||||
@ -24,12 +24,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 {
|
||||
|
||||
@ -11,7 +11,7 @@ contract MinterRole {
|
||||
Roles.Role private minters;
|
||||
|
||||
constructor() public {
|
||||
minters.add(msg.sender);
|
||||
_addMinter(msg.sender);
|
||||
}
|
||||
|
||||
modifier onlyMinter() {
|
||||
@ -24,12 +24,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 {
|
||||
|
||||
@ -11,7 +11,7 @@ contract PauserRole {
|
||||
Roles.Role private pausers;
|
||||
|
||||
constructor() public {
|
||||
pausers.add(msg.sender);
|
||||
_addPauser(msg.sender);
|
||||
}
|
||||
|
||||
modifier onlyPauser() {
|
||||
@ -24,12 +24,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 {
|
||||
|
||||
@ -11,7 +11,7 @@ contract SignerRole {
|
||||
Roles.Role private signers;
|
||||
|
||||
constructor() public {
|
||||
signers.add(msg.sender);
|
||||
_addSigner(msg.sender);
|
||||
}
|
||||
|
||||
modifier onlySigner() {
|
||||
@ -24,12 +24,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 {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"package_name": "zeppelin",
|
||||
"version": "1.12.0",
|
||||
"version": "2.0.0-rc.1",
|
||||
"description": "Secure Smart Contract library for Solidity",
|
||||
"authors": [
|
||||
"OpenZeppelin Community <maintainers@openzeppelin.org>"
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "openzeppelin-solidity",
|
||||
"version": "1.12.0",
|
||||
"version": "2.0.0-rc.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "openzeppelin-solidity",
|
||||
"version": "1.12.0",
|
||||
"version": "2.0.0-rc.1",
|
||||
"description": "Secure Smart Contract library for Solidity",
|
||||
"files": [
|
||||
"build",
|
||||
|
||||
@ -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