ERC20Mintable.behavior.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const { assertRevert } = require('../../../helpers/assertRevert');
  2. const expectEvent = require('../../../helpers/expectEvent');
  3. const BigNumber = web3.BigNumber;
  4. require('chai')
  5. .use(require('chai-bignumber')(BigNumber))
  6. .should();
  7. function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
  8. const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
  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. };