ERC721PausedToken.behavior.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const { assertRevert } = require('../../helpers/assertRevert');
  2. const { sendTransaction } = require('../../helpers/sendTransaction');
  3. const { ZERO_ADDRESS } = require('../../helpers/constants');
  4. const BigNumber = web3.BigNumber;
  5. require('chai')
  6. .use(require('chai-bignumber')(BigNumber))
  7. .should();
  8. function shouldBehaveLikeERC721PausedToken (owner, [recipient, operator]) {
  9. const firstTokenId = 1;
  10. const mintedTokens = 1;
  11. const mockData = '0x42';
  12. describe('like a paused ERC721', function () {
  13. beforeEach(async function () {
  14. await this.token.mint(owner, firstTokenId, { from: owner });
  15. });
  16. it('reverts when trying to approve', async function () {
  17. await assertRevert(this.token.approve(recipient, firstTokenId, { from: owner }));
  18. });
  19. it('reverts when trying to setApprovalForAll', async function () {
  20. await assertRevert(this.token.setApprovalForAll(operator, true, { from: owner }));
  21. });
  22. it('reverts when trying to transferFrom', async function () {
  23. await assertRevert(this.token.transferFrom(owner, recipient, firstTokenId, { from: owner }));
  24. });
  25. it('reverts when trying to safeTransferFrom', async function () {
  26. await assertRevert(this.token.safeTransferFrom(owner, recipient, firstTokenId, { from: owner }));
  27. });
  28. it('reverts when trying to safeTransferFrom with data', async function () {
  29. await assertRevert(
  30. sendTransaction(
  31. this.token,
  32. 'safeTransferFrom',
  33. 'address,address,uint256,bytes',
  34. [owner, recipient, firstTokenId, mockData],
  35. { from: owner }
  36. )
  37. );
  38. });
  39. describe('getApproved', function () {
  40. it('returns approved address', async function () {
  41. const approvedAccount = await this.token.getApproved(firstTokenId);
  42. approvedAccount.should.be.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. balance.should.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. ownerOfToken.should.be.equal(owner);
  55. });
  56. });
  57. describe('exists', function () {
  58. it('should return token existance', async function () {
  59. const result = await this.token.exists(firstTokenId);
  60. result.should.eq(true);
  61. });
  62. });
  63. describe('isApprovedForAll', function () {
  64. it('returns the approval of the operator', async function () {
  65. const isApproved = await this.token.isApprovedForAll(owner, operator);
  66. isApproved.should.eq(false);
  67. });
  68. });
  69. });
  70. }
  71. module.exports = {
  72. shouldBehaveLikeERC721PausedToken,
  73. };