BurnableToken.test.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import assertRevert from '../helpers/assertRevert';
  2. const BurnableTokenMock = artifacts.require('BurnableTokenMock');
  3. contract('BurnableToken', function ([owner]) {
  4. beforeEach(async function () {
  5. this.token = await BurnableTokenMock.new(owner, 1000);
  6. });
  7. describe('burn', function () {
  8. const from = owner;
  9. describe('when the given amount is not greater than balance of the sender', function () {
  10. const amount = 100;
  11. it('burns the requested amount', async function () {
  12. await this.token.burn(amount, { from });
  13. const balance = await this.token.balanceOf(from);
  14. assert.equal(balance, 900);
  15. });
  16. it('emits a burn event', async function () {
  17. const { logs } = await this.token.burn(amount, { from });
  18. assert.equal(logs.length, 1);
  19. assert.equal(logs[0].event, 'Burn');
  20. assert.equal(logs[0].args.burner, owner);
  21. assert.equal(logs[0].args.value, amount);
  22. });
  23. });
  24. describe('when the given amount is greater than the balance of the sender', function () {
  25. const amount = 1001;
  26. it('reverts', async function () {
  27. await assertRevert(this.token.burn(amount, { from }));
  28. });
  29. });
  30. });
  31. });