ERC1155Pausable.test.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. const { BN } = require('@openzeppelin/test-helpers');
  2. const { expect } = require('chai');
  3. const { expectRevertCustomError } = require('../../../helpers/customError');
  4. const ERC1155Pausable = artifacts.require('$ERC1155Pausable');
  5. contract('ERC1155Pausable', function (accounts) {
  6. const [holder, operator, receiver, other] = accounts;
  7. const uri = 'https://token.com';
  8. beforeEach(async function () {
  9. this.token = await ERC1155Pausable.new(uri);
  10. });
  11. context('when token is paused', function () {
  12. const firstTokenId = new BN('37');
  13. const firstTokenAmount = new BN('42');
  14. const secondTokenId = new BN('19842');
  15. const secondTokenAmount = new BN('23');
  16. beforeEach(async function () {
  17. await this.token.setApprovalForAll(operator, true, { from: holder });
  18. await this.token.$_mint(holder, firstTokenId, firstTokenAmount, '0x');
  19. await this.token.$_pause();
  20. });
  21. it('reverts when trying to safeTransferFrom from holder', async function () {
  22. await expectRevertCustomError(
  23. this.token.safeTransferFrom(holder, receiver, firstTokenId, firstTokenAmount, '0x', { from: holder }),
  24. 'Paused',
  25. [],
  26. );
  27. });
  28. it('reverts when trying to safeTransferFrom from operator', async function () {
  29. await expectRevertCustomError(
  30. this.token.safeTransferFrom(holder, receiver, firstTokenId, firstTokenAmount, '0x', { from: operator }),
  31. 'Paused',
  32. [],
  33. );
  34. });
  35. it('reverts when trying to safeBatchTransferFrom from holder', async function () {
  36. await expectRevertCustomError(
  37. this.token.safeBatchTransferFrom(holder, receiver, [firstTokenId], [firstTokenAmount], '0x', { from: holder }),
  38. 'Paused',
  39. [],
  40. );
  41. });
  42. it('reverts when trying to safeBatchTransferFrom from operator', async function () {
  43. await expectRevertCustomError(
  44. this.token.safeBatchTransferFrom(holder, receiver, [firstTokenId], [firstTokenAmount], '0x', {
  45. from: operator,
  46. }),
  47. 'Paused',
  48. [],
  49. );
  50. });
  51. it('reverts when trying to mint', async function () {
  52. await expectRevertCustomError(this.token.$_mint(holder, secondTokenId, secondTokenAmount, '0x'), 'Paused', []);
  53. });
  54. it('reverts when trying to mintBatch', async function () {
  55. await expectRevertCustomError(
  56. this.token.$_mintBatch(holder, [secondTokenId], [secondTokenAmount], '0x'),
  57. 'Paused',
  58. [],
  59. );
  60. });
  61. it('reverts when trying to burn', async function () {
  62. await expectRevertCustomError(this.token.$_burn(holder, firstTokenId, firstTokenAmount), 'Paused', []);
  63. });
  64. it('reverts when trying to burnBatch', async function () {
  65. await expectRevertCustomError(this.token.$_burnBatch(holder, [firstTokenId], [firstTokenAmount]), 'Paused', []);
  66. });
  67. describe('setApprovalForAll', function () {
  68. it('approves an operator', async function () {
  69. await this.token.setApprovalForAll(other, true, { from: holder });
  70. expect(await this.token.isApprovedForAll(holder, other)).to.equal(true);
  71. });
  72. });
  73. describe('balanceOf', function () {
  74. it('returns the amount of tokens owned by the given address', async function () {
  75. const balance = await this.token.balanceOf(holder, firstTokenId);
  76. expect(balance).to.be.bignumber.equal(firstTokenAmount);
  77. });
  78. });
  79. describe('isApprovedForAll', function () {
  80. it('returns the approval of the operator', async function () {
  81. expect(await this.token.isApprovedForAll(holder, operator)).to.equal(true);
  82. });
  83. });
  84. });
  85. });