-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e397b15
commit d0d6599
Showing
1 changed file
with
28 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 })); | ||
}); | ||
}); | ||
}); | ||
}); |