ERC721Pausable.test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const { ethers } = require('hardhat');
  2. const { expect } = require('chai');
  3. const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
  4. const name = 'Non Fungible Token';
  5. const symbol = 'NFT';
  6. const tokenId = 1n;
  7. const otherTokenId = 2n;
  8. const data = ethers.Typed.bytes('0x42');
  9. async function fixture() {
  10. const [owner, receiver, operator] = await ethers.getSigners();
  11. const token = await ethers.deployContract('$ERC721Pausable', [name, symbol]);
  12. return { owner, receiver, operator, token };
  13. }
  14. describe('ERC721Pausable', function () {
  15. beforeEach(async function () {
  16. Object.assign(this, await loadFixture(fixture));
  17. });
  18. context('when token is paused', function () {
  19. beforeEach(async function () {
  20. await this.token.$_mint(this.owner, tokenId);
  21. await this.token.$_pause();
  22. });
  23. it('reverts when trying to transferFrom', async function () {
  24. await expect(
  25. this.token.connect(this.owner).transferFrom(this.owner, this.receiver, tokenId),
  26. ).to.be.revertedWithCustomError(this.token, 'EnforcedPause');
  27. });
  28. it('reverts when trying to safeTransferFrom', async function () {
  29. await expect(
  30. this.token.connect(this.owner).safeTransferFrom(this.owner, this.receiver, tokenId),
  31. ).to.be.revertedWithCustomError(this.token, 'EnforcedPause');
  32. });
  33. it('reverts when trying to safeTransferFrom with data', async function () {
  34. await expect(
  35. this.token.connect(this.owner).safeTransferFrom(this.owner, this.receiver, tokenId, data),
  36. ).to.be.revertedWithCustomError(this.token, 'EnforcedPause');
  37. });
  38. it('reverts when trying to mint', async function () {
  39. await expect(this.token.$_mint(this.receiver, otherTokenId)).to.be.revertedWithCustomError(
  40. this.token,
  41. 'EnforcedPause',
  42. );
  43. });
  44. it('reverts when trying to burn', async function () {
  45. await expect(this.token.$_burn(tokenId)).to.be.revertedWithCustomError(this.token, 'EnforcedPause');
  46. });
  47. describe('getApproved', function () {
  48. it('returns approved address', async function () {
  49. expect(await this.token.getApproved(tokenId)).to.equal(ethers.ZeroAddress);
  50. });
  51. });
  52. describe('balanceOf', function () {
  53. it('returns the amount of tokens owned by the given address', async function () {
  54. expect(await this.token.balanceOf(this.owner)).to.equal(1n);
  55. });
  56. });
  57. describe('ownerOf', function () {
  58. it('returns the amount of tokens owned by the given address', async function () {
  59. expect(await this.token.ownerOf(tokenId)).to.equal(this.owner.address);
  60. });
  61. });
  62. describe('isApprovedForAll', function () {
  63. it('returns the approval of the operator', async function () {
  64. expect(await this.token.isApprovedForAll(this.owner, this.operator)).to.be.false;
  65. });
  66. });
  67. });
  68. });