ERC20Capped.behavior.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. const { expectRevert } = require('@openzeppelin/test-helpers');
  2. const { expect } = require('chai');
  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 expectRevert(this.token.$_mint(user, 2), 'ERC20Capped: cap exceeded');
  16. });
  17. it('fails to mint after cap is reached', async function () {
  18. await this.token.$_mint(user, cap);
  19. await expectRevert(this.token.$_mint(user, 1), 'ERC20Capped: cap exceeded');
  20. });
  21. });
  22. }
  23. module.exports = {
  24. shouldBehaveLikeERC20Capped,
  25. };