ERC721Pausable.test.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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)'](
  34. owner, receiver, firstTokenId, mockData, { from: owner },
  35. ), 'ERC721Pausable: token transfer while paused',
  36. );
  37. });
  38. it('reverts when trying to mint', async function () {
  39. await expectRevert(
  40. this.token.$_mint(receiver, secondTokenId),
  41. 'ERC721Pausable: token transfer while paused',
  42. );
  43. });
  44. it('reverts when trying to burn', async function () {
  45. await expectRevert(
  46. this.token.$_burn(firstTokenId),
  47. 'ERC721Pausable: token transfer while paused',
  48. );
  49. });
  50. describe('getApproved', function () {
  51. it('returns approved address', async function () {
  52. const approvedAccount = await this.token.getApproved(firstTokenId);
  53. expect(approvedAccount).to.equal(constants.ZERO_ADDRESS);
  54. });
  55. });
  56. describe('balanceOf', function () {
  57. it('returns the amount of tokens owned by the given address', async function () {
  58. const balance = await this.token.balanceOf(owner);
  59. expect(balance).to.be.bignumber.equal('1');
  60. });
  61. });
  62. describe('ownerOf', function () {
  63. it('returns the amount of tokens owned by the given address', async function () {
  64. const ownerOfToken = await this.token.ownerOf(firstTokenId);
  65. expect(ownerOfToken).to.equal(owner);
  66. });
  67. });
  68. describe('exists', function () {
  69. it('returns token existence', async function () {
  70. expect(await this.token.$_exists(firstTokenId)).to.equal(true);
  71. });
  72. });
  73. describe('isApprovedForAll', function () {
  74. it('returns the approval of the operator', async function () {
  75. expect(await this.token.isApprovedForAll(owner, operator)).to.equal(false);
  76. });
  77. });
  78. });
  79. });