ERC20Mintable.behavior.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const { assertRevert } = require('../../../helpers/assertRevert');
  2. const expectEvent = require('../../../helpers/expectEvent');
  3. const { ZERO_ADDRESS } = require('../../../helpers/constants');
  4. const BigNumber = web3.BigNumber;
  5. require('chai')
  6. .use(require('chai-bignumber')(BigNumber))
  7. .should();
  8. function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
  9. describe('as a mintable token', function () {
  10. describe('mint', function () {
  11. const amount = 100;
  12. context('when the sender has minting permission', function () {
  13. const from = minter;
  14. context('for a zero amount', function () {
  15. shouldMint(0);
  16. });
  17. context('for a non-zero amount', function () {
  18. shouldMint(amount);
  19. });
  20. function shouldMint (amount) {
  21. beforeEach(async function () {
  22. ({ logs: this.logs } = await this.token.mint(anyone, amount, { from }));
  23. });
  24. it('mints the requested amount', async function () {
  25. (await this.token.balanceOf(anyone)).should.be.bignumber.equal(amount);
  26. });
  27. it('emits a mint and a transfer event', async function () {
  28. expectEvent.inLogs(this.logs, 'Transfer', {
  29. from: ZERO_ADDRESS,
  30. to: anyone,
  31. value: amount,
  32. });
  33. });
  34. }
  35. });
  36. context('when the sender doesn\'t have minting permission', function () {
  37. const from = anyone;
  38. it('reverts', async function () {
  39. await assertRevert(this.token.mint(anyone, amount, { from }));
  40. });
  41. });
  42. });
  43. });
  44. }
  45. module.exports = {
  46. shouldBehaveLikeERC20Mintable,
  47. };