Roles.test.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const { assertRevert } = require('../helpers/assertRevert');
  2. const { ZERO_ADDRESS } = require('../helpers/constants');
  3. const RolesMock = artifacts.require('RolesMock');
  4. require('chai')
  5. .should();
  6. contract('Roles', function ([_, authorized, otherAuthorized, anyone]) {
  7. beforeEach(async function () {
  8. this.roles = await RolesMock.new();
  9. });
  10. it('reverts when querying roles for the null account', async function () {
  11. await assertRevert(this.roles.has(ZERO_ADDRESS));
  12. });
  13. context('initially', function () {
  14. it('doesn\'t pre-assign roles', async function () {
  15. (await this.roles.has(authorized)).should.equal(false);
  16. (await this.roles.has(otherAuthorized)).should.equal(false);
  17. (await this.roles.has(anyone)).should.equal(false);
  18. });
  19. describe('adding roles', function () {
  20. it('adds roles to a single account', async function () {
  21. await this.roles.add(authorized);
  22. (await this.roles.has(authorized)).should.equal(true);
  23. (await this.roles.has(anyone)).should.equal(false);
  24. });
  25. it('adds roles to an already-assigned account', async function () {
  26. await this.roles.add(authorized);
  27. await this.roles.add(authorized);
  28. (await this.roles.has(authorized)).should.equal(true);
  29. });
  30. it('reverts when adding roles to the null account', async function () {
  31. await assertRevert(this.roles.add(ZERO_ADDRESS));
  32. });
  33. });
  34. });
  35. context('with added roles', function () {
  36. beforeEach(async function () {
  37. await this.roles.add(authorized);
  38. await this.roles.add(otherAuthorized);
  39. });
  40. describe('removing roles', function () {
  41. it('removes a single role', async function () {
  42. await this.roles.remove(authorized);
  43. (await this.roles.has(authorized)).should.equal(false);
  44. (await this.roles.has(otherAuthorized)).should.equal(true);
  45. });
  46. it('doesn\'t revert when removing unassigned roles', async function () {
  47. await this.roles.remove(anyone);
  48. });
  49. it('reverts when removing roles from the null account', async function () {
  50. await assertRevert(this.roles.remove(ZERO_ADDRESS));
  51. });
  52. });
  53. });
  54. });