StandardBurnableToken.test.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const { assertRevert } = require('../../helpers/assertRevert');
  2. const { inLogs } = require('../../helpers/expectEvent');
  3. const { shouldBehaveLikeBurnableToken } = require('./BurnableToken.behaviour');
  4. const StandardBurnableTokenMock = artifacts.require('StandardBurnableTokenMock');
  5. const BigNumber = web3.BigNumber;
  6. const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
  7. require('chai')
  8. .use(require('chai-bignumber')(BigNumber))
  9. .should();
  10. contract('StandardBurnableToken', function ([owner, burner]) {
  11. const initialBalance = 1000;
  12. beforeEach(async function () {
  13. this.token = await StandardBurnableTokenMock.new(owner, initialBalance);
  14. });
  15. shouldBehaveLikeBurnableToken([owner], initialBalance);
  16. describe('burnFrom', function () {
  17. describe('on success', function () {
  18. const amount = 100;
  19. beforeEach(async function () {
  20. await this.token.approve(burner, 300, { from: owner });
  21. const { logs } = await this.token.burnFrom(owner, amount, { from: burner });
  22. this.logs = logs;
  23. });
  24. it('burns the requested amount', async function () {
  25. const balance = await this.token.balanceOf(owner);
  26. balance.should.be.bignumber.equal(initialBalance - amount);
  27. });
  28. it('decrements allowance', async function () {
  29. const allowance = await this.token.allowance(owner, burner);
  30. allowance.should.be.bignumber.equal(200);
  31. });
  32. it('emits a burn event', async function () {
  33. const event = await inLogs(this.logs, 'Burn');
  34. event.args.burner.should.eq(owner);
  35. event.args.value.should.be.bignumber.equal(amount);
  36. });
  37. it('emits a transfer event', async function () {
  38. const event = await inLogs(this.logs, 'Transfer');
  39. event.args.from.should.eq(owner);
  40. event.args.to.should.eq(ZERO_ADDRESS);
  41. event.args.value.should.be.bignumber.equal(amount);
  42. });
  43. });
  44. describe('when the given amount is greater than the balance of the sender', function () {
  45. const amount = initialBalance + 1;
  46. it('reverts', async function () {
  47. await this.token.approve(burner, amount, { from: owner });
  48. await assertRevert(this.token.burnFrom(owner, amount, { from: burner }));
  49. });
  50. });
  51. describe('when the given amount is greater than the allowance', function () {
  52. const amount = 100;
  53. it('reverts', async function () {
  54. await this.token.approve(burner, amount - 1, { from: owner });
  55. await assertRevert(this.token.burnFrom(owner, amount, { from: burner }));
  56. });
  57. });
  58. });
  59. });