CappedToken.behavior.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const { expectThrow } = require('../../helpers/expectThrow');
  2. const expectEvent = require('../../helpers/expectEvent');
  3. const BigNumber = web3.BigNumber;
  4. require('chai')
  5. .use(require('chai-bignumber')(BigNumber))
  6. .should();
  7. function shouldBehaveLikeCappedToken (minter, [anyone], cap) {
  8. describe('capped token', function () {
  9. const from = minter;
  10. it('should start with the correct cap', async function () {
  11. (await this.token.cap()).should.be.bignumber.equal(cap);
  12. });
  13. it('should mint when amount is less than cap', async function () {
  14. const { logs } = await this.token.mint(anyone, cap.sub(1), { from });
  15. expectEvent.inLogs(logs, 'Mint');
  16. });
  17. it('should fail to mint if the ammount exceeds the cap', async function () {
  18. await this.token.mint(anyone, cap.sub(1), { from });
  19. await expectThrow(this.token.mint(anyone, 100, { from }));
  20. });
  21. it('should fail to mint after cap is reached', async function () {
  22. await this.token.mint(anyone, cap, { from });
  23. await expectThrow(this.token.mint(anyone, 1, { from }));
  24. });
  25. });
  26. }
  27. module.exports = {
  28. shouldBehaveLikeCappedToken,
  29. };