ERC721Burnable.test.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
  2. const { ZERO_ADDRESS } = constants;
  3. const { expect } = require('chai');
  4. const ERC721BurnableMock = artifacts.require('ERC721BurnableMock');
  5. contract('ERC721Burnable', function (accounts) {
  6. const [owner, approved] = accounts;
  7. const firstTokenId = new BN(1);
  8. const secondTokenId = new BN(2);
  9. const unknownTokenId = new BN(3);
  10. const name = 'Non Fungible Token';
  11. const symbol = 'NFT';
  12. beforeEach(async function () {
  13. this.token = await ERC721BurnableMock.new(name, symbol);
  14. });
  15. describe('like a burnable ERC721', function () {
  16. beforeEach(async function () {
  17. await this.token.mint(owner, firstTokenId);
  18. await this.token.mint(owner, secondTokenId);
  19. });
  20. describe('burn', function () {
  21. const tokenId = firstTokenId;
  22. let receipt = null;
  23. describe('when successful', function () {
  24. beforeEach(async function () {
  25. receipt = await this.token.burn(tokenId, { from: owner });
  26. });
  27. it('burns the given token ID and adjusts the balance of the owner', async function () {
  28. await expectRevert(
  29. this.token.ownerOf(tokenId),
  30. 'ERC721: owner query for nonexistent token',
  31. );
  32. expect(await this.token.balanceOf(owner)).to.be.bignumber.equal('1');
  33. });
  34. it('emits a burn event', async function () {
  35. expectEvent(receipt, 'Transfer', {
  36. from: owner,
  37. to: ZERO_ADDRESS,
  38. tokenId: tokenId,
  39. });
  40. });
  41. });
  42. describe('when there is a previous approval burned', function () {
  43. beforeEach(async function () {
  44. await this.token.approve(approved, tokenId, { from: owner });
  45. receipt = await this.token.burn(tokenId, { from: owner });
  46. });
  47. context('getApproved', function () {
  48. it('reverts', async function () {
  49. await expectRevert(
  50. this.token.getApproved(tokenId), 'ERC721: approved query for nonexistent token',
  51. );
  52. });
  53. });
  54. });
  55. describe('when the given token ID was not tracked by this contract', function () {
  56. it('reverts', async function () {
  57. await expectRevert(
  58. this.token.burn(unknownTokenId, { from: owner }), 'ERC721: operator query for nonexistent token',
  59. );
  60. });
  61. });
  62. });
  63. });
  64. });