ERC1155Pausable.test.js 3.7 KB

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