ERC1155Pausable.test.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 firstTokenValue = new BN('42');
  14. const secondTokenId = new BN('19842');
  15. const secondTokenValue = new BN('23');
  16. beforeEach(async function () {
  17. await this.token.setApprovalForAll(operator, true, { from: holder });
  18. await this.token.$_mint(holder, firstTokenId, firstTokenValue, '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, firstTokenValue, '0x', { from: holder }),
  24. 'EnforcedPause',
  25. [],
  26. );
  27. });
  28. it('reverts when trying to safeTransferFrom from operator', async function () {
  29. await expectRevertCustomError(
  30. this.token.safeTransferFrom(holder, receiver, firstTokenId, firstTokenValue, '0x', { from: operator }),
  31. 'EnforcedPause',
  32. [],
  33. );
  34. });
  35. it('reverts when trying to safeBatchTransferFrom from holder', async function () {
  36. await expectRevertCustomError(
  37. this.token.safeBatchTransferFrom(holder, receiver, [firstTokenId], [firstTokenValue], '0x', { from: holder }),
  38. 'EnforcedPause',
  39. [],
  40. );
  41. });
  42. it('reverts when trying to safeBatchTransferFrom from operator', async function () {
  43. await expectRevertCustomError(
  44. this.token.safeBatchTransferFrom(holder, receiver, [firstTokenId], [firstTokenValue], '0x', {
  45. from: operator,
  46. }),
  47. 'EnforcedPause',
  48. [],
  49. );
  50. });
  51. it('reverts when trying to mint', async function () {
  52. await expectRevertCustomError(
  53. this.token.$_mint(holder, secondTokenId, secondTokenValue, '0x'),
  54. 'EnforcedPause',
  55. [],
  56. );
  57. });
  58. it('reverts when trying to mintBatch', async function () {
  59. await expectRevertCustomError(
  60. this.token.$_mintBatch(holder, [secondTokenId], [secondTokenValue], '0x'),
  61. 'EnforcedPause',
  62. [],
  63. );
  64. });
  65. it('reverts when trying to burn', async function () {
  66. await expectRevertCustomError(this.token.$_burn(holder, firstTokenId, firstTokenValue), 'EnforcedPause', []);
  67. });
  68. it('reverts when trying to burnBatch', async function () {
  69. await expectRevertCustomError(
  70. this.token.$_burnBatch(holder, [firstTokenId], [firstTokenValue]),
  71. 'EnforcedPause',
  72. [],
  73. );
  74. });
  75. describe('setApprovalForAll', function () {
  76. it('approves an operator', async function () {
  77. await this.token.setApprovalForAll(other, true, { from: holder });
  78. expect(await this.token.isApprovedForAll(holder, other)).to.equal(true);
  79. });
  80. });
  81. describe('balanceOf', function () {
  82. it('returns the token value owned by the given address', async function () {
  83. const balance = await this.token.balanceOf(holder, firstTokenId);
  84. expect(balance).to.be.bignumber.equal(firstTokenValue);
  85. });
  86. });
  87. describe('isApprovedForAll', function () {
  88. it('returns the approval of the operator', async function () {
  89. expect(await this.token.isApprovedForAll(holder, operator)).to.equal(true);
  90. });
  91. });
  92. });
  93. });