StandardBurnableToken.test.js 2.6 KB

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