ERC1155Pausable.test.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. const { ethers } = require('hardhat');
  2. const { expect } = require('chai');
  3. const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
  4. async function fixture() {
  5. const [holder, operator, receiver, other] = await ethers.getSigners();
  6. const token = await ethers.deployContract('$ERC1155Pausable', ['https://token-cdn-domain/{id}.json']);
  7. return { token, holder, operator, receiver, other };
  8. }
  9. describe('ERC1155Pausable', function () {
  10. const firstTokenId = 37n;
  11. const firstTokenValue = 42n;
  12. const secondTokenId = 19842n;
  13. const secondTokenValue = 23n;
  14. beforeEach(async function () {
  15. Object.assign(this, await loadFixture(fixture));
  16. });
  17. context('when token is paused', function () {
  18. beforeEach(async function () {
  19. await this.token.connect(this.holder).setApprovalForAll(this.operator, true);
  20. await this.token.$_mint(this.holder, firstTokenId, firstTokenValue, '0x');
  21. await this.token.$_pause();
  22. });
  23. it('reverts when trying to safeTransferFrom from holder', async function () {
  24. await expect(
  25. this.token
  26. .connect(this.holder)
  27. .safeTransferFrom(this.holder, this.receiver, firstTokenId, firstTokenValue, '0x'),
  28. ).to.be.revertedWithCustomError(this.token, 'EnforcedPause');
  29. });
  30. it('reverts when trying to safeTransferFrom from operator', async function () {
  31. await expect(
  32. this.token
  33. .connect(this.operator)
  34. .safeTransferFrom(this.holder, this.receiver, firstTokenId, firstTokenValue, '0x'),
  35. ).to.be.revertedWithCustomError(this.token, 'EnforcedPause');
  36. });
  37. it('reverts when trying to safeBatchTransferFrom from holder', async function () {
  38. await expect(
  39. this.token
  40. .connect(this.holder)
  41. .safeBatchTransferFrom(this.holder, this.receiver, [firstTokenId], [firstTokenValue], '0x'),
  42. ).to.be.revertedWithCustomError(this.token, 'EnforcedPause');
  43. });
  44. it('reverts when trying to safeBatchTransferFrom from operator', async function () {
  45. await expect(
  46. this.token
  47. .connect(this.operator)
  48. .safeBatchTransferFrom(this.holder, this.receiver, [firstTokenId], [firstTokenValue], '0x'),
  49. ).to.be.revertedWithCustomError(this.token, 'EnforcedPause');
  50. });
  51. it('reverts when trying to mint', async function () {
  52. await expect(this.token.$_mint(this.holder, secondTokenId, secondTokenValue, '0x')).to.be.revertedWithCustomError(
  53. this.token,
  54. 'EnforcedPause',
  55. );
  56. });
  57. it('reverts when trying to mintBatch', async function () {
  58. await expect(
  59. this.token.$_mintBatch(this.holder, [secondTokenId], [secondTokenValue], '0x'),
  60. ).to.be.revertedWithCustomError(this.token, 'EnforcedPause');
  61. });
  62. it('reverts when trying to burn', async function () {
  63. await expect(this.token.$_burn(this.holder, firstTokenId, firstTokenValue)).to.be.revertedWithCustomError(
  64. this.token,
  65. 'EnforcedPause',
  66. );
  67. });
  68. it('reverts when trying to burnBatch', async function () {
  69. await expect(
  70. this.token.$_burnBatch(this.holder, [firstTokenId], [firstTokenValue]),
  71. ).to.be.revertedWithCustomError(this.token, 'EnforcedPause');
  72. });
  73. describe('setApprovalForAll', function () {
  74. it('approves an operator', async function () {
  75. await this.token.connect(this.holder).setApprovalForAll(this.other, true);
  76. expect(await this.token.isApprovedForAll(this.holder, this.other)).to.be.true;
  77. });
  78. });
  79. describe('balanceOf', function () {
  80. it('returns the token value owned by the given address', async function () {
  81. expect(await this.token.balanceOf(this.holder, firstTokenId)).to.equal(firstTokenValue);
  82. });
  83. });
  84. describe('isApprovedForAll', function () {
  85. it('returns the approval of the operator', async function () {
  86. expect(await this.token.isApprovedForAll(this.holder, this.operator)).to.be.true;
  87. });
  88. });
  89. });
  90. });