ERC1155Pausable.test.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const { accounts, contract } = require('@openzeppelin/test-environment');
  2. const { BN, expectRevert } = require('@openzeppelin/test-helpers');
  3. const { expect } = require('chai');
  4. const ERC1155PausableMock = contract.fromArtifact('ERC1155PausableMock');
  5. describe('ERC1155Pausable', function () {
  6. const [ holder, operator, receiver, other ] = accounts;
  7. const uri = 'https://token.com';
  8. beforeEach(async function () {
  9. this.token = await ERC1155PausableMock.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 expectRevert(
  23. this.token.safeTransferFrom(holder, receiver, firstTokenId, firstTokenAmount, '0x', { from: holder }),
  24. 'ERC1155Pausable: token transfer while paused'
  25. );
  26. });
  27. it('reverts when trying to safeTransferFrom from operator', async function () {
  28. await expectRevert(
  29. this.token.safeTransferFrom(holder, receiver, firstTokenId, firstTokenAmount, '0x', { from: operator }),
  30. 'ERC1155Pausable: token transfer while paused'
  31. );
  32. });
  33. it('reverts when trying to safeBatchTransferFrom from holder', async function () {
  34. await expectRevert(
  35. this.token.safeBatchTransferFrom(holder, receiver, [firstTokenId], [firstTokenAmount], '0x', { from: holder }),
  36. 'ERC1155Pausable: token transfer while paused'
  37. );
  38. });
  39. it('reverts when trying to safeBatchTransferFrom from operator', async function () {
  40. await expectRevert(
  41. this.token.safeBatchTransferFrom(
  42. holder, receiver, [firstTokenId], [firstTokenAmount], '0x', { from: operator }
  43. ),
  44. 'ERC1155Pausable: token transfer while paused'
  45. );
  46. });
  47. it('reverts when trying to mint', async function () {
  48. await expectRevert(
  49. this.token.mint(holder, secondTokenId, secondTokenAmount, '0x'),
  50. 'ERC1155Pausable: token transfer while paused'
  51. );
  52. });
  53. it('reverts when trying to mintBatch', async function () {
  54. await expectRevert(
  55. this.token.mintBatch(holder, [secondTokenId], [secondTokenAmount], '0x'),
  56. 'ERC1155Pausable: token transfer while paused'
  57. );
  58. });
  59. it('reverts when trying to burn', async function () {
  60. await expectRevert(
  61. this.token.burn(holder, firstTokenId, firstTokenAmount),
  62. 'ERC1155Pausable: token transfer while paused'
  63. );
  64. });
  65. it('reverts when trying to burnBatch', async function () {
  66. await expectRevert(
  67. this.token.burn(holder, [firstTokenId], [firstTokenAmount]),
  68. 'ERC1155Pausable: token transfer while paused'
  69. );
  70. });
  71. describe('setApprovalForAll', function () {
  72. it('approves an operator', async function () {
  73. await this.token.setApprovalForAll(other, true, { from: holder });
  74. expect(await this.token.isApprovedForAll(holder, other)).to.equal(true);
  75. });
  76. });
  77. describe('balanceOf', function () {
  78. it('returns the amount of tokens owned by the given address', async function () {
  79. const balance = await this.token.balanceOf(holder, firstTokenId);
  80. expect(balance).to.be.bignumber.equal(firstTokenAmount);
  81. });
  82. });
  83. describe('isApprovedForAll', function () {
  84. it('returns the approval of the operator', async function () {
  85. expect(await this.token.isApprovedForAll(holder, operator)).to.equal(true);
  86. });
  87. });
  88. });
  89. });