ERC20Mintable.behavior.js 1.6 KB

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