ERC721PausedToken.behavior.js 2.8 KB

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