Add TimedCrowdsale::_extendTime (#1636)
* Add TimedCrowdsale::_extendTime * Add tests for TimedCrowdsale extending method * Reverse event arguments order * Rename method argument * Refactor TimedCrowdsale test * Simplify TimedCrowdsaleImpl * Fix extendTime method behaviour to deny TimedCrowdsale re-opening after it was ended * Append chengelog * Update CHANGELOG.md Co-Authored-By: k06a <k06aaa@gmail.com> * Update contracts/crowdsale/validation/TimedCrowdsale.sol Co-Authored-By: k06a <k06aaa@gmail.com> * Improve tests
This commit is contained in:
committed by
Nicolás Venturo
parent
3772233cf5
commit
352ec94579
@ -1,4 +1,4 @@
|
||||
const { BN, ether, shouldFail, time } = require('openzeppelin-test-helpers');
|
||||
const { BN, ether, expectEvent, shouldFail, time } = require('openzeppelin-test-helpers');
|
||||
|
||||
const TimedCrowdsaleImpl = artifacts.require('TimedCrowdsaleImpl');
|
||||
const SimpleToken = artifacts.require('SimpleToken');
|
||||
@ -73,5 +73,62 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) {
|
||||
await shouldFail.reverting(this.crowdsale.buyTokens(investor, { value: value, from: purchaser }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('extending closing time', function () {
|
||||
it('should not reduce duration', async function () {
|
||||
// Same date
|
||||
await shouldFail.reverting(this.crowdsale.extendTime(this.closingTime));
|
||||
|
||||
// Prescending date
|
||||
const newClosingTime = this.closingTime.sub(time.duration.seconds(1));
|
||||
await shouldFail.reverting(this.crowdsale.extendTime(newClosingTime));
|
||||
});
|
||||
|
||||
context('before crowdsale start', function () {
|
||||
beforeEach(async function () {
|
||||
(await this.crowdsale.isOpen()).should.equal(false);
|
||||
await shouldFail.reverting(this.crowdsale.send(value));
|
||||
});
|
||||
|
||||
it('it extends end time', async function () {
|
||||
const newClosingTime = this.closingTime.add(time.duration.days(1));
|
||||
const { logs } = await this.crowdsale.extendTime(newClosingTime);
|
||||
expectEvent.inLogs(logs, 'TimedCrowdsaleExtended', {
|
||||
prevClosingTime: this.closingTime,
|
||||
newClosingTime: newClosingTime,
|
||||
});
|
||||
(await this.crowdsale.closingTime()).should.be.bignumber.equal(newClosingTime);
|
||||
});
|
||||
});
|
||||
|
||||
context('after crowdsale start', function () {
|
||||
beforeEach(async function () {
|
||||
await time.increaseTo(this.openingTime);
|
||||
(await this.crowdsale.isOpen()).should.equal(true);
|
||||
await this.crowdsale.send(value);
|
||||
});
|
||||
|
||||
it('it extends end time', async function () {
|
||||
const newClosingTime = this.closingTime.add(time.duration.days(1));
|
||||
const { logs } = await this.crowdsale.extendTime(newClosingTime);
|
||||
expectEvent.inLogs(logs, 'TimedCrowdsaleExtended', {
|
||||
prevClosingTime: this.closingTime,
|
||||
newClosingTime: newClosingTime,
|
||||
});
|
||||
(await this.crowdsale.closingTime()).should.be.bignumber.equal(newClosingTime);
|
||||
});
|
||||
});
|
||||
|
||||
context('after crowdsale end', function () {
|
||||
beforeEach(async function () {
|
||||
await time.increaseTo(this.afterClosingTime);
|
||||
});
|
||||
|
||||
it('it reverts', async function () {
|
||||
const newClosingTime = await time.latest();
|
||||
await shouldFail.reverting(this.crowdsale.extendTime(newClosingTime));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user