Roles.test.js 2.0 KB

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