BurnableToken.test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
  19. assert.equal(logs.length, 2);
  20. assert.equal(logs[0].event, 'Burn');
  21. assert.equal(logs[0].args.burner, owner);
  22. assert.equal(logs[0].args.value, amount);
  23. assert.equal(logs[1].event, 'Transfer');
  24. assert.equal(logs[1].args.from, owner);
  25. assert.equal(logs[1].args.to, ZERO_ADDRESS);
  26. assert.equal(logs[1].args.value, amount);
  27. });
  28. });
  29. describe('when the given amount is greater than the balance of the sender', function () {
  30. const amount = 1001;
  31. it('reverts', async function () {
  32. await assertRevert(this.token.burn(amount, { from }));
  33. });
  34. });
  35. });
  36. });