Roles.test.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const shouldFail = require('../helpers/shouldFail');
  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 shouldFail.reverting(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('reverts when adding roles to an already assigned account', async function () {
  26. await this.roles.add(authorized);
  27. await shouldFail.reverting(this.roles.add(authorized));
  28. });
  29. it('reverts when adding roles to the null account', async function () {
  30. await shouldFail.reverting(this.roles.add(ZERO_ADDRESS));
  31. });
  32. });
  33. });
  34. context('with added roles', function () {
  35. beforeEach(async function () {
  36. await this.roles.add(authorized);
  37. await this.roles.add(otherAuthorized);
  38. });
  39. describe('removing roles', function () {
  40. it('removes a single role', async function () {
  41. await this.roles.remove(authorized);
  42. (await this.roles.has(authorized)).should.equal(false);
  43. (await this.roles.has(otherAuthorized)).should.equal(true);
  44. });
  45. it('reverts when removing unassigned roles', async function () {
  46. await shouldFail.reverting(this.roles.remove(anyone));
  47. });
  48. it('reverts when removing roles from the null account', async function () {
  49. await shouldFail.reverting(this.roles.remove(ZERO_ADDRESS));
  50. });
  51. });
  52. });
  53. });