Skip to content

Commit d0d6599

Browse files
committed
Improve BurnableToken test coverage
1 parent e397b15 commit d0d6599

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

test/token/BurnableToken.test.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
1-
2-
const EVMRevert = require('../helpers/EVMRevert.js');
1+
import assertRevert from '../helpers/assertRevert';
32
const BurnableTokenMock = artifacts.require('BurnableTokenMock');
4-
const BigNumber = web3.BigNumber;
53

6-
require('chai')
7-
.use(require('chai-as-promised'))
8-
.use(require('chai-bignumber')(BigNumber))
9-
.should();
4+
contract('BurnableToken', function (owner) {
5+
beforeEach(async function () {
6+
this.token = await BurnableTokenMock.new(owner, 1000);
7+
});
108

11-
const expect = require('chai').expect;
9+
describe('burn', function () {
10+
const from = owner;
1211

13-
contract('BurnableToken', function (accounts) {
14-
let token;
15-
let expectedTokenSupply = new BigNumber(999);
12+
describe('when the given amount is not greater than balance of the sender', function () {
13+
const amount = 100;
1614

17-
beforeEach(async function () {
18-
token = await BurnableTokenMock.new(accounts[0], 1000);
19-
});
15+
it('burns the requested amount', async function () {
16+
await this.token.burn(amount, { from });
2017

21-
it('owner should be able to burn tokens', async function () {
22-
const { logs } = await token.burn(1, { from: accounts[0] });
18+
const balance = await this.token.balanceOf(from);
19+
assert.equal(balance, 900);
20+
});
2321

24-
const balance = await token.balanceOf(accounts[0]);
25-
balance.should.be.bignumber.equal(expectedTokenSupply);
22+
it('emits a burn event', async function () {
23+
const { logs } = await this.token.burn(amount, { from });
2624

27-
const totalSupply = await token.totalSupply();
28-
totalSupply.should.be.bignumber.equal(expectedTokenSupply);
25+
assert.equal(logs.length, 1);
26+
assert.equal(logs[0].event, 'Burn');
27+
assert.equal(logs[0].args.burner, owner);
28+
assert.equal(logs[0].args.value, amount);
29+
});
30+
});
2931

30-
const event = logs.find(e => e.event === 'Burn');
31-
expect(event).to.exist;
32-
});
32+
describe('when the given amount is greater than the balance of the sender', function () {
33+
const amount = 1001;
3334

34-
it('cannot burn more tokens than your balance', async function () {
35-
await token.burn(2000, { from: accounts[0] })
36-
.should.be.rejectedWith(EVMRevert);
35+
it('reverts', async function () {
36+
await assertRevert(this.token.burn(amount, { from }));
37+
});
38+
});
3739
});
3840
});

0 commit comments

Comments
 (0)