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