ERC721PresetMinterPauserAutoId.test.js 3.9 KB

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