Skip to content

Commit

Permalink
Rename WhitelisterRole to WhitelistAdminRole. (#1589)
Browse files Browse the repository at this point in the history
* Rename WhitelisterRole to WhitelistAdminRole.

* Update WhitelistAdmin changelog entry.
  • Loading branch information
nventuro authored Jan 4, 2019
1 parent a5b14f2 commit 35d7039
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 88 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### New features:
* Now targeting the 0.5.x line of Solidity compilers. For 0.4.24 support, use version 2.0 of OpenZeppelin.
* `WhitelistCrowdsale`: a crowdsale where only whitelisted accounts (`WhitelistedRole`) can purchase tokens. Adding or removing accounts from the whitelist is done by whitelisters (`WhitelisterRole`). Similar to the pre-2.0 `WhitelistedCrowdsale`. ([#1525](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1525))
* `WhitelistCrowdsale`: a crowdsale where only whitelisted accounts (`WhitelistedRole`) can purchase tokens. Adding or removing accounts from the whitelist is done by whitelist admins (`WhitelistAdminRole`). Similar to the pre-2.0 `WhitelistedCrowdsale`. ([#1525](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1525), [#1589](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1589))
* `RefundablePostDeliveryCrowdsale`: replacement for `RefundableCrowdsale` (deprecated, see below) where tokens are only granted once the crowdsale ends (if it meets its goal). ([#1543](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1543))
* `PausableCrowdsale`: allows for pausers (`PauserRole`) to pause token purchases. Other crowdsale operations (e.g. withdrawals and refunds, if applicable) are not affected. ([#832](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/832))
* `ERC20`: `transferFrom` and `_burnFrom ` now emit `Approval` events, to represent the token's state comprehensively through events. ([#1524](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1524))
Expand Down
47 changes: 47 additions & 0 deletions contracts/access/roles/WhitelistAdminRole.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
pragma solidity ^0.5.0;

import "../Roles.sol";

/**
* @title WhitelistAdminRole
* @dev WhitelistAdmins are responsible for assigning and removing Whitelisted accounts.
*/
contract WhitelistAdminRole {
using Roles for Roles.Role;

event WhitelistAdminAdded(address indexed account);
event WhitelistAdminRemoved(address indexed account);

Roles.Role private _whitelistAdmins;

constructor () internal {
_addWhitelistAdmin(msg.sender);
}

modifier onlyWhitelistAdmin() {
require(isWhitelistAdmin(msg.sender));
_;
}

function isWhitelistAdmin(address account) public view returns (bool) {
return _whitelistAdmins.has(account);
}

function addWhitelistAdmin(address account) public onlyWhitelistAdmin {
_addWhitelistAdmin(account);
}

function renounceWhitelistAdmin() public {
_removeWhitelistAdmin(msg.sender);
}

function _addWhitelistAdmin(address account) internal {
_whitelistAdmins.add(account);
emit WhitelistAdminAdded(account);
}

function _removeWhitelistAdmin(address account) internal {
_whitelistAdmins.remove(account);
emit WhitelistAdminRemoved(account);
}
}
14 changes: 7 additions & 7 deletions contracts/access/roles/WhitelistedRole.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
pragma solidity ^0.5.0;

import "../Roles.sol";
import "./WhitelisterRole.sol";
import "./WhitelistAdminRole.sol";

/**
* @title WhitelistedRole
* @dev Whitelisted accounts have been approved by a Whitelister to perform certain actions (e.g. participate in a
* crowdsale). This role is special in that the only accounts that can add it are Whitelisters (who can also remove it),
* and not Whitelisteds themselves.
* @dev Whitelisted accounts have been approved by a WhitelistAdmin to perform certain actions (e.g. participate in a
* crowdsale). This role is special in that the only accounts that can add it are WhitelistAdmins (who can also remove
* it), and not Whitelisteds themselves.
*/
contract WhitelistedRole is WhitelisterRole {
contract WhitelistedRole is WhitelistAdminRole {
using Roles for Roles.Role;

event WhitelistedAdded(address indexed account);
Expand All @@ -26,11 +26,11 @@ contract WhitelistedRole is WhitelisterRole {
return _whitelisteds.has(account);
}

function addWhitelisted(address account) public onlyWhitelister {
function addWhitelisted(address account) public onlyWhitelistAdmin {
_addWhitelisted(account);
}

function removeWhitelisted(address account) public onlyWhitelister {
function removeWhitelisted(address account) public onlyWhitelistAdmin {
_removeWhitelisted(account);
}

Expand Down
47 changes: 0 additions & 47 deletions contracts/access/roles/WhitelisterRole.sol

This file was deleted.

17 changes: 17 additions & 0 deletions contracts/mocks/WhitelistAdminRoleMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pragma solidity ^0.5.0;

import "../access/roles/WhitelistAdminRole.sol";

contract WhitelistAdminRoleMock is WhitelistAdminRole {
function removeWhitelistAdmin(address account) public {
_removeWhitelistAdmin(account);
}

function onlyWhitelistAdminMock() public view onlyWhitelistAdmin {
}

// Causes a compilation error if super._removeWhitelistAdmin is not internal
function _removeWhitelistAdmin(address account) internal {
super._removeWhitelistAdmin(account);
}
}
17 changes: 0 additions & 17 deletions contracts/mocks/WhitelisterRoleMock.sol

This file was deleted.

11 changes: 11 additions & 0 deletions test/access/roles/WhitelistAdminRole.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { shouldBehaveLikePublicRole } = require('../../access/roles/PublicRole.behavior');
const WhitelistAdminRoleMock = artifacts.require('WhitelistAdminRoleMock');

contract('WhitelistAdminRole', function ([_, whitelistAdmin, otherWhitelistAdmin, ...otherAccounts]) {
beforeEach(async function () {
this.contract = await WhitelistAdminRoleMock.new({ from: whitelistAdmin });
await this.contract.addWhitelistAdmin(otherWhitelistAdmin, { from: whitelistAdmin });
});

shouldBehaveLikePublicRole(whitelistAdmin, otherWhitelistAdmin, otherAccounts, 'whitelistAdmin');
});
10 changes: 5 additions & 5 deletions test/access/roles/WhitelistedRole.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { shouldBehaveLikePublicRole } = require('../../access/roles/PublicRole.behavior');
const WhitelistedRoleMock = artifacts.require('WhitelistedRoleMock');

contract('WhitelistedRole', function ([_, whitelisted, otherWhitelisted, whitelister, ...otherAccounts]) {
contract('WhitelistedRole', function ([_, whitelisted, otherWhitelisted, whitelistAdmin, ...otherAccounts]) {
beforeEach(async function () {
this.contract = await WhitelistedRoleMock.new({ from: whitelister });
await this.contract.addWhitelisted(whitelisted, { from: whitelister });
await this.contract.addWhitelisted(otherWhitelisted, { from: whitelister });
this.contract = await WhitelistedRoleMock.new({ from: whitelistAdmin });
await this.contract.addWhitelisted(whitelisted, { from: whitelistAdmin });
await this.contract.addWhitelisted(otherWhitelisted, { from: whitelistAdmin });
});

shouldBehaveLikePublicRole(whitelisted, otherWhitelisted, otherAccounts, 'whitelisted', whitelister);
shouldBehaveLikePublicRole(whitelisted, otherWhitelisted, otherAccounts, 'whitelisted', whitelistAdmin);
});
11 changes: 0 additions & 11 deletions test/access/roles/WhitelisterRole.test.js

This file was deleted.

0 comments on commit 35d7039

Please sign in to comment.