|
1 | | - |
2 | | -const EVMRevert = require('../helpers/EVMRevert.js'); |
| 1 | +import assertRevert from '../helpers/assertRevert'; |
3 | 2 | const BurnableTokenMock = artifacts.require('BurnableTokenMock'); |
4 | | -const BigNumber = web3.BigNumber; |
5 | 3 |
|
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 | + }); |
10 | 8 |
|
11 | | -const expect = require('chai').expect; |
| 9 | + describe('burn', function () { |
| 10 | + const from = owner; |
12 | 11 |
|
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; |
16 | 14 |
|
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 }); |
20 | 17 |
|
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 | + }); |
23 | 21 |
|
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 }); |
26 | 24 |
|
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 | + }); |
29 | 31 |
|
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; |
33 | 34 |
|
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 | + }); |
37 | 39 | }); |
38 | 40 | }); |
0 commit comments