BurnableToken.behaviour.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const { assertRevert } = require('../../helpers/assertRevert');
  2. const { inLogs } = require('../../helpers/expectEvent');
  3. const BigNumber = web3.BigNumber;
  4. const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
  5. require('chai')
  6. .use(require('chai-bignumber')(BigNumber))
  7. .should();
  8. function shouldBehaveLikeBurnableToken ([owner], initialBalance) {
  9. describe('as a basic burnable token', function () {
  10. const from = owner;
  11. describe('when the given amount is not greater than balance of the sender', function () {
  12. const amount = 100;
  13. beforeEach(async function () {
  14. ({ logs: this.logs } = await this.token.burn(amount, { from }));
  15. });
  16. it('burns the requested amount', async function () {
  17. const balance = await this.token.balanceOf(from);
  18. balance.should.be.bignumber.equal(initialBalance - amount);
  19. });
  20. it('emits a burn event', async function () {
  21. const event = await inLogs(this.logs, 'Burn');
  22. event.args.burner.should.eq(owner);
  23. event.args.value.should.be.bignumber.equal(amount);
  24. });
  25. it('emits a transfer event', async function () {
  26. const event = await inLogs(this.logs, 'Transfer');
  27. event.args.from.should.eq(owner);
  28. event.args.to.should.eq(ZERO_ADDRESS);
  29. event.args.value.should.be.bignumber.equal(amount);
  30. });
  31. });
  32. describe('when the given amount is greater than the balance of the sender', function () {
  33. const amount = initialBalance + 1;
  34. it('reverts', async function () {
  35. await assertRevert(this.token.burn(amount, { from }));
  36. });
  37. });
  38. });
  39. }
  40. module.exports = {
  41. shouldBehaveLikeBurnableToken,
  42. };