ERC20PresetMinterPauser.test.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
  2. const { ZERO_ADDRESS } = constants;
  3. const { expect } = require('chai');
  4. const ERC20PresetMinterPauser = artifacts.require('ERC20PresetMinterPauser');
  5. contract('ERC20PresetMinterPauser', function (accounts) {
  6. const [ deployer, other ] = accounts;
  7. const name = 'MinterPauserToken';
  8. const symbol = 'DRT';
  9. const amount = new BN('5000');
  10. const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000';
  11. const MINTER_ROLE = web3.utils.soliditySha3('MINTER_ROLE');
  12. const PAUSER_ROLE = web3.utils.soliditySha3('PAUSER_ROLE');
  13. beforeEach(async function () {
  14. this.token = await ERC20PresetMinterPauser.new(name, symbol, { from: deployer });
  15. });
  16. it('deployer has the default admin role', async function () {
  17. expect(await this.token.getRoleMemberCount(DEFAULT_ADMIN_ROLE)).to.be.bignumber.equal('1');
  18. expect(await this.token.getRoleMember(DEFAULT_ADMIN_ROLE, 0)).to.equal(deployer);
  19. });
  20. it('deployer has the minter role', async function () {
  21. expect(await this.token.getRoleMemberCount(MINTER_ROLE)).to.be.bignumber.equal('1');
  22. expect(await this.token.getRoleMember(MINTER_ROLE, 0)).to.equal(deployer);
  23. });
  24. it('deployer has the pauser role', async function () {
  25. expect(await this.token.getRoleMemberCount(PAUSER_ROLE)).to.be.bignumber.equal('1');
  26. expect(await this.token.getRoleMember(PAUSER_ROLE, 0)).to.equal(deployer);
  27. });
  28. it('minter and pauser role admin is the default admin', async function () {
  29. expect(await this.token.getRoleAdmin(MINTER_ROLE)).to.equal(DEFAULT_ADMIN_ROLE);
  30. expect(await this.token.getRoleAdmin(PAUSER_ROLE)).to.equal(DEFAULT_ADMIN_ROLE);
  31. });
  32. describe('minting', function () {
  33. it('deployer can mint tokens', async function () {
  34. const receipt = await this.token.mint(other, amount, { from: deployer });
  35. expectEvent(receipt, 'Transfer', { from: ZERO_ADDRESS, to: other, value: amount });
  36. expect(await this.token.balanceOf(other)).to.be.bignumber.equal(amount);
  37. });
  38. it('other accounts cannot mint tokens', async function () {
  39. await expectRevert(
  40. this.token.mint(other, amount, { from: other }),
  41. 'ERC20PresetMinterPauser: must have minter role to mint',
  42. );
  43. });
  44. });
  45. describe('pausing', function () {
  46. it('deployer can pause', async function () {
  47. const receipt = await this.token.pause({ from: deployer });
  48. expectEvent(receipt, 'Paused', { account: deployer });
  49. expect(await this.token.paused()).to.equal(true);
  50. });
  51. it('deployer can unpause', async function () {
  52. await this.token.pause({ from: deployer });
  53. const receipt = await this.token.unpause({ from: deployer });
  54. expectEvent(receipt, 'Unpaused', { account: deployer });
  55. expect(await this.token.paused()).to.equal(false);
  56. });
  57. it('cannot mint while paused', async function () {
  58. await this.token.pause({ from: deployer });
  59. await expectRevert(
  60. this.token.mint(other, amount, { from: deployer }),
  61. 'ERC20Pausable: token transfer while paused',
  62. );
  63. });
  64. it('other accounts cannot pause', async function () {
  65. await expectRevert(this.token.pause({ from: other }), 'ERC20PresetMinterPauser: must have pauser role to pause');
  66. });
  67. });
  68. describe('burning', function () {
  69. it('holders can burn their tokens', async function () {
  70. await this.token.mint(other, amount, { from: deployer });
  71. const receipt = await this.token.burn(amount.subn(1), { from: other });
  72. expectEvent(receipt, 'Transfer', { from: other, to: ZERO_ADDRESS, value: amount.subn(1) });
  73. expect(await this.token.balanceOf(other)).to.be.bignumber.equal('1');
  74. });
  75. });
  76. });