ERC721MinterPauser.test.js 3.9 KB

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