ERC721Pausable.test.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const { BN, constants } = require('@openzeppelin/test-helpers');
  2. const { expect } = require('chai');
  3. const { expectRevertCustomError } = require('../../../helpers/customError');
  4. const ERC721Pausable = artifacts.require('$ERC721Pausable');
  5. contract('ERC721Pausable', function (accounts) {
  6. const [owner, receiver, operator] = accounts;
  7. const name = 'Non Fungible Token';
  8. const symbol = 'NFT';
  9. beforeEach(async function () {
  10. this.token = await ERC721Pausable.new(name, symbol);
  11. });
  12. context('when token is paused', function () {
  13. const firstTokenId = new BN(1);
  14. const secondTokenId = new BN(1337);
  15. const mockData = '0x42';
  16. beforeEach(async function () {
  17. await this.token.$_mint(owner, firstTokenId, { from: owner });
  18. await this.token.$_pause();
  19. });
  20. it('reverts when trying to transferFrom', async function () {
  21. await expectRevertCustomError(
  22. this.token.transferFrom(owner, receiver, firstTokenId, { from: owner }),
  23. 'EnforcedPause',
  24. [],
  25. );
  26. });
  27. it('reverts when trying to safeTransferFrom', async function () {
  28. await expectRevertCustomError(
  29. this.token.safeTransferFrom(owner, receiver, firstTokenId, { from: owner }),
  30. 'EnforcedPause',
  31. [],
  32. );
  33. });
  34. it('reverts when trying to safeTransferFrom with data', async function () {
  35. await expectRevertCustomError(
  36. this.token.methods['safeTransferFrom(address,address,uint256,bytes)'](owner, receiver, firstTokenId, mockData, {
  37. from: owner,
  38. }),
  39. 'EnforcedPause',
  40. [],
  41. );
  42. });
  43. it('reverts when trying to mint', async function () {
  44. await expectRevertCustomError(this.token.$_mint(receiver, secondTokenId), 'EnforcedPause', []);
  45. });
  46. it('reverts when trying to burn', async function () {
  47. await expectRevertCustomError(this.token.$_burn(firstTokenId), 'EnforcedPause', []);
  48. });
  49. describe('getApproved', function () {
  50. it('returns approved address', async function () {
  51. const approvedAccount = await this.token.getApproved(firstTokenId);
  52. expect(approvedAccount).to.equal(constants.ZERO_ADDRESS);
  53. });
  54. });
  55. describe('balanceOf', function () {
  56. it('returns the amount of tokens owned by the given address', async function () {
  57. const balance = await this.token.balanceOf(owner);
  58. expect(balance).to.be.bignumber.equal('1');
  59. });
  60. });
  61. describe('ownerOf', function () {
  62. it('returns the amount of tokens owned by the given address', async function () {
  63. const ownerOfToken = await this.token.ownerOf(firstTokenId);
  64. expect(ownerOfToken).to.equal(owner);
  65. });
  66. });
  67. describe('isApprovedForAll', function () {
  68. it('returns the approval of the operator', async function () {
  69. expect(await this.token.isApprovedForAll(owner, operator)).to.equal(false);
  70. });
  71. });
  72. });
  73. });