Skip to content

Commit

Permalink
Improve BurnableToken test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo committed Jan 28, 2018
1 parent 6eae6a1 commit 4018821
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions test/token/BurnableToken.test.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@

const EVMRevert = require('../helpers/EVMRevert.js');
import assertRevert from '../helpers/assertRevert';
const BurnableTokenMock = artifacts.require('BurnableTokenMock');
const BigNumber = web3.BigNumber;

require('chai')
.use(require('chai-as-promised'))
.use(require('chai-bignumber')(BigNumber))
.should();
contract('BurnableToken', function (owner) {
beforeEach(async function () {
this.token = await BurnableTokenMock.new(owner, 1000);
});

const expect = require('chai').expect;
describe('burn', function () {
const from = owner;

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

beforeEach(async function () {
token = await BurnableTokenMock.new(accounts[0], 1000);
});
it('burns the requested amount', async function () {
await this.token.burn(amount, { from });

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

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

const totalSupply = await token.totalSupply();
totalSupply.should.be.bignumber.equal(expectedTokenSupply);
assert.equal(logs.length, 1);
assert.equal(logs[0].event, 'Burn');
assert.equal(logs[0].args.burner, owner);
assert.equal(logs[0].args.value, amount);
});
});

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

it('cannot burn more tokens than your balance', async function () {
await token.burn(2000, { from: accounts[0] })
.should.be.rejectedWith(EVMRevert);
it('reverts', async function () {
await assertRevert(this.token.burn(amount, { from }));
});
});
});
});

0 comments on commit 4018821

Please sign in to comment.