Commit 95146069 by Nicolás Venturo Committed by Francisco Giordano

Added events to the role contracts. (#1302)

* Added events to the role contracts.

* Fixed linter error.
parent 84e63bbf
...@@ -6,6 +6,9 @@ import "../Roles.sol"; ...@@ -6,6 +6,9 @@ import "../Roles.sol";
contract CapperRole { contract CapperRole {
using Roles for Roles.Role; using Roles for Roles.Role;
event CapperAdded(address indexed account);
event CapperRemoved(address indexed account);
Roles.Role private cappers; Roles.Role private cappers;
constructor() public { constructor() public {
...@@ -23,6 +26,7 @@ contract CapperRole { ...@@ -23,6 +26,7 @@ contract CapperRole {
function addCapper(address _account) public onlyCapper { function addCapper(address _account) public onlyCapper {
cappers.add(_account); cappers.add(_account);
emit CapperAdded(_account);
} }
function renounceCapper() public { function renounceCapper() public {
...@@ -31,5 +35,6 @@ contract CapperRole { ...@@ -31,5 +35,6 @@ contract CapperRole {
function _removeCapper(address _account) internal { function _removeCapper(address _account) internal {
cappers.remove(_account); cappers.remove(_account);
emit CapperRemoved(_account);
} }
} }
...@@ -6,6 +6,9 @@ import "../Roles.sol"; ...@@ -6,6 +6,9 @@ import "../Roles.sol";
contract MinterRole { contract MinterRole {
using Roles for Roles.Role; using Roles for Roles.Role;
event MinterAdded(address indexed account);
event MinterRemoved(address indexed account);
Roles.Role private minters; Roles.Role private minters;
constructor() public { constructor() public {
...@@ -23,6 +26,7 @@ contract MinterRole { ...@@ -23,6 +26,7 @@ contract MinterRole {
function addMinter(address _account) public onlyMinter { function addMinter(address _account) public onlyMinter {
minters.add(_account); minters.add(_account);
emit MinterAdded(_account);
} }
function renounceMinter() public { function renounceMinter() public {
...@@ -31,5 +35,6 @@ contract MinterRole { ...@@ -31,5 +35,6 @@ contract MinterRole {
function _removeMinter(address _account) internal { function _removeMinter(address _account) internal {
minters.remove(_account); minters.remove(_account);
emit MinterRemoved(_account);
} }
} }
...@@ -6,6 +6,9 @@ import "../Roles.sol"; ...@@ -6,6 +6,9 @@ import "../Roles.sol";
contract PauserRole { contract PauserRole {
using Roles for Roles.Role; using Roles for Roles.Role;
event PauserAdded(address indexed account);
event PauserRemoved(address indexed account);
Roles.Role private pausers; Roles.Role private pausers;
constructor() public { constructor() public {
...@@ -23,6 +26,7 @@ contract PauserRole { ...@@ -23,6 +26,7 @@ contract PauserRole {
function addPauser(address _account) public onlyPauser { function addPauser(address _account) public onlyPauser {
pausers.add(_account); pausers.add(_account);
emit PauserAdded(_account);
} }
function renouncePauser() public { function renouncePauser() public {
...@@ -31,5 +35,6 @@ contract PauserRole { ...@@ -31,5 +35,6 @@ contract PauserRole {
function _removePauser(address _account) internal { function _removePauser(address _account) internal {
pausers.remove(_account); pausers.remove(_account);
emit PauserRemoved(_account);
} }
} }
...@@ -6,6 +6,9 @@ import "../Roles.sol"; ...@@ -6,6 +6,9 @@ import "../Roles.sol";
contract SignerRole { contract SignerRole {
using Roles for Roles.Role; using Roles for Roles.Role;
event SignerAdded(address indexed account);
event SignerRemoved(address indexed account);
Roles.Role private signers; Roles.Role private signers;
constructor() public { constructor() public {
...@@ -23,6 +26,7 @@ contract SignerRole { ...@@ -23,6 +26,7 @@ contract SignerRole {
function addSigner(address _account) public onlySigner { function addSigner(address _account) public onlySigner {
signers.add(_account); signers.add(_account);
emit SignerAdded(_account);
} }
function renounceSigner() public { function renounceSigner() public {
...@@ -31,5 +35,6 @@ contract SignerRole { ...@@ -31,5 +35,6 @@ contract SignerRole {
function _removeSigner(address _account) internal { function _removeSigner(address _account) internal {
signers.remove(_account); signers.remove(_account);
emit SignerRemoved(_account);
} }
} }
const expectEvent = require('../../helpers/expectEvent');
require('chai') require('chai')
.should(); .should();
...@@ -22,6 +24,11 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role ...@@ -22,6 +24,11 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
(await this.contract[`is${rolename}`](anyone)).should.equal(true); (await this.contract[`is${rolename}`](anyone)).should.equal(true);
}); });
it(`emits a ${rolename}Added event`, async function () {
const { logs } = await this.contract[`add${rolename}`](anyone, { from: authorized });
expectEvent.inLogs(logs, `${rolename}Added`, { account: anyone });
});
it('adds role to an already-assigned account', async function () { it('adds role to an already-assigned account', async function () {
await this.contract[`add${rolename}`](authorized, { from: authorized }); await this.contract[`add${rolename}`](authorized, { from: authorized });
(await this.contract[`is${rolename}`](authorized)).should.equal(true); (await this.contract[`is${rolename}`](authorized)).should.equal(true);
...@@ -39,6 +46,11 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role ...@@ -39,6 +46,11 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [anyone], role
(await this.contract[`is${rolename}`](otherAuthorized)).should.equal(true); (await this.contract[`is${rolename}`](otherAuthorized)).should.equal(true);
}); });
it(`emits a ${rolename}Removed event`, async function () {
const { logs } = await this.contract[`remove${rolename}`](authorized);
expectEvent.inLogs(logs, `${rolename}Removed`, { account: authorized });
});
it('doesn\'t revert when removing from an unassigned account', async function () { it('doesn\'t revert when removing from an unassigned account', async function () {
await this.contract[`remove${rolename}`](anyone); await this.contract[`remove${rolename}`](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