ERC721Pausable.test.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 mintedTokens = new BN(1);
  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. describe('getApproved', function () {
  41. it('returns approved address', async function () {
  42. const approvedAccount = await this.token.getApproved(firstTokenId);
  43. expect(approvedAccount).to.equal(ZERO_ADDRESS);
  44. });
  45. });
  46. describe('balanceOf', function () {
  47. it('returns the amount of tokens owned by the given address', async function () {
  48. const balance = await this.token.balanceOf(owner);
  49. expect(balance).to.be.bignumber.equal(mintedTokens);
  50. });
  51. });
  52. describe('ownerOf', function () {
  53. it('returns the amount of tokens owned by the given address', async function () {
  54. const ownerOfToken = await this.token.ownerOf(firstTokenId);
  55. expect(ownerOfToken).to.equal(owner);
  56. });
  57. });
  58. describe('exists', function () {
  59. it('should return token existence', async function () {
  60. expect(await this.token.exists(firstTokenId)).to.equal(true);
  61. });
  62. });
  63. describe('isApprovedForAll', function () {
  64. it('returns the approval of the operator', async function () {
  65. expect(await this.token.isApprovedForAll(owner, operator)).to.equal(false);
  66. });
  67. });
  68. });
  69. });