ERC20Capped.behavior.js 1.0 KB

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