ERC721PausedToken.behavior.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. const { BN, constants, expectRevert } = require('openzeppelin-test-helpers');
  2. const { ZERO_ADDRESS } = constants;
  3. const { expect } = require('chai');
  4. function shouldBehaveLikeERC721PausedToken (owner, [recipient, operator]) {
  5. const firstTokenId = new BN(1);
  6. const mintedTokens = new BN(1);
  7. const mockData = '0x42';
  8. describe('like a paused ERC721', function () {
  9. beforeEach(async function () {
  10. await this.token.mint(owner, firstTokenId, { from: owner });
  11. });
  12. it('reverts when trying to approve', async function () {
  13. await expectRevert(
  14. this.token.approve(recipient, firstTokenId, { from: owner }), 'Pausable: paused'
  15. );
  16. });
  17. it('reverts when trying to setApprovalForAll', async function () {
  18. await expectRevert(
  19. this.token.setApprovalForAll(operator, true, { from: owner }), 'Pausable: paused'
  20. );
  21. });
  22. it('reverts when trying to transferFrom', async function () {
  23. await expectRevert(
  24. this.token.transferFrom(owner, recipient, firstTokenId, { from: owner }), 'Pausable: paused'
  25. );
  26. });
  27. it('reverts when trying to safeTransferFrom', async function () {
  28. await expectRevert(
  29. this.token.safeTransferFrom(owner, recipient, firstTokenId, { from: owner }), 'Pausable: 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, recipient, firstTokenId, mockData, { from: owner }
  36. ), 'Pausable: paused'
  37. );
  38. });
  39. describe('getApproved', function () {
  40. it('returns approved address', async function () {
  41. const approvedAccount = await this.token.getApproved(firstTokenId);
  42. expect(approvedAccount).to.equal(ZERO_ADDRESS);
  43. });
  44. });
  45. describe('balanceOf', function () {
  46. it('returns the amount of tokens owned by the given address', async function () {
  47. const balance = await this.token.balanceOf(owner);
  48. expect(balance).to.be.bignumber.equal(mintedTokens);
  49. });
  50. });
  51. describe('ownerOf', function () {
  52. it('returns the amount of tokens owned by the given address', async function () {
  53. const ownerOfToken = await this.token.ownerOf(firstTokenId);
  54. expect(ownerOfToken).to.equal(owner);
  55. });
  56. });
  57. describe('exists', function () {
  58. it('should return token existence', async function () {
  59. expect(await this.token.exists(firstTokenId)).to.equal(true);
  60. });
  61. });
  62. describe('isApprovedForAll', function () {
  63. it('returns the approval of the operator', async function () {
  64. expect(await this.token.isApprovedForAll(owner, operator)).to.equal(false);
  65. });
  66. });
  67. });
  68. }
  69. module.exports = {
  70. shouldBehaveLikeERC721PausedToken,
  71. };