Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions contracts/access/Whitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import "../access/rbac/RBAC.sol";
* This simplifies the implementation of "user permissions".
*/
contract Whitelist is Ownable, RBAC {
string public constant ROLE_WHITELISTED = "whitelist";

// Name of the whitelisted role.
string private constant ROLE_WHITELISTED = "whitelist";

/**
* @dev Throws if operator is not whitelisted.
Expand All @@ -35,9 +37,10 @@ contract Whitelist is Ownable, RBAC {
}

/**
* @dev getter to determine if address is in whitelist
* @dev Determine if an account is whitelisted.
* @return true if the account is whitelisted, false otherwise.
*/
function whitelist(address _operator)
function isWhitelisted(address _operator)
public
view
returns (bool)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { expectThrow } = require('../helpers/expectThrow');
const expectEvent = require('../helpers/expectEvent');

const WhitelistMock = artifacts.require('WhitelistMock');

Expand All @@ -11,47 +10,30 @@ contract('Whitelist', function ([_, owner, whitelistedAddress1, whitelistedAddre

beforeEach(async function () {
this.mock = await WhitelistMock.new({ from: owner });
this.role = await this.mock.ROLE_WHITELISTED();
});

context('in normal conditions', function () {
it('should add address to the whitelist', async function () {
await expectEvent.inTransaction(
this.mock.addAddressToWhitelist(whitelistedAddress1, { from: owner }),
'RoleAdded',
{ role: this.role },
);
(await this.mock.whitelist(whitelistedAddress1)).should.equal(true);
await this.mock.addAddressToWhitelist(whitelistedAddress1, { from: owner });
(await this.mock.isWhitelisted(whitelistedAddress1)).should.equal(true);
});

it('should add addresses to the whitelist', async function () {
await expectEvent.inTransaction(
this.mock.addAddressesToWhitelist(whitelistedAddresses, { from: owner }),
'RoleAdded',
{ role: this.role },
);
await this.mock.addAddressesToWhitelist(whitelistedAddresses, { from: owner });
for (const addr of whitelistedAddresses) {
(await this.mock.whitelist(addr)).should.equal(true);
(await this.mock.isWhitelisted(addr)).should.equal(true);
}
});

it('should remove address from the whitelist', async function () {
await expectEvent.inTransaction(
this.mock.removeAddressFromWhitelist(whitelistedAddress1, { from: owner }),
'RoleRemoved',
{ role: this.role },
);
(await this.mock.whitelist(whitelistedAddress1)).should.equal(false);
await this.mock.removeAddressFromWhitelist(whitelistedAddress1, { from: owner });
(await this.mock.isWhitelisted(whitelistedAddress1)).should.equal(false);
});

it('should remove addresses from the the whitelist', async function () {
await expectEvent.inTransaction(
this.mock.removeAddressesFromWhitelist(whitelistedAddresses, { from: owner }),
'RoleRemoved',
{ role: this.role },
);
await this.mock.removeAddressesFromWhitelist(whitelistedAddresses, { from: owner });
for (const addr of whitelistedAddresses) {
(await this.mock.whitelist(addr)).should.equal(false);
(await this.mock.isWhitelisted(addr)).should.equal(false);
}
});

Expand Down
10 changes: 5 additions & 5 deletions test/crowdsale/WhitelistedCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized,

describe('reporting whitelisted', function () {
it('should correctly report whitelisted addresses', async function () {
(await this.crowdsale.whitelist(authorized)).should.equal(true);
(await this.crowdsale.whitelist(unauthorized)).should.equal(false);
(await this.crowdsale.isWhitelisted(authorized)).should.equal(true);
(await this.crowdsale.isWhitelisted(unauthorized)).should.equal(false);
});
});
});
Expand Down Expand Up @@ -80,9 +80,9 @@ contract('WhitelistedCrowdsale', function ([_, wallet, authorized, unauthorized,

describe('reporting whitelisted', function () {
it('should correctly report whitelisted addresses', async function () {
(await this.crowdsale.whitelist(authorized)).should.equal(true);
(await this.crowdsale.whitelist(anotherAuthorized)).should.equal(true);
(await this.crowdsale.whitelist(unauthorized)).should.equal(false);
(await this.crowdsale.isWhitelisted(authorized)).should.equal(true);
(await this.crowdsale.isWhitelisted(anotherAuthorized)).should.equal(true);
(await this.crowdsale.isWhitelisted(unauthorized)).should.equal(false);
});
});
});
Expand Down