ERC721Pausable.test.js 3.0 KB

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