Files
openzeppelin-contracts/test/token/ERC20/TokenTimelock.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

71 lines
2.9 KiB
JavaScript

const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, expectRevert, time } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const ERC20Mock = contract.fromArtifact('ERC20Mock');
const TokenTimelock = contract.fromArtifact('TokenTimelock');
describe('TokenTimelock', function () {
const [ beneficiary ] = accounts;
const amount = new BN(100);
context('with token', function () {
beforeEach(async function () {
this.token = await ERC20Mock.new(beneficiary, 0); // We're not using the preminted tokens
});
it('rejects a release time in the past', async function () {
const pastReleaseTime = (await time.latest()).sub(time.duration.years(1));
await expectRevert(
TokenTimelock.new(this.token.address, beneficiary, pastReleaseTime),
'TokenTimelock: release time is before current time'
);
});
context('once deployed', function () {
beforeEach(async function () {
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);
});
it('can get state', async function () {
expect(await this.timelock.token()).to.equal(this.token.address);
expect(await this.timelock.beneficiary()).to.equal(beneficiary);
expect(await this.timelock.releaseTime()).to.be.bignumber.equal(this.releaseTime);
});
it('cannot be released before time limit', async function () {
await expectRevert(this.timelock.release(), 'TokenTimelock: current time is before release time');
});
it('cannot be released just before time limit', async function () {
await time.increaseTo(this.releaseTime.sub(time.duration.seconds(3)));
await expectRevert(this.timelock.release(), 'TokenTimelock: current time is before release time');
});
it('can be released just after limit', async function () {
await time.increaseTo(this.releaseTime.add(time.duration.seconds(1)));
await this.timelock.release();
expect(await this.token.balanceOf(beneficiary)).to.be.bignumber.equal(amount);
});
it('can be released after time limit', async function () {
await time.increaseTo(this.releaseTime.add(time.duration.years(1)));
await this.timelock.release();
expect(await this.token.balanceOf(beneficiary)).to.be.bignumber.equal(amount);
});
it('cannot be released twice', async function () {
await time.increaseTo(this.releaseTime.add(time.duration.years(1)));
await this.timelock.release();
await expectRevert(this.timelock.release(), 'TokenTimelock: no tokens to release');
expect(await this.token.balanceOf(beneficiary)).to.be.bignumber.equal(amount);
});
});
});
});