Migrate all ERC20 tests.
This commit is contained in:
@ -1,11 +1,8 @@
|
||||
const shouldFail = require('../helpers/shouldFail');
|
||||
const expectEvent = require('../helpers/expectEvent');
|
||||
const { expectEvent, shouldFail } = require('openzeppelin-test-helpers');
|
||||
|
||||
const PausableMock = artifacts.require('PausableMock');
|
||||
const { shouldBehaveLikePublicRole } = require('../access/roles/PublicRole.behavior');
|
||||
|
||||
require('../helpers/setup');
|
||||
|
||||
contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts]) {
|
||||
beforeEach(async function () {
|
||||
this.pausable = await PausableMock.new({ from: pauser });
|
||||
@ -26,10 +23,10 @@ contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts
|
||||
});
|
||||
|
||||
it('can perform normal process in non-pause', async function () {
|
||||
(await this.pausable.count()).should.be.bignumber.equal(0);
|
||||
(await this.pausable.count()).should.be.bignumber.equal('0');
|
||||
|
||||
await this.pausable.normalProcess({ from: anyone });
|
||||
(await this.pausable.count()).should.be.bignumber.equal(1);
|
||||
(await this.pausable.count()).should.be.bignumber.equal('1');
|
||||
});
|
||||
|
||||
it('cannot take drastic measure in non-pause', async function () {
|
||||
@ -89,9 +86,9 @@ contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts
|
||||
});
|
||||
|
||||
it('should resume allowing normal process', async function () {
|
||||
(await this.pausable.count()).should.be.bignumber.equal(0);
|
||||
(await this.pausable.count()).should.be.bignumber.equal('0');
|
||||
await this.pausable.normalProcess({ from: anyone });
|
||||
(await this.pausable.count()).should.be.bignumber.equal(1);
|
||||
(await this.pausable.count()).should.be.bignumber.equal('1');
|
||||
});
|
||||
|
||||
it('should prevent drastic measure', async function () {
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
const { BN } = require('openzeppelin-test-helpers');
|
||||
|
||||
const { shouldBehaveLikeERC20Burnable } = require('./behaviors/ERC20Burnable.behavior');
|
||||
const ERC20BurnableMock = artifacts.require('ERC20BurnableMock');
|
||||
|
||||
contract('ERC20Burnable', function ([_, owner, ...otherAccounts]) {
|
||||
const initialBalance = 1000;
|
||||
const initialBalance = new BN(1000);
|
||||
|
||||
beforeEach(async function () {
|
||||
this.token = await ERC20BurnableMock.new(owner, initialBalance, { from: owner });
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
const shouldFail = require('../../helpers/shouldFail');
|
||||
const { ether } = require('../../helpers/ether');
|
||||
const { BN, ether, shouldFail } = require('openzeppelin-test-helpers');
|
||||
const { shouldBehaveLikeERC20Mintable } = require('./behaviors/ERC20Mintable.behavior');
|
||||
const { shouldBehaveLikeERC20Capped } = require('./behaviors/ERC20Capped.behavior');
|
||||
|
||||
const ERC20Capped = artifacts.require('ERC20Capped');
|
||||
|
||||
contract('ERC20Capped', function ([_, minter, ...otherAccounts]) {
|
||||
const cap = ether(1000);
|
||||
const cap = ether('1000');
|
||||
|
||||
it('requires a non-zero cap', async function () {
|
||||
await shouldFail.reverting(
|
||||
ERC20Capped.new(0, { from: minter })
|
||||
ERC20Capped.new(new BN(0), { from: minter })
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
require('../../helpers/setup');
|
||||
const { BN } = require('openzeppelin-test-helpers');
|
||||
|
||||
const ERC20DetailedMock = artifacts.require('ERC20DetailedMock');
|
||||
|
||||
contract('ERC20Detailed', function () {
|
||||
const _name = 'My Detailed ERC20';
|
||||
const _symbol = 'MDT';
|
||||
const _decimals = 18;
|
||||
const _decimals = new BN(18);
|
||||
|
||||
beforeEach(async function () {
|
||||
this.detailedERC20 = await ERC20DetailedMock.new(_name, _symbol, _decimals);
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
const expectEvent = require('../../helpers/expectEvent');
|
||||
const shouldFail = require('../../helpers/shouldFail');
|
||||
const { BN, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
|
||||
|
||||
const ERC20PausableMock = artifacts.require('ERC20PausableMock');
|
||||
const { shouldBehaveLikePublicRole } = require('../../access/roles/PublicRole.behavior');
|
||||
|
||||
contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherAccount, ...otherAccounts]) {
|
||||
const initialSupply = new BN(100);
|
||||
|
||||
beforeEach(async function () {
|
||||
this.token = await ERC20PausableMock.new(pauser, 100, { from: pauser });
|
||||
this.token = await ERC20PausableMock.new(pauser, initialSupply, { from: pauser });
|
||||
});
|
||||
|
||||
describe('pauser role', function () {
|
||||
@ -114,132 +115,142 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA
|
||||
|
||||
describe('transfer', function () {
|
||||
it('allows to transfer when unpaused', async function () {
|
||||
await this.token.transfer(recipient, 100, { from: pauser });
|
||||
await this.token.transfer(recipient, initialSupply, { from: pauser });
|
||||
|
||||
(await this.token.balanceOf(pauser)).should.be.bignumber.equal(0);
|
||||
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(100);
|
||||
(await this.token.balanceOf(pauser)).should.be.bignumber.equal('0');
|
||||
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(initialSupply);
|
||||
});
|
||||
|
||||
it('allows to transfer when paused and then unpaused', async function () {
|
||||
await this.token.pause({ from: pauser });
|
||||
await this.token.unpause({ from: pauser });
|
||||
|
||||
await this.token.transfer(recipient, 100, { from: pauser });
|
||||
await this.token.transfer(recipient, initialSupply, { from: pauser });
|
||||
|
||||
(await this.token.balanceOf(pauser)).should.be.bignumber.equal(0);
|
||||
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(100);
|
||||
(await this.token.balanceOf(pauser)).should.be.bignumber.equal('0');
|
||||
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(initialSupply);
|
||||
});
|
||||
|
||||
it('reverts when trying to transfer when paused', async function () {
|
||||
await this.token.pause({ from: pauser });
|
||||
|
||||
await shouldFail.reverting(this.token.transfer(recipient, 100, { from: pauser }));
|
||||
await shouldFail.reverting(this.token.transfer(recipient, initialSupply, { from: pauser }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('approve', function () {
|
||||
it('allows to approve when unpaused', async function () {
|
||||
await this.token.approve(anotherAccount, 40, { from: pauser });
|
||||
const allowance = new BN(40);
|
||||
|
||||
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(40);
|
||||
it('allows to approve when unpaused', async function () {
|
||||
await this.token.approve(anotherAccount, allowance, { from: pauser });
|
||||
|
||||
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance);
|
||||
});
|
||||
|
||||
it('allows to approve when paused and then unpaused', async function () {
|
||||
await this.token.pause({ from: pauser });
|
||||
await this.token.unpause({ from: pauser });
|
||||
|
||||
await this.token.approve(anotherAccount, 40, { from: pauser });
|
||||
await this.token.approve(anotherAccount, allowance, { from: pauser });
|
||||
|
||||
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(40);
|
||||
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance);
|
||||
});
|
||||
|
||||
it('reverts when trying to approve when paused', async function () {
|
||||
await this.token.pause({ from: pauser });
|
||||
|
||||
await shouldFail.reverting(this.token.approve(anotherAccount, 40, { from: pauser }));
|
||||
await shouldFail.reverting(this.token.approve(anotherAccount, allowance, { from: pauser }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('transfer from', function () {
|
||||
const allowance = new BN(40);
|
||||
|
||||
beforeEach(async function () {
|
||||
await this.token.approve(anotherAccount, 50, { from: pauser });
|
||||
await this.token.approve(anotherAccount, allowance, { from: pauser });
|
||||
});
|
||||
|
||||
it('allows to transfer from when unpaused', async function () {
|
||||
await this.token.transferFrom(pauser, recipient, 40, { from: anotherAccount });
|
||||
await this.token.transferFrom(pauser, recipient, allowance, { from: anotherAccount });
|
||||
|
||||
(await this.token.balanceOf(pauser)).should.be.bignumber.equal(60);
|
||||
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(40);
|
||||
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(allowance);
|
||||
(await this.token.balanceOf(pauser)).should.be.bignumber.equal(initialSupply.sub(allowance));
|
||||
});
|
||||
|
||||
it('allows to transfer when paused and then unpaused', async function () {
|
||||
await this.token.pause({ from: pauser });
|
||||
await this.token.unpause({ from: pauser });
|
||||
|
||||
await this.token.transferFrom(pauser, recipient, 40, { from: anotherAccount });
|
||||
await this.token.transferFrom(pauser, recipient, allowance, { from: anotherAccount });
|
||||
|
||||
(await this.token.balanceOf(pauser)).should.be.bignumber.equal(60);
|
||||
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(40);
|
||||
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(allowance);
|
||||
(await this.token.balanceOf(pauser)).should.be.bignumber.equal(initialSupply.sub(allowance));
|
||||
});
|
||||
|
||||
it('reverts when trying to transfer from when paused', async function () {
|
||||
await this.token.pause({ from: pauser });
|
||||
|
||||
await shouldFail.reverting(this.token.transferFrom(pauser, recipient, 40, { from: anotherAccount }));
|
||||
await shouldFail.reverting(this.token.transferFrom(pauser, recipient, allowance, { from: anotherAccount }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('decrease approval', function () {
|
||||
const allowance = new BN(40);
|
||||
const decrement = new BN(10);
|
||||
|
||||
beforeEach(async function () {
|
||||
await this.token.approve(anotherAccount, 100, { from: pauser });
|
||||
await this.token.approve(anotherAccount, allowance, { from: pauser });
|
||||
});
|
||||
|
||||
it('allows to decrease approval when unpaused', async function () {
|
||||
await this.token.decreaseAllowance(anotherAccount, 40, { from: pauser });
|
||||
await this.token.decreaseAllowance(anotherAccount, decrement, { from: pauser });
|
||||
|
||||
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(60);
|
||||
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance.sub(decrement));
|
||||
});
|
||||
|
||||
it('allows to decrease approval when paused and then unpaused', async function () {
|
||||
await this.token.pause({ from: pauser });
|
||||
await this.token.unpause({ from: pauser });
|
||||
|
||||
await this.token.decreaseAllowance(anotherAccount, 40, { from: pauser });
|
||||
await this.token.decreaseAllowance(anotherAccount, decrement, { from: pauser });
|
||||
|
||||
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(60);
|
||||
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance.sub(decrement));
|
||||
});
|
||||
|
||||
it('reverts when trying to transfer when paused', async function () {
|
||||
await this.token.pause({ from: pauser });
|
||||
|
||||
await shouldFail.reverting(this.token.decreaseAllowance(anotherAccount, 40, { from: pauser }));
|
||||
await shouldFail.reverting(this.token.decreaseAllowance(anotherAccount, decrement, { from: pauser }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('increase approval', function () {
|
||||
const allowance = new BN(40);
|
||||
const increment = new BN(30);
|
||||
|
||||
beforeEach(async function () {
|
||||
await this.token.approve(anotherAccount, 100, { from: pauser });
|
||||
await this.token.approve(anotherAccount, allowance, { from: pauser });
|
||||
});
|
||||
|
||||
it('allows to increase approval when unpaused', async function () {
|
||||
await this.token.increaseAllowance(anotherAccount, 40, { from: pauser });
|
||||
await this.token.increaseAllowance(anotherAccount, increment, { from: pauser });
|
||||
|
||||
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(140);
|
||||
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance.add(increment));
|
||||
});
|
||||
|
||||
it('allows to increase approval when paused and then unpaused', async function () {
|
||||
await this.token.pause({ from: pauser });
|
||||
await this.token.unpause({ from: pauser });
|
||||
|
||||
await this.token.increaseAllowance(anotherAccount, 40, { from: pauser });
|
||||
await this.token.increaseAllowance(anotherAccount, increment, { from: pauser });
|
||||
|
||||
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(140);
|
||||
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance.add(increment));
|
||||
});
|
||||
|
||||
it('reverts when trying to increase approval when paused', async function () {
|
||||
await this.token.pause({ from: pauser });
|
||||
|
||||
await shouldFail.reverting(this.token.increaseAllowance(anotherAccount, 40, { from: pauser }));
|
||||
await shouldFail.reverting(this.token.increaseAllowance(anotherAccount, increment, { from: pauser }));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
const shouldFail = require('../../helpers/shouldFail');
|
||||
|
||||
require('../../helpers/setup');
|
||||
const { shouldFail } = require('openzeppelin-test-helpers');
|
||||
|
||||
const SafeERC20Helper = artifacts.require('SafeERC20Helper');
|
||||
|
||||
|
||||
@ -1,13 +1,10 @@
|
||||
const shouldFail = require('../../helpers/shouldFail');
|
||||
const time = require('../../helpers/time');
|
||||
|
||||
const { BigNumber } = require('../../helpers/setup');
|
||||
const { BN, shouldFail, time } = require('openzeppelin-test-helpers');
|
||||
|
||||
const ERC20Mintable = artifacts.require('ERC20Mintable');
|
||||
const TokenTimelock = artifacts.require('TokenTimelock');
|
||||
|
||||
contract('TokenTimelock', function ([_, minter, beneficiary]) {
|
||||
const amount = new BigNumber(100);
|
||||
const amount = new BN(100);
|
||||
|
||||
context('with token', function () {
|
||||
beforeEach(async function () {
|
||||
@ -15,7 +12,7 @@ contract('TokenTimelock', function ([_, minter, beneficiary]) {
|
||||
});
|
||||
|
||||
it('rejects a release time in the past', async function () {
|
||||
const pastReleaseTime = (await time.latest()) - time.duration.years(1);
|
||||
const pastReleaseTime = (await time.latest()).sub(time.duration.years(1));
|
||||
await shouldFail.reverting(
|
||||
TokenTimelock.new(this.token.address, beneficiary, pastReleaseTime)
|
||||
);
|
||||
@ -23,7 +20,7 @@ contract('TokenTimelock', function ([_, minter, beneficiary]) {
|
||||
|
||||
context('once deployed', function () {
|
||||
beforeEach(async function () {
|
||||
this.releaseTime = (await time.latest()) + time.duration.years(1);
|
||||
this.releaseTime = (await time.latest()).add(time.duration.years(1));
|
||||
this.timelock = await TokenTimelock.new(this.token.address, beneficiary, this.releaseTime);
|
||||
await this.token.mint(this.timelock.address, amount, { from: minter });
|
||||
});
|
||||
@ -39,24 +36,24 @@ contract('TokenTimelock', function ([_, minter, beneficiary]) {
|
||||
});
|
||||
|
||||
it('cannot be released just before time limit', async function () {
|
||||
await time.increaseTo(this.releaseTime - time.duration.seconds(3));
|
||||
await time.increaseTo(this.releaseTime.sub(time.duration.seconds(3)));
|
||||
await shouldFail.reverting(this.timelock.release());
|
||||
});
|
||||
|
||||
it('can be released just after limit', async function () {
|
||||
await time.increaseTo(this.releaseTime + time.duration.seconds(1));
|
||||
await time.increaseTo(this.releaseTime.add(time.duration.seconds(1)));
|
||||
await this.timelock.release();
|
||||
(await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount);
|
||||
});
|
||||
|
||||
it('can be released after time limit', async function () {
|
||||
await time.increaseTo(this.releaseTime + time.duration.years(1));
|
||||
await time.increaseTo(this.releaseTime.add(time.duration.years(1)));
|
||||
await this.timelock.release();
|
||||
(await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount);
|
||||
});
|
||||
|
||||
it('cannot be released twice', async function () {
|
||||
await time.increaseTo(this.releaseTime + time.duration.years(1));
|
||||
await time.increaseTo(this.releaseTime.add(time.duration.years(1)));
|
||||
await this.timelock.release();
|
||||
await shouldFail.reverting(this.timelock.release());
|
||||
(await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount);
|
||||
|
||||
@ -1,18 +1,14 @@
|
||||
const shouldFail = require('../../../helpers/shouldFail');
|
||||
const expectEvent = require('../../../helpers/expectEvent');
|
||||
const { ZERO_ADDRESS } = require('../../../helpers/constants');
|
||||
|
||||
require('../../../helpers/setup');
|
||||
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
|
||||
|
||||
function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
|
||||
describe('burn', function () {
|
||||
describe('when the given amount is not greater than balance of the sender', function () {
|
||||
context('for a zero amount', function () {
|
||||
shouldBurn(0);
|
||||
shouldBurn(new BN(0));
|
||||
});
|
||||
|
||||
context('for a non-zero amount', function () {
|
||||
shouldBurn(100);
|
||||
shouldBurn(new BN(100));
|
||||
});
|
||||
|
||||
function shouldBurn (amount) {
|
||||
@ -21,13 +17,13 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
|
||||
});
|
||||
|
||||
it('burns the requested amount', async function () {
|
||||
(await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance - amount);
|
||||
(await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance.sub(amount));
|
||||
});
|
||||
|
||||
it('emits a transfer event', async function () {
|
||||
expectEvent.inLogs(this.logs, 'Transfer', {
|
||||
from: owner,
|
||||
to: ZERO_ADDRESS,
|
||||
to: constants.ZERO_ADDRESS,
|
||||
value: amount,
|
||||
});
|
||||
});
|
||||
@ -35,7 +31,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
|
||||
});
|
||||
|
||||
describe('when the given amount is greater than the balance of the sender', function () {
|
||||
const amount = initialBalance + 1;
|
||||
const amount = initialBalance.addn(1);
|
||||
|
||||
it('reverts', async function () {
|
||||
await shouldFail.reverting(this.token.burn(amount, { from: owner }));
|
||||
@ -46,15 +42,15 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
|
||||
describe('burnFrom', function () {
|
||||
describe('on success', function () {
|
||||
context('for a zero amount', function () {
|
||||
shouldBurnFrom(0);
|
||||
shouldBurnFrom(new BN(0));
|
||||
});
|
||||
|
||||
context('for a non-zero amount', function () {
|
||||
shouldBurnFrom(100);
|
||||
shouldBurnFrom(new BN(100));
|
||||
});
|
||||
|
||||
function shouldBurnFrom (amount) {
|
||||
const originalAllowance = amount * 3;
|
||||
const originalAllowance = amount.muln(3);
|
||||
|
||||
beforeEach(async function () {
|
||||
await this.token.approve(burner, originalAllowance, { from: owner });
|
||||
@ -63,17 +59,17 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
|
||||
});
|
||||
|
||||
it('burns the requested amount', async function () {
|
||||
(await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance - amount);
|
||||
(await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance.sub(amount));
|
||||
});
|
||||
|
||||
it('decrements allowance', async function () {
|
||||
(await this.token.allowance(owner, burner)).should.be.bignumber.equal(originalAllowance - amount);
|
||||
(await this.token.allowance(owner, burner)).should.be.bignumber.equal(originalAllowance.sub(amount));
|
||||
});
|
||||
|
||||
it('emits a transfer event', async function () {
|
||||
expectEvent.inLogs(this.logs, 'Transfer', {
|
||||
from: owner,
|
||||
to: ZERO_ADDRESS,
|
||||
to: constants.ZERO_ADDRESS,
|
||||
value: amount,
|
||||
});
|
||||
});
|
||||
@ -81,7 +77,8 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
|
||||
});
|
||||
|
||||
describe('when the given amount is greater than the balance of the sender', function () {
|
||||
const amount = initialBalance + 1;
|
||||
const amount = initialBalance.addn(1);
|
||||
|
||||
it('reverts', async function () {
|
||||
await this.token.approve(burner, amount, { from: owner });
|
||||
await shouldFail.reverting(this.token.burnFrom(owner, amount, { from: burner }));
|
||||
@ -89,10 +86,11 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
|
||||
});
|
||||
|
||||
describe('when the given amount is greater than the allowance', function () {
|
||||
const amount = 100;
|
||||
const allowance = new BN(100);
|
||||
|
||||
it('reverts', async function () {
|
||||
await this.token.approve(burner, amount - 1, { from: owner });
|
||||
await shouldFail.reverting(this.token.burnFrom(owner, amount, { from: burner }));
|
||||
await this.token.approve(burner, allowance, { from: owner });
|
||||
await shouldFail.reverting(this.token.burnFrom(owner, allowance.addn(1), { from: burner }));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
const shouldFail = require('../../../helpers/shouldFail');
|
||||
|
||||
require('../../../helpers/setup');
|
||||
const { shouldFail } = require('openzeppelin-test-helpers');
|
||||
|
||||
function shouldBehaveLikeERC20Capped (minter, [anyone], cap) {
|
||||
describe('capped token', function () {
|
||||
@ -11,13 +9,13 @@ function shouldBehaveLikeERC20Capped (minter, [anyone], cap) {
|
||||
});
|
||||
|
||||
it('should mint when amount is less than cap', async function () {
|
||||
await this.token.mint(anyone, cap.sub(1), { from });
|
||||
(await this.token.totalSupply()).should.be.bignumber.equal(cap.sub(1));
|
||||
await this.token.mint(anyone, cap.subn(1), { from });
|
||||
(await this.token.totalSupply()).should.be.bignumber.equal(cap.subn(1));
|
||||
});
|
||||
|
||||
it('should fail to mint if the ammount exceeds the cap', async function () {
|
||||
await this.token.mint(anyone, cap.sub(1), { from });
|
||||
await shouldFail.reverting(this.token.mint(anyone, 100, { from }));
|
||||
it('should fail to mint if the amount exceeds the cap', async function () {
|
||||
await this.token.mint(anyone, cap.subn(1), { from });
|
||||
await shouldFail.reverting(this.token.mint(anyone, 2, { from }));
|
||||
});
|
||||
|
||||
it('should fail to mint after cap is reached', async function () {
|
||||
|
||||
@ -1,19 +1,15 @@
|
||||
const shouldFail = require('../../../helpers/shouldFail');
|
||||
const expectEvent = require('../../../helpers/expectEvent');
|
||||
const { ZERO_ADDRESS } = require('../../../helpers/constants');
|
||||
|
||||
require('../../../helpers/setup');
|
||||
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
|
||||
|
||||
function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
|
||||
describe('as a mintable token', function () {
|
||||
describe('mint', function () {
|
||||
const amount = 100;
|
||||
const amount = new BN(100);
|
||||
|
||||
context('when the sender has minting permission', function () {
|
||||
const from = minter;
|
||||
|
||||
context('for a zero amount', function () {
|
||||
shouldMint(0);
|
||||
shouldMint(new BN(0));
|
||||
});
|
||||
|
||||
context('for a non-zero amount', function () {
|
||||
@ -31,7 +27,7 @@ function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
|
||||
|
||||
it('emits a mint and a transfer event', async function () {
|
||||
expectEvent.inLogs(this.logs, 'Transfer', {
|
||||
from: ZERO_ADDRESS,
|
||||
from: constants.ZERO_ADDRESS,
|
||||
to: anyone,
|
||||
value: amount,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user