Files
openzeppelin-contracts/test/token/ERC20/ERC20Pausable.test.js
Nicolás Venturo 5dfe7215a9 Migrate Contracts to Solidity v0.6 (#2080)
* Initial migration to Solidity 0.6.x - v3.0 first steps (#2063)

* Initial migration, missing GSN, 721, 777 and Crowdsales.

* Add _beforeTokenOperation and _afterTokenOperation.

* Add documentation for hooks.

* Add hooks doc

* Add missing drafts

* Add back ERC721 with hooks

* Bring back ERC777

* Notes on hooks

* Bring back GSN

* Make functions virtual

* Make GSN overrides explicit

* Fix ERC20Pausable tests

* Remove virtual from some view functions

* Update linter

* Delete examples

* Remove unnecessary virtual

* Remove roles from Pausable

* Remove roles

* Remove users of roles

* Adapt ERC20 tests

* Fix ERC721 tests

* Add all ERC721 hooks

* Add ERC777 hooks

* Fix remaining tests

* Bump compiler version

* Move 721BurnableMock into mocks directory

* Remove _before hooks

* Fix tests

* Upgrade linter

* Put modifiers last

* Remove _beforeTokenApproval and _beforeOperatorApproval hooks
2020-02-14 11:12:32 -03:00

80 lines
2.9 KiB
JavaScript

const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const ERC20PausableMock = contract.fromArtifact('ERC20PausableMock');
describe('ERC20Pausable', function () {
const [ holder, recipient, anotherAccount ] = accounts;
const initialSupply = new BN(100);
beforeEach(async function () {
this.token = await ERC20PausableMock.new(holder, initialSupply);
});
describe('pausable token', function () {
describe('transfer', function () {
it('allows to transfer when unpaused', async function () {
await this.token.transfer(recipient, initialSupply, { from: holder });
expect(await this.token.balanceOf(holder)).to.be.bignumber.equal('0');
expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(initialSupply);
});
it('allows to transfer when paused and then unpaused', async function () {
await this.token.pause();
await this.token.unpause();
await this.token.transfer(recipient, initialSupply, { from: holder });
expect(await this.token.balanceOf(holder)).to.be.bignumber.equal('0');
expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(initialSupply);
});
it('reverts when trying to transfer when paused', async function () {
await this.token.pause();
await expectRevert(this.token.transfer(recipient, initialSupply, { from: holder }),
'ERC20Pausable: token transfer while paused'
);
});
});
describe('transfer from', function () {
const allowance = new BN(40);
beforeEach(async function () {
await this.token.approve(anotherAccount, allowance, { from: holder });
});
it('allows to transfer from when unpaused', async function () {
await this.token.transferFrom(holder, recipient, allowance, { from: anotherAccount });
expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(allowance);
expect(await this.token.balanceOf(holder)).to.be.bignumber.equal(initialSupply.sub(allowance));
});
it('allows to transfer when paused and then unpaused', async function () {
await this.token.pause();
await this.token.unpause();
await this.token.transferFrom(holder, recipient, allowance, { from: anotherAccount });
expect(await this.token.balanceOf(recipient)).to.be.bignumber.equal(allowance);
expect(await this.token.balanceOf(holder)).to.be.bignumber.equal(initialSupply.sub(allowance));
});
it('reverts when trying to transfer from when paused', async function () {
await this.token.pause();
await expectRevert(this.token.transferFrom(
holder, recipient, allowance, { from: anotherAccount }), 'ERC20Pausable: token transfer while paused'
);
});
});
});
});