Files
openzeppelin-contracts/test/access/Roles.test.js
Balaji Pachai 3682c6575c Added message string for require() (#1704)
* Error handling in ERC20 and ERC721

* Added message string for require.

* Fixed solhint errors.

* Updated PR as per issue #1709

* changes as per #1709 and openzeppelin forum.

* Changes in require statement

* Changes in require statement

* build pipeline fix

* Changes as per @nventuro's comment.

* Update revert reason strings.

* Fianal update of revert reason strings.

* WIP: Updating reason strings in test cases

* WIP: Added changes to ERC20 and ERC721

* Fixes linting errors in *.tes.js files

* Achieved 100% code coverage

* Updated the test cases with shouldFail.reverting.withMessage()

* Fix package-lock.

* address review comments

* fix linter issues

* fix remaining revert reasons
2019-04-24 11:17:08 -03:00

63 lines
2.4 KiB
JavaScript

const { shouldFail, constants } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const RolesMock = artifacts.require('RolesMock');
contract('Roles', function ([_, authorized, otherAuthorized, other]) {
beforeEach(async function () {
this.roles = await RolesMock.new();
});
it('reverts when querying roles for the zero account', async function () {
await shouldFail.reverting.withMessage(this.roles.has(ZERO_ADDRESS), 'Roles: account is the zero address');
});
context('initially', function () {
it('doesn\'t pre-assign roles', async function () {
(await this.roles.has(authorized)).should.equal(false);
(await this.roles.has(otherAuthorized)).should.equal(false);
(await this.roles.has(other)).should.equal(false);
});
describe('adding roles', function () {
it('adds roles to a single account', async function () {
await this.roles.add(authorized);
(await this.roles.has(authorized)).should.equal(true);
(await this.roles.has(other)).should.equal(false);
});
it('reverts when adding roles to an already assigned account', async function () {
await this.roles.add(authorized);
await shouldFail.reverting.withMessage(this.roles.add(authorized), 'Roles: account already has role');
});
it('reverts when adding roles to the zero account', async function () {
await shouldFail.reverting.withMessage(this.roles.add(ZERO_ADDRESS), 'Roles: account is the zero address');
});
});
});
context('with added roles', function () {
beforeEach(async function () {
await this.roles.add(authorized);
await this.roles.add(otherAuthorized);
});
describe('removing roles', function () {
it('removes a single role', async function () {
await this.roles.remove(authorized);
(await this.roles.has(authorized)).should.equal(false);
(await this.roles.has(otherAuthorized)).should.equal(true);
});
it('reverts when removing unassigned roles', async function () {
await shouldFail.reverting.withMessage(this.roles.remove(other), 'Roles: account does not have role');
});
it('reverts when removing roles from the zero account', async function () {
await shouldFail.reverting.withMessage(this.roles.remove(ZERO_ADDRESS), 'Roles: account is the zero address');
});
});
});
});