ERC20Capped.behavior.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. const { expect } = require('chai');
  2. const { expectRevertCustomError } = require('../../../helpers/customError');
  3. function shouldBehaveLikeERC20Capped(accounts, cap) {
  4. describe('capped token', function () {
  5. const user = accounts[0];
  6. it('starts with the correct cap', async function () {
  7. expect(await this.token.cap()).to.be.bignumber.equal(cap);
  8. });
  9. it('mints when amount is less than cap', async function () {
  10. await this.token.$_mint(user, cap.subn(1));
  11. expect(await this.token.totalSupply()).to.be.bignumber.equal(cap.subn(1));
  12. });
  13. it('fails to mint if the amount exceeds the cap', async function () {
  14. await this.token.$_mint(user, cap.subn(1));
  15. await expectRevertCustomError(this.token.$_mint(user, 2), 'ERC20ExceededCap', [cap.addn(1), cap]);
  16. });
  17. it('fails to mint after cap is reached', async function () {
  18. await this.token.$_mint(user, cap);
  19. await expectRevertCustomError(this.token.$_mint(user, 1), 'ERC20ExceededCap', [cap.addn(1), cap]);
  20. });
  21. });
  22. }
  23. module.exports = {
  24. shouldBehaveLikeERC20Capped,
  25. };