ERC721Burnable.test.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. const name = 'Non Fungible Token';
  12. const symbol = 'NFT';
  13. beforeEach(async function () {
  14. this.token = await ERC721BurnableMock.new(name, symbol);
  15. });
  16. describe('like a burnable ERC721', function () {
  17. beforeEach(async function () {
  18. await this.token.mint(owner, firstTokenId);
  19. await this.token.mint(owner, secondTokenId);
  20. });
  21. describe('burn', function () {
  22. const tokenId = firstTokenId;
  23. let logs = null;
  24. describe('when successful', function () {
  25. beforeEach(async function () {
  26. const result = await this.token.burn(tokenId, { from: owner });
  27. logs = result.logs;
  28. });
  29. it('burns the given token ID and adjusts the balance of the owner', async function () {
  30. await expectRevert(
  31. this.token.ownerOf(tokenId),
  32. 'ERC721: owner query for nonexistent token'
  33. );
  34. expect(await this.token.balanceOf(owner)).to.be.bignumber.equal('1');
  35. });
  36. it('emits a burn event', async function () {
  37. expectEvent.inLogs(logs, 'Transfer', {
  38. from: owner,
  39. to: ZERO_ADDRESS,
  40. tokenId: tokenId,
  41. });
  42. });
  43. });
  44. describe('when there is a previous approval burned', function () {
  45. beforeEach(async function () {
  46. await this.token.approve(approved, tokenId, { from: owner });
  47. const result = await this.token.burn(tokenId, { from: owner });
  48. logs = result.logs;
  49. });
  50. context('getApproved', function () {
  51. it('reverts', async function () {
  52. await expectRevert(
  53. this.token.getApproved(tokenId), 'ERC721: approved query for nonexistent token'
  54. );
  55. });
  56. });
  57. });
  58. describe('when the given token ID was not tracked by this contract', function () {
  59. it('reverts', async function () {
  60. await expectRevert(
  61. this.token.burn(unknownTokenId, { from: owner }), 'ERC721: operator query for nonexistent token'
  62. );
  63. });
  64. });
  65. });
  66. });
  67. });