Browse Source

Added events to the role contracts. (#1302)

* Added events to the role contracts.

* Fixed linter error.
Nicolás Venturo 7 years ago
parent
commit
951460696e

+ 5 - 0
contracts/access/roles/CapperRole.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 {
 
 
   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 {
 
 
   function _removeCapper(address _account) internal {
   function _removeCapper(address _account) internal {
     cappers.remove(_account);
     cappers.remove(_account);
+    emit CapperRemoved(_account);
   }
   }
 }
 }

+ 5 - 0
contracts/access/roles/MinterRole.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 {
 
 
   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 {
 
 
   function _removeMinter(address _account) internal {
   function _removeMinter(address _account) internal {
     minters.remove(_account);
     minters.remove(_account);
+    emit MinterRemoved(_account);
   }
   }
 }
 }

+ 5 - 0
contracts/access/roles/PauserRole.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 {
 
 
   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 {
 
 
   function _removePauser(address _account) internal {
   function _removePauser(address _account) internal {
     pausers.remove(_account);
     pausers.remove(_account);
+    emit PauserRemoved(_account);
   }
   }
 }
 }

+ 5 - 0
contracts/access/roles/SignerRole.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 {
 
 
   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 {
 
 
   function _removeSigner(address _account) internal {
   function _removeSigner(address _account) internal {
     signers.remove(_account);
     signers.remove(_account);
+    emit SignerRemoved(_account);
   }
   }
 }
 }

+ 12 - 0
test/access/roles/PublicRole.behavior.js

@@ -1,3 +1,5 @@
+const expectEvent = require('../../helpers/expectEvent');
+
 require('chai')
 require('chai')
   .should();
   .should();
 
 
@@ -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
         (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);
       });
       });