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
This commit is contained in:
Leo Arias
2018-09-03 16:06:43 -06:00
committed by Francisco Giordano
parent b0f20d43df
commit f4eb51a7e9
11 changed files with 58 additions and 53 deletions

View File

@ -16,7 +16,6 @@ const INVALID_SIGNATURE = '0xabcd';
contract('Bouncer', function ([_, owner, anyone, bouncerAddress, authorizedUser]) {
beforeEach(async function () {
this.bouncer = await Bouncer.new({ from: owner });
this.roleBouncer = await this.bouncer.ROLE_BOUNCER();
});
context('management', function () {
@ -26,7 +25,7 @@ contract('Bouncer', function ([_, owner, anyone, bouncerAddress, authorizedUser]
it('allows the owner to add a bouncer', async function () {
await this.bouncer.addBouncer(bouncerAddress, { from: owner });
(await this.bouncer.hasRole(bouncerAddress, this.roleBouncer)).should.equal(true);
(await this.bouncer.isBouncer(bouncerAddress)).should.equal(true);
});
it('does not allow adding an invalid address', async function () {
@ -39,7 +38,7 @@ contract('Bouncer', function ([_, owner, anyone, bouncerAddress, authorizedUser]
await this.bouncer.addBouncer(bouncerAddress, { from: owner });
await this.bouncer.removeBouncer(bouncerAddress, { from: owner });
(await this.bouncer.hasRole(bouncerAddress, this.roleBouncer)).should.equal(false);
(await this.bouncer.isBouncer(bouncerAddress)).should.equal(false);
});
it('does not allow anyone to add a bouncer', async function () {

View File

@ -1,5 +1,4 @@
const { expectThrow } = require('../helpers/expectThrow');
const expectEvent = require('../helpers/expectEvent');
const WhitelistMock = artifacts.require('WhitelistMock');
@ -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);
}
});

View File

@ -28,8 +28,6 @@ contract('MintedCrowdsale', function ([_, investor, wallet, purchaser]) {
});
describe('using RBACMintableToken', function () {
const ROLE_MINTER = 'minter';
beforeEach(async function () {
this.token = await RBACMintableToken.new();
this.crowdsale = await MintedCrowdsale.new(rate, wallet, this.token.address);
@ -37,7 +35,7 @@ contract('MintedCrowdsale', function ([_, investor, wallet, purchaser]) {
});
it('should have minter role on token', async function () {
(await this.token.hasRole(this.crowdsale.address, ROLE_MINTER)).should.equal(true);
(await this.token.isMinter(this.crowdsale.address)).should.equal(true);
});
shouldBehaveLikeMintedCrowdsale([_, investor, wallet, purchaser], rate, value);

View File

@ -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);
});
});
});
@ -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);
});
});
});

View File

@ -1,15 +1,13 @@
const { expectThrow } = require('../../helpers/expectThrow');
const ROLE_MINTER = 'minter';
function shouldBehaveLikeRBACMintableToken (owner, [anyone]) {
describe('handle roles', function () {
it('owner can add and remove a minter role', async function () {
await this.token.addMinter(anyone, { from: owner });
(await this.token.hasRole(anyone, ROLE_MINTER)).should.equal(true);
(await this.token.isMinter(anyone)).should.equal(true);
await this.token.removeMinter(anyone, { from: owner });
(await this.token.hasRole(anyone, ROLE_MINTER)).should.equal(false);
(await this.token.isMinter(anyone)).should.equal(false);
});
it('anyone can\'t add or remove a minter role', async function () {