Skip to content

Commit

Permalink
Merge pull request #29 from ConsenSys/feature/set_whitelisted
Browse files Browse the repository at this point in the history
feat(setWhitelisted): Update access rights to setWhitelisted function
  • Loading branch information
gauthierpetetin authored Jul 14, 2019
2 parents 34991ae + e21501e commit b1e43c7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
3 changes: 2 additions & 1 deletion contracts/token/ERC20/ERC1400ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ contract ERC1400ERC20 is IERC20, ERC1400 {
* @param tokenHolder Address to add/remove from whitelist.
* @param authorized 'true' if tokenHolder shall be added to whitelist, 'false' if not.
*/
function setWhitelisted(address tokenHolder, bool authorized) external onlyOwner {
function setWhitelisted(address tokenHolder, bool authorized) external {
require(_isController[msg.sender]);
_setWhitelisted(tokenHolder, authorized);
}

Expand Down
3 changes: 2 additions & 1 deletion contracts/token/ERC20/ERC1400RawERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ contract ERC1400RawERC20 is IERC20, ERC1400RawIssuable {
* @param tokenHolder Address to add/remove from whitelist.
* @param authorized 'true' if tokenHolder shall be added to whitelist, 'false' if not.
*/
function setWhitelisted(address tokenHolder, bool authorized) external onlyOwner {
function setWhitelisted(address tokenHolder, bool authorized) external {
require(_isController[msg.sender]);
_setWhitelisted(tokenHolder, authorized);
}

Expand Down
26 changes: 13 additions & 13 deletions test/ERC1400ERC20.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ contract('ERC1400ERC20', function ([owner, operator, controller, tokenHolder, re
// SETWHITELISTED

describe('setWhitelisted', function () {
describe('when sender is the contract owner', function () {
describe('when sender is a controller', function () {
describe('when targeted address is not the zero address', function () {
it('adds/removes the address from whitelist', async function () {
assert(!(await this.token.whitelisted(tokenHolder)));
await this.token.setWhitelisted(tokenHolder, true, { from: owner });
await this.token.setWhitelisted(tokenHolder, true, { from: controller });
assert(await this.token.whitelisted(tokenHolder));
await this.token.setWhitelisted(tokenHolder, false, { from: owner });
await this.token.setWhitelisted(tokenHolder, false, { from: controller });
assert(!(await this.token.whitelisted(tokenHolder)));
});
});
describe('when targeted address is the zero address', function () {
it('reverts', async function () {
await shouldFail.reverting(this.token.setWhitelisted(ZERO_ADDRESS, true, { from: owner }));
await shouldFail.reverting(this.token.setWhitelisted(ZERO_ADDRESS, true, { from: controller }));
});
});
});
describe('when sender is not the contract owner', function () {
describe('when sender is not a controller', function () {
it('reverts', async function () {
await shouldFail.reverting(this.token.setWhitelisted(tokenHolder, true, { from: unknown }));
});
Expand Down Expand Up @@ -259,8 +259,8 @@ contract('ERC1400ERC20', function ([owner, operator, controller, tokenHolder, re
describe('transfer', function () {
const to = recipient;
beforeEach(async function () {
await this.token.setWhitelisted(tokenHolder, true, { from: owner });
await this.token.setWhitelisted(to, true, { from: owner });
await this.token.setWhitelisted(tokenHolder, true, { from: controller });
await this.token.setWhitelisted(to, true, { from: controller });
await this.token.issueByPartition(partition1, tokenHolder, issuanceAmount, VALID_CERTIFICATE, { from: owner });
});

Expand Down Expand Up @@ -338,15 +338,15 @@ contract('ERC1400ERC20', function ([owner, operator, controller, tokenHolder, re
const amount = issuanceAmount;

it('reverts', async function () {
await this.token.setWhitelisted(tokenHolder, false, { from: owner });
await this.token.setWhitelisted(tokenHolder, false, { from: controller });
await shouldFail.reverting(this.token.transfer(to, amount, { from: tokenHolder }));
});
});
describe('when the recipient is not whitelisted', function () {
const amount = issuanceAmount;

it('reverts', async function () {
await this.token.setWhitelisted(to, false, { from: owner });
await this.token.setWhitelisted(to, false, { from: controller });
await shouldFail.reverting(this.token.transfer(to, amount, { from: tokenHolder }));
});
});
Expand All @@ -358,8 +358,8 @@ contract('ERC1400ERC20', function ([owner, operator, controller, tokenHolder, re
const to = recipient;
const approvedAmount = 10000;
beforeEach(async function () {
await this.token.setWhitelisted(tokenHolder, true, { from: owner });
await this.token.setWhitelisted(to, true, { from: owner });
await this.token.setWhitelisted(tokenHolder, true, { from: controller });
await this.token.setWhitelisted(to, true, { from: controller });
await this.token.issueByPartition(partition1, tokenHolder, issuanceAmount, VALID_CERTIFICATE, { from: owner });
});

Expand Down Expand Up @@ -465,14 +465,14 @@ contract('ERC1400ERC20', function ([owner, operator, controller, tokenHolder, re
describe('when the sender is not whitelisted', function () {
const amount = approvedAmount;
it('reverts', async function () {
await this.token.setWhitelisted(tokenHolder, false, { from: owner });
await this.token.setWhitelisted(tokenHolder, false, { from: controller });
await shouldFail.reverting(this.token.transferFrom(tokenHolder, to, amount, { from: operator }));
});
});
describe('when the recipient is not whitelisted', function () {
const amount = approvedAmount;
it('reverts', async function () {
await this.token.setWhitelisted(to, false, { from: owner });
await this.token.setWhitelisted(to, false, { from: controller });
await shouldFail.reverting(this.token.transferFrom(tokenHolder, to, amount, { from: operator }));
});
});
Expand Down
24 changes: 12 additions & 12 deletions test/ERC1400RawERC20.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ contract('ERC1400RawERC20', function ([owner, operator, controller, tokenHolder,
// SETWHITELISTED

describe('setWhitelisted', function () {
describe('when sender is the contract owner', function () {
describe('when sender is a controller', function () {
describe('when targeted address is not the zero address', function () {
it('adds/removes the address from whitelist', async function () {
assert(!(await this.token.whitelisted(tokenHolder)));
await this.token.setWhitelisted(tokenHolder, true, { from: owner });
await this.token.setWhitelisted(tokenHolder, true, { from: controller });
assert(await this.token.whitelisted(tokenHolder));
await this.token.setWhitelisted(tokenHolder, false, { from: owner });
await this.token.setWhitelisted(tokenHolder, false, { from: controller });
assert(!(await this.token.whitelisted(tokenHolder)));
});
});
describe('when targeted address is the zero address', function () {
it('reverts', async function () {
await shouldFail.reverting(this.token.setWhitelisted(ZERO_ADDRESS, true, { from: owner }));
await shouldFail.reverting(this.token.setWhitelisted(ZERO_ADDRESS, true, { from: controller }));
});
});
});
describe('when sender is not the contract owner', function () {
describe('when sender is not a controller', function () {
it('reverts', async function () {
await shouldFail.reverting(this.token.setWhitelisted(tokenHolder, true, { from: unknown }));
});
Expand Down Expand Up @@ -213,8 +213,8 @@ contract('ERC1400RawERC20', function ([owner, operator, controller, tokenHolder,
const to = recipient;
beforeEach(async function () {
await this.token.issue(tokenHolder, initialSupply, VALID_CERTIFICATE, { from: owner });
await this.token.setWhitelisted(tokenHolder, true, { from: owner });
await this.token.setWhitelisted(to, true, { from: owner });
await this.token.setWhitelisted(tokenHolder, true, { from: controller });
await this.token.setWhitelisted(to, true, { from: controller });
});

describe('when the sender and the recipient are whitelisted', function () {
Expand Down Expand Up @@ -281,15 +281,15 @@ contract('ERC1400RawERC20', function ([owner, operator, controller, tokenHolder,
const amount = initialSupply;

it('reverts', async function () {
await this.token.setWhitelisted(tokenHolder, false, { from: owner });
await this.token.setWhitelisted(tokenHolder, false, { from: controller });
await shouldFail.reverting(this.token.transfer(to, amount, { from: tokenHolder }));
});
});
describe('when the recipient is not whitelisted', function () {
const amount = initialSupply;

it('reverts', async function () {
await this.token.setWhitelisted(to, false, { from: owner });
await this.token.setWhitelisted(to, false, { from: controller });
await shouldFail.reverting(this.token.transfer(to, amount, { from: tokenHolder }));
});
});
Expand All @@ -302,8 +302,8 @@ contract('ERC1400RawERC20', function ([owner, operator, controller, tokenHolder,
const approvedAmount = 10000;
beforeEach(async function () {
await this.token.issue(tokenHolder, initialSupply, VALID_CERTIFICATE, { from: owner });
await this.token.setWhitelisted(tokenHolder, true, { from: owner });
await this.token.setWhitelisted(to, true, { from: owner });
await this.token.setWhitelisted(tokenHolder, true, { from: controller });
await this.token.setWhitelisted(to, true, { from: controller });
});

describe('when the recipient is whitelisted', function () {
Expand Down Expand Up @@ -398,7 +398,7 @@ contract('ERC1400RawERC20', function ([owner, operator, controller, tokenHolder,
describe('when the recipient is not whitelisted', function () {
const amount = approvedAmount;
it('reverts', async function () {
await this.token.setWhitelisted(to, false, { from: owner });
await this.token.setWhitelisted(to, false, { from: controller });
await shouldFail.reverting(this.token.transferFrom(tokenHolder, to, amount, { from: operator }));
});
});
Expand Down

0 comments on commit b1e43c7

Please sign in to comment.