RBACMintableToken.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import expectThrow from '../../helpers/expectThrow';
  2. import shouldBehaveLikeMintableToken from './MintableToken.behaviour';
  3. const RBACMintableToken = artifacts.require('RBACMintableToken');
  4. const ROLE_MINTER = 'minter';
  5. contract('RBACMintableToken', function ([owner, anotherAccount, minter]) {
  6. beforeEach(async function () {
  7. this.token = await RBACMintableToken.new({ from: owner });
  8. await this.token.addMinter(minter, { from: owner });
  9. });
  10. describe('handle roles', function () {
  11. it('owner can add and remove a minter role', async function () {
  12. await this.token.addMinter(anotherAccount, { from: owner });
  13. let hasRole = await this.token.hasRole(anotherAccount, ROLE_MINTER);
  14. assert.equal(hasRole, true);
  15. await this.token.removeMinter(anotherAccount, { from: owner });
  16. hasRole = await this.token.hasRole(anotherAccount, ROLE_MINTER);
  17. assert.equal(hasRole, false);
  18. });
  19. it('another account can\'t add or remove a minter role', async function () {
  20. await expectThrow(
  21. this.token.addMinter(anotherAccount, { from: anotherAccount })
  22. );
  23. await this.token.addMinter(anotherAccount, { from: owner });
  24. await expectThrow(
  25. this.token.removeMinter(anotherAccount, { from: anotherAccount })
  26. );
  27. });
  28. });
  29. shouldBehaveLikeMintableToken([owner, anotherAccount, minter]);
  30. });