ERC721PausedToken.behavior.js 2.8 KB

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