ERC721Burnable.test.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. const { accounts, contract } = require('@openzeppelin/test-environment');
  2. const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
  3. const { ZERO_ADDRESS } = constants;
  4. const { expect } = require('chai');
  5. const ERC721BurnableMock = contract.fromArtifact('ERC721BurnableMock');
  6. describe('ERC721Burnable', function () {
  7. const [owner, approved] = accounts;
  8. const firstTokenId = new BN(1);
  9. const secondTokenId = new BN(2);
  10. const unknownTokenId = new BN(3);
  11. beforeEach(async function () {
  12. this.token = await ERC721BurnableMock.new();
  13. });
  14. describe('like a burnable ERC721', function () {
  15. beforeEach(async function () {
  16. await this.token.mint(owner, firstTokenId);
  17. await this.token.mint(owner, secondTokenId);
  18. });
  19. describe('burn', function () {
  20. const tokenId = firstTokenId;
  21. let logs = null;
  22. describe('when successful', function () {
  23. beforeEach(async function () {
  24. const result = await this.token.burn(tokenId, { from: owner });
  25. logs = result.logs;
  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.inLogs(logs, '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. const result = await this.token.burn(tokenId, { from: owner });
  46. logs = result.logs;
  47. });
  48. context('getApproved', function () {
  49. it('reverts', async function () {
  50. await expectRevert(
  51. this.token.getApproved(tokenId), 'ERC721: approved query for nonexistent token'
  52. );
  53. });
  54. });
  55. });
  56. describe('when the given token ID was not tracked by this contract', function () {
  57. it('reverts', async function () {
  58. await expectRevert(
  59. this.token.burn(unknownTokenId, { from: owner }), 'ERC721: operator query for nonexistent token'
  60. );
  61. });
  62. });
  63. });
  64. });
  65. });