ERC721PresetMinterPauserAutoId.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 ERC721PresetMinterPauserAutoId = contract.fromArtifact('ERC721PresetMinterPauserAutoId');
  6. describe('ERC721PresetMinterPauserAutoId', function () {
  7. const [ deployer, other ] = accounts;
  8. const name = 'MinterAutoIDToken';
  9. const symbol = 'MAIT';
  10. const baseURI = 'my.app/';
  11. const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000';
  12. const MINTER_ROLE = web3.utils.soliditySha3('MINTER_ROLE');
  13. beforeEach(async function () {
  14. this.token = await ERC721PresetMinterPauserAutoId.new(name, symbol, baseURI, { from: deployer });
  15. });
  16. it('token has correct name', async function () {
  17. expect(await this.token.name()).to.equal(name);
  18. });
  19. it('token has correct symbol', async function () {
  20. expect(await this.token.symbol()).to.equal(symbol);
  21. });
  22. it('token has correct base URI', async function () {
  23. expect(await this.token.baseURI()).to.equal(baseURI);
  24. });
  25. it('deployer has the default admin role', async function () {
  26. expect(await this.token.getRoleMemberCount(DEFAULT_ADMIN_ROLE)).to.be.bignumber.equal('1');
  27. expect(await this.token.getRoleMember(DEFAULT_ADMIN_ROLE, 0)).to.equal(deployer);
  28. });
  29. it('deployer has the minter role', async function () {
  30. expect(await this.token.getRoleMemberCount(MINTER_ROLE)).to.be.bignumber.equal('1');
  31. expect(await this.token.getRoleMember(MINTER_ROLE, 0)).to.equal(deployer);
  32. });
  33. it('minter role admin is the default admin', async function () {
  34. expect(await this.token.getRoleAdmin(MINTER_ROLE)).to.equal(DEFAULT_ADMIN_ROLE);
  35. });
  36. describe('minting', function () {
  37. it('deployer can mint tokens', async function () {
  38. const tokenId = new BN('0');
  39. const receipt = await this.token.mint(other, { from: deployer });
  40. expectEvent(receipt, 'Transfer', { from: ZERO_ADDRESS, to: other, tokenId });
  41. expect(await this.token.balanceOf(other)).to.be.bignumber.equal('1');
  42. expect(await this.token.ownerOf(tokenId)).to.equal(other);
  43. expect(await this.token.tokenURI(tokenId)).to.equal(baseURI + tokenId);
  44. });
  45. it('other accounts cannot mint tokens', async function () {
  46. await expectRevert(
  47. this.token.mint(other, { from: other }),
  48. 'ERC721PresetMinterPauserAutoId: must have minter role to mint'
  49. );
  50. });
  51. });
  52. describe('pausing', function () {
  53. it('deployer can pause', async function () {
  54. const receipt = await this.token.pause({ from: deployer });
  55. expectEvent(receipt, 'Paused', { account: deployer });
  56. expect(await this.token.paused()).to.equal(true);
  57. });
  58. it('deployer can unpause', async function () {
  59. await this.token.pause({ from: deployer });
  60. const receipt = await this.token.unpause({ from: deployer });
  61. expectEvent(receipt, 'Unpaused', { account: deployer });
  62. expect(await this.token.paused()).to.equal(false);
  63. });
  64. it('cannot mint while paused', async function () {
  65. await this.token.pause({ from: deployer });
  66. await expectRevert(
  67. this.token.mint(other, { from: deployer }),
  68. 'ERC721Pausable: token transfer while paused'
  69. );
  70. });
  71. it('other accounts cannot pause', async function () {
  72. await expectRevert(
  73. this.token.pause({ from: other }),
  74. 'ERC721PresetMinterPauserAutoId: must have pauser role to pause'
  75. );
  76. });
  77. });
  78. describe('burning', function () {
  79. it('holders can burn their tokens', async function () {
  80. const tokenId = new BN('0');
  81. await this.token.mint(other, { from: deployer });
  82. const receipt = await this.token.burn(tokenId, { from: other });
  83. expectEvent(receipt, 'Transfer', { from: other, to: ZERO_ADDRESS, tokenId });
  84. expect(await this.token.balanceOf(other)).to.be.bignumber.equal('0');
  85. expect(await this.token.totalSupply()).to.be.bignumber.equal('0');
  86. });
  87. });
  88. });