ERC721Pausable.test.js 3.1 KB

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