ERC721Pausable.test.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. const { accounts, contract } = require('@openzeppelin/test-environment');
  2. const { BN, constants, expectRevert } = require('@openzeppelin/test-helpers');
  3. const { ZERO_ADDRESS } = constants;
  4. const { expect } = require('chai');
  5. const ERC721PausableMock = contract.fromArtifact('ERC721PausableMock');
  6. describe('ERC721Pausable', function () {
  7. const [ owner, receiver, operator ] = accounts;
  8. const name = 'Non Fungible Token';
  9. const symbol = 'NFT';
  10. beforeEach(async function () {
  11. this.token = await ERC721PausableMock.new(name, symbol);
  12. });
  13. context('when token is paused', function () {
  14. const firstTokenId = new BN(1);
  15. const secondTokenId = new BN(1337);
  16. const mockData = '0x42';
  17. beforeEach(async function () {
  18. await this.token.mint(owner, firstTokenId, { from: owner });
  19. await this.token.pause();
  20. });
  21. it('reverts when trying to transferFrom', async function () {
  22. await expectRevert(
  23. this.token.transferFrom(owner, receiver, firstTokenId, { from: owner }),
  24. 'ERC721Pausable: token transfer while paused'
  25. );
  26. });
  27. it('reverts when trying to safeTransferFrom', async function () {
  28. await expectRevert(
  29. this.token.safeTransferFrom(owner, receiver, firstTokenId, { from: owner }),
  30. 'ERC721Pausable: token transfer while paused'
  31. );
  32. });
  33. it('reverts when trying to safeTransferFrom with data', async function () {
  34. await expectRevert(
  35. this.token.methods['safeTransferFrom(address,address,uint256,bytes)'](
  36. owner, receiver, firstTokenId, mockData, { from: owner }
  37. ), 'ERC721Pausable: token transfer while paused'
  38. );
  39. });
  40. it('reverts when trying to mint', async function () {
  41. await expectRevert(
  42. this.token.mint(receiver, secondTokenId),
  43. 'ERC721Pausable: token transfer while paused'
  44. );
  45. });
  46. it('reverts when trying to burn', async function () {
  47. await expectRevert(
  48. this.token.burn(firstTokenId),
  49. 'ERC721Pausable: token transfer while paused'
  50. );
  51. });
  52. describe('getApproved', function () {
  53. it('returns approved address', async function () {
  54. const approvedAccount = await this.token.getApproved(firstTokenId);
  55. expect(approvedAccount).to.equal(ZERO_ADDRESS);
  56. });
  57. });
  58. describe('balanceOf', function () {
  59. it('returns the amount of tokens owned by the given address', async function () {
  60. const balance = await this.token.balanceOf(owner);
  61. expect(balance).to.be.bignumber.equal('1');
  62. });
  63. });
  64. describe('ownerOf', function () {
  65. it('returns the amount of tokens owned by the given address', async function () {
  66. const ownerOfToken = await this.token.ownerOf(firstTokenId);
  67. expect(ownerOfToken).to.equal(owner);
  68. });
  69. });
  70. describe('exists', function () {
  71. it('returns token existence', async function () {
  72. expect(await this.token.exists(firstTokenId)).to.equal(true);
  73. });
  74. });
  75. describe('isApprovedForAll', function () {
  76. it('returns the approval of the operator', async function () {
  77. expect(await this.token.isApprovedForAll(owner, operator)).to.equal(false);
  78. });
  79. });
  80. });
  81. });