ERC20Capped.behavior.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. const { expectRevert } = require('@openzeppelin/test-helpers');
  2. const { expect } = require('chai');
  3. function shouldBehaveLikeERC20Capped (minter, [other], cap) {
  4. describe('capped token', function () {
  5. const from = minter;
  6. it('should start with the correct cap', async function () {
  7. expect(await this.token.cap()).to.be.bignumber.equal(cap);
  8. });
  9. it('should mint when amount is less than cap', async function () {
  10. await this.token.mint(other, cap.subn(1), { from });
  11. expect(await this.token.totalSupply()).to.be.bignumber.equal(cap.subn(1));
  12. });
  13. it('should fail to mint if the amount exceeds the cap', async function () {
  14. await this.token.mint(other, cap.subn(1), { from });
  15. await expectRevert(this.token.mint(other, 2, { from }), 'ERC20Capped: cap exceeded');
  16. });
  17. it('should fail to mint after cap is reached', async function () {
  18. await this.token.mint(other, cap, { from });
  19. await expectRevert(this.token.mint(other, 1, { from }), 'ERC20Capped: cap exceeded');
  20. });
  21. });
  22. }
  23. module.exports = {
  24. shouldBehaveLikeERC20Capped,
  25. };