ERC721PausedToken.behavior.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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(this.token.approve(recipient, firstTokenId, { from: owner }));
  13. });
  14. it('reverts when trying to setApprovalForAll', async function () {
  15. await shouldFail.reverting(this.token.setApprovalForAll(operator, true, { from: owner }));
  16. });
  17. it('reverts when trying to transferFrom', async function () {
  18. await shouldFail.reverting(this.token.transferFrom(owner, recipient, firstTokenId, { from: owner }));
  19. });
  20. it('reverts when trying to safeTransferFrom', async function () {
  21. await shouldFail.reverting(this.token.safeTransferFrom(owner, recipient, firstTokenId, { from: owner }));
  22. });
  23. it('reverts when trying to safeTransferFrom with data', async function () {
  24. await shouldFail.reverting(this.token.methods['safeTransferFrom(address,address,uint256,bytes)'](
  25. owner, recipient, firstTokenId, mockData, { from: owner })
  26. );
  27. });
  28. describe('getApproved', function () {
  29. it('returns approved address', async function () {
  30. const approvedAccount = await this.token.getApproved(firstTokenId);
  31. approvedAccount.should.be.equal(ZERO_ADDRESS);
  32. });
  33. });
  34. describe('balanceOf', function () {
  35. it('returns the amount of tokens owned by the given address', async function () {
  36. const balance = await this.token.balanceOf(owner);
  37. balance.should.be.bignumber.equal(mintedTokens);
  38. });
  39. });
  40. describe('ownerOf', function () {
  41. it('returns the amount of tokens owned by the given address', async function () {
  42. const ownerOfToken = await this.token.ownerOf(firstTokenId);
  43. ownerOfToken.should.be.equal(owner);
  44. });
  45. });
  46. describe('exists', function () {
  47. it('should return token existence', async function () {
  48. (await this.token.exists(firstTokenId)).should.equal(true);
  49. });
  50. });
  51. describe('isApprovedForAll', function () {
  52. it('returns the approval of the operator', async function () {
  53. (await this.token.isApprovedForAll(owner, operator)).should.equal(false);
  54. });
  55. });
  56. });
  57. }
  58. module.exports = {
  59. shouldBehaveLikeERC721PausedToken,
  60. };