ERC20Mintable.behavior.js 1.6 KB

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