ERC20Mintable.behavior.js 1.6 KB

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