ERC721Pausable.test.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
  6. const ERC721PausableMock = contract.fromArtifact('ERC721PausableMock');
  7. describe('ERC721Pausable', function () {
  8. const [ owner, receiver, operator ] = accounts;
  9. beforeEach(async function () {
  10. this.token = await ERC721PausableMock.new();
  11. });
  12. context('when token is not paused yet', function () {
  13. shouldBehaveLikeERC721(accounts);
  14. });
  15. context('when token is paused', function () {
  16. const firstTokenId = new BN(1);
  17. const mintedTokens = new BN(1);
  18. const mockData = '0x42';
  19. beforeEach(async function () {
  20. await this.token.mint(owner, firstTokenId, { from: owner });
  21. await this.token.pause();
  22. });
  23. it('reverts when trying to transferFrom', async function () {
  24. await expectRevert(
  25. this.token.transferFrom(owner, receiver, firstTokenId, { from: owner }),
  26. 'ERC721Pausable: token transfer while paused'
  27. );
  28. });
  29. it('reverts when trying to safeTransferFrom', async function () {
  30. await expectRevert(
  31. this.token.safeTransferFrom(owner, receiver, firstTokenId, { from: owner }),
  32. 'ERC721Pausable: token transfer while paused'
  33. );
  34. });
  35. it('reverts when trying to safeTransferFrom with data', async function () {
  36. await expectRevert(
  37. this.token.methods['safeTransferFrom(address,address,uint256,bytes)'](
  38. owner, receiver, firstTokenId, mockData, { from: owner }
  39. ), 'ERC721Pausable: token transfer while paused'
  40. );
  41. });
  42. describe('getApproved', function () {
  43. it('returns approved address', async function () {
  44. const approvedAccount = await this.token.getApproved(firstTokenId);
  45. expect(approvedAccount).to.equal(ZERO_ADDRESS);
  46. });
  47. });
  48. describe('balanceOf', function () {
  49. it('returns the amount of tokens owned by the given address', async function () {
  50. const balance = await this.token.balanceOf(owner);
  51. expect(balance).to.be.bignumber.equal(mintedTokens);
  52. });
  53. });
  54. describe('ownerOf', function () {
  55. it('returns the amount of tokens owned by the given address', async function () {
  56. const ownerOfToken = await this.token.ownerOf(firstTokenId);
  57. expect(ownerOfToken).to.equal(owner);
  58. });
  59. });
  60. describe('exists', function () {
  61. it('should return token existence', async function () {
  62. expect(await this.token.exists(firstTokenId)).to.equal(true);
  63. });
  64. });
  65. describe('isApprovedForAll', function () {
  66. it('returns the approval of the operator', async function () {
  67. expect(await this.token.isApprovedForAll(owner, operator)).to.equal(false);
  68. });
  69. });
  70. });
  71. });