You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
4.5 KiB
135 lines
4.5 KiB
5 years ago
|
const { BN, expectRevert } = require('@openzeppelin/test-helpers');
|
||
6 years ago
|
|
||
6 years ago
|
const { expect } = require('chai');
|
||
|
|
||
4 years ago
|
const ERC20PausableMock = artifacts.require('ERC20PausableMock');
|
||
8 years ago
|
|
||
4 years ago
|
contract('ERC20Pausable', function (accounts) {
|
||
5 years ago
|
const [ holder, recipient, anotherAccount ] = accounts;
|
||
5 years ago
|
|
||
6 years ago
|
const initialSupply = new BN(100);
|
||
|
|
||
5 years ago
|
const name = 'My Token';
|
||
|
const symbol = 'MTKN';
|
||
|
|
||
7 years ago
|
beforeEach(async function () {
|
||
5 years ago
|
this.token = await ERC20PausableMock.new(name, symbol, holder, initialSupply);
|
||
8 years ago
|
});
|
||
|
|
||
7 years ago
|
describe('pausable token', function () {
|
||
|
describe('transfer', function () {
|
||
|
it('allows to transfer when unpaused', async function () {
|
||
5 years ago
|
await this.token.transfer(recipient, initialSupply, { from: holder });
|
||
7 years ago
|
|
||
5 years ago
|
expect(await this.token.balanceOf(holder)).to.be.bignumber.equal('0');
|
||
6 years ago
|
expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(initialSupply);
|
||
7 years ago
|
});
|
||
|
|
||
|
it('allows to transfer when paused and then unpaused', async function () {
|
||
5 years ago
|
await this.token.pause();
|
||
|
await this.token.unpause();
|
||
7 years ago
|
|
||
5 years ago
|
await this.token.transfer(recipient, initialSupply, { from: holder });
|
||
7 years ago
|
|
||
5 years ago
|
expect(await this.token.balanceOf(holder)).to.be.bignumber.equal('0');
|
||
6 years ago
|
expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(initialSupply);
|
||
7 years ago
|
});
|
||
|
|
||
|
it('reverts when trying to transfer when paused', async function () {
|
||
5 years ago
|
await this.token.pause();
|
||
7 years ago
|
|
||
5 years ago
|
await expectRevert(this.token.transfer(recipient, initialSupply, { from: holder }),
|
||
4 years ago
|
'ERC20Pausable: token transfer while paused',
|
||
6 years ago
|
);
|
||
7 years ago
|
});
|
||
|
});
|
||
|
|
||
|
describe('transfer from', function () {
|
||
6 years ago
|
const allowance = new BN(40);
|
||
|
|
||
7 years ago
|
beforeEach(async function () {
|
||
5 years ago
|
await this.token.approve(anotherAccount, allowance, { from: holder });
|
||
7 years ago
|
});
|
||
|
|
||
|
it('allows to transfer from when unpaused', async function () {
|
||
5 years ago
|
await this.token.transferFrom(holder, recipient, allowance, { from: anotherAccount });
|
||
7 years ago
|
|
||
6 years ago
|
expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(allowance);
|
||
5 years ago
|
expect(await this.token.balanceOf(holder)).to.be.bignumber.equal(initialSupply.sub(allowance));
|
||
7 years ago
|
});
|
||
|
|
||
|
it('allows to transfer when paused and then unpaused', async function () {
|
||
5 years ago
|
await this.token.pause();
|
||
|
await this.token.unpause();
|
||
7 years ago
|
|
||
5 years ago
|
await this.token.transferFrom(holder, recipient, allowance, { from: anotherAccount });
|
||
7 years ago
|
|
||
6 years ago
|
expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(allowance);
|
||
5 years ago
|
expect(await this.token.balanceOf(holder)).to.be.bignumber.equal(initialSupply.sub(allowance));
|
||
7 years ago
|
});
|
||
|
|
||
|
it('reverts when trying to transfer from when paused', async function () {
|
||
5 years ago
|
await this.token.pause();
|
||
7 years ago
|
|
||
6 years ago
|
await expectRevert(this.token.transferFrom(
|
||
4 years ago
|
holder, recipient, allowance, { from: anotherAccount }), 'ERC20Pausable: token transfer while paused',
|
||
6 years ago
|
);
|
||
7 years ago
|
});
|
||
|
});
|
||
5 years ago
|
|
||
|
describe('mint', function () {
|
||
|
const amount = new BN('42');
|
||
|
|
||
|
it('allows to mint when unpaused', async function () {
|
||
|
await this.token.mint(recipient, amount);
|
||
|
|
||
|
expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(amount);
|
||
|
});
|
||
|
|
||
|
it('allows to mint when paused and then unpaused', async function () {
|
||
|
await this.token.pause();
|
||
|
await this.token.unpause();
|
||
|
|
||
|
await this.token.mint(recipient, amount);
|
||
|
|
||
|
expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(amount);
|
||
|
});
|
||
|
|
||
|
it('reverts when trying to mint when paused', async function () {
|
||
|
await this.token.pause();
|
||
|
|
||
|
await expectRevert(this.token.mint(recipient, amount),
|
||
4 years ago
|
'ERC20Pausable: token transfer while paused',
|
||
5 years ago
|
);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('burn', function () {
|
||
|
const amount = new BN('42');
|
||
|
|
||
|
it('allows to burn when unpaused', async function () {
|
||
|
await this.token.burn(holder, amount);
|
||
|
|
||
|
expect(await this.token.balanceOf(holder)).to.be.bignumber.equal(initialSupply.sub(amount));
|
||
|
});
|
||
|
|
||
|
it('allows to burn when paused and then unpaused', async function () {
|
||
|
await this.token.pause();
|
||
|
await this.token.unpause();
|
||
|
|
||
|
await this.token.burn(holder, amount);
|
||
|
|
||
|
expect(await this.token.balanceOf(holder)).to.be.bignumber.equal(initialSupply.sub(amount));
|
||
|
});
|
||
|
|
||
|
it('reverts when trying to burn when paused', async function () {
|
||
|
await this.token.pause();
|
||
|
|
||
|
await expectRevert(this.token.burn(holder, amount),
|
||
4 years ago
|
'ERC20Pausable: token transfer while paused',
|
||
5 years ago
|
);
|
||
|
});
|
||
|
});
|
||
8 years ago
|
});
|
||
7 years ago
|
});
|