Files
openzeppelin-contracts/test/access/Whitelist.test.js
Leo Arias f4eb51a7e9 Improve encapsulation on SignatureBouncer, Whitelist and RBAC example (#1265)
* Improve encapsulation on Whitelist

* remove only

* update whitelisted crowdsale test

* Improve encapsulation on SignatureBouncer

* fix missing test

* Improve encapsulation on RBAC example

* Improve encapsulation on RBAC example

* Remove extra visibility

* Improve encapsulation on ERC20 Mintable

* Improve encapsulation on Superuser

* fix lint

* add missing constant
2018-09-03 19:06:43 -03:00

66 lines
2.4 KiB
JavaScript

const { expectThrow } = require('../helpers/expectThrow');
const WhitelistMock = artifacts.require('WhitelistMock');
require('chai')
.should();
contract('Whitelist', function ([_, owner, whitelistedAddress1, whitelistedAddress2, anyone]) {
const whitelistedAddresses = [whitelistedAddress1, whitelistedAddress2];
beforeEach(async function () {
this.mock = await WhitelistMock.new({ from: owner });
});
context('in normal conditions', function () {
it('should add address to the whitelist', async function () {
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 this.mock.addAddressesToWhitelist(whitelistedAddresses, { from: owner });
for (const addr of whitelistedAddresses) {
(await this.mock.isWhitelisted(addr)).should.equal(true);
}
});
it('should remove address from the whitelist', async function () {
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 this.mock.removeAddressesFromWhitelist(whitelistedAddresses, { from: owner });
for (const addr of whitelistedAddresses) {
(await this.mock.isWhitelisted(addr)).should.equal(false);
}
});
it('should allow whitelisted address to call #onlyWhitelistedCanDoThis', async function () {
await this.mock.addAddressToWhitelist(whitelistedAddress1, { from: owner });
await this.mock.onlyWhitelistedCanDoThis({ from: whitelistedAddress1 });
});
});
context('in adversarial conditions', function () {
it('should not allow "anyone" to add to the whitelist', async function () {
await expectThrow(
this.mock.addAddressToWhitelist(whitelistedAddress1, { from: anyone })
);
});
it('should not allow "anyone" to remove from the whitelist', async function () {
await expectThrow(
this.mock.removeAddressFromWhitelist(whitelistedAddress1, { from: anyone })
);
});
it('should not allow "anyone" to call #onlyWhitelistedCanDoThis', async function () {
await expectThrow(
this.mock.onlyWhitelistedCanDoThis({ from: anyone })
);
});
});
});