ERC721PresetMinterPauserAutoId.test.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
  2. const { ZERO_ADDRESS } = constants;
  3. const { shouldSupportInterfaces } = require('../../../utils/introspection/SupportsInterface.behavior');
  4. const { expect } = require('chai');
  5. const ERC721PresetMinterPauserAutoId = artifacts.require('ERC721PresetMinterPauserAutoId');
  6. contract('ERC721PresetMinterPauserAutoId', function (accounts) {
  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. shouldSupportInterfaces(['ERC721', 'ERC721Enumerable', 'AccessControl', 'AccessControlEnumerable']);
  17. it('token has correct name', async function () {
  18. expect(await this.token.name()).to.equal(name);
  19. });
  20. it('token has correct symbol', async function () {
  21. expect(await this.token.symbol()).to.equal(symbol);
  22. });
  23. it('deployer has the default admin role', async function () {
  24. expect(await this.token.getRoleMemberCount(DEFAULT_ADMIN_ROLE)).to.be.bignumber.equal('1');
  25. expect(await this.token.getRoleMember(DEFAULT_ADMIN_ROLE, 0)).to.equal(deployer);
  26. });
  27. it('deployer has the minter role', async function () {
  28. expect(await this.token.getRoleMemberCount(MINTER_ROLE)).to.be.bignumber.equal('1');
  29. expect(await this.token.getRoleMember(MINTER_ROLE, 0)).to.equal(deployer);
  30. });
  31. it('minter role admin is the default admin', async function () {
  32. expect(await this.token.getRoleAdmin(MINTER_ROLE)).to.equal(DEFAULT_ADMIN_ROLE);
  33. });
  34. describe('minting', function () {
  35. it('deployer can mint tokens', async function () {
  36. const tokenId = new BN('0');
  37. const receipt = await this.token.mint(other, { from: deployer });
  38. expectEvent(receipt, 'Transfer', { from: ZERO_ADDRESS, to: other, tokenId });
  39. expect(await this.token.balanceOf(other)).to.be.bignumber.equal('1');
  40. expect(await this.token.ownerOf(tokenId)).to.equal(other);
  41. expect(await this.token.tokenURI(tokenId)).to.equal(baseURI + tokenId);
  42. });
  43. it('other accounts cannot mint tokens', async function () {
  44. await expectRevert(
  45. this.token.mint(other, { from: other }),
  46. 'ERC721PresetMinterPauserAutoId: must have minter role to mint',
  47. );
  48. });
  49. });
  50. describe('pausing', function () {
  51. it('deployer can pause', async function () {
  52. const receipt = await this.token.pause({ from: deployer });
  53. expectEvent(receipt, 'Paused', { account: deployer });
  54. expect(await this.token.paused()).to.equal(true);
  55. });
  56. it('deployer can unpause', async function () {
  57. await this.token.pause({ from: deployer });
  58. const receipt = await this.token.unpause({ from: deployer });
  59. expectEvent(receipt, 'Unpaused', { account: deployer });
  60. expect(await this.token.paused()).to.equal(false);
  61. });
  62. it('cannot mint while paused', async function () {
  63. await this.token.pause({ from: deployer });
  64. await expectRevert(
  65. this.token.mint(other, { from: deployer }),
  66. 'ERC721Pausable: token transfer while paused',
  67. );
  68. });
  69. it('other accounts cannot pause', async function () {
  70. await expectRevert(
  71. this.token.pause({ from: other }),
  72. 'ERC721PresetMinterPauserAutoId: must have pauser role to pause',
  73. );
  74. });
  75. it('other accounts cannot unpause', async function () {
  76. await this.token.pause({ from: deployer });
  77. await expectRevert(
  78. this.token.unpause({ from: other }),
  79. 'ERC721PresetMinterPauserAutoId: must have pauser role to unpause',
  80. );
  81. });
  82. });
  83. describe('burning', function () {
  84. it('holders can burn their tokens', async function () {
  85. const tokenId = new BN('0');
  86. await this.token.mint(other, { from: deployer });
  87. const receipt = await this.token.burn(tokenId, { from: other });
  88. expectEvent(receipt, 'Transfer', { from: other, to: ZERO_ADDRESS, tokenId });
  89. expect(await this.token.balanceOf(other)).to.be.bignumber.equal('0');
  90. expect(await this.token.totalSupply()).to.be.bignumber.equal('0');
  91. });
  92. });
  93. });