ERC721Burnable.test.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
  2. const { expect } = require('chai');
  3. const ERC721Burnable = artifacts.require('$ERC721Burnable');
  4. contract('ERC721Burnable', function (accounts) {
  5. const [owner, approved] = accounts;
  6. const firstTokenId = new BN(1);
  7. const secondTokenId = new BN(2);
  8. const unknownTokenId = new BN(3);
  9. const name = 'Non Fungible Token';
  10. const symbol = 'NFT';
  11. beforeEach(async function () {
  12. this.token = await ERC721Burnable.new(name, symbol);
  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 receipt = null;
  22. describe('when successful', function () {
  23. beforeEach(async function () {
  24. receipt = await this.token.burn(tokenId, { from: owner });
  25. });
  26. it('burns the given token ID and adjusts the balance of the owner', async function () {
  27. await expectRevert(this.token.ownerOf(tokenId), 'ERC721: invalid token ID');
  28. expect(await this.token.balanceOf(owner)).to.be.bignumber.equal('1');
  29. });
  30. it('emits a burn event', async function () {
  31. expectEvent(receipt, 'Transfer', {
  32. from: owner,
  33. to: constants.ZERO_ADDRESS,
  34. tokenId: tokenId,
  35. });
  36. });
  37. });
  38. describe('when there is a previous approval burned', function () {
  39. beforeEach(async function () {
  40. await this.token.approve(approved, tokenId, { from: owner });
  41. receipt = await this.token.burn(tokenId, { from: owner });
  42. });
  43. context('getApproved', function () {
  44. it('reverts', async function () {
  45. await expectRevert(this.token.getApproved(tokenId), 'ERC721: invalid token ID');
  46. });
  47. });
  48. });
  49. describe('when the given token ID was not tracked by this contract', function () {
  50. it('reverts', async function () {
  51. await expectRevert(this.token.burn(unknownTokenId, { from: owner }), 'ERC721: invalid token ID');
  52. });
  53. });
  54. });
  55. });
  56. });