From ecae7608f9a1eb8af0c66c393d98edac703c3d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Fri, 19 Oct 2018 15:37:24 -0300 Subject: [PATCH] InitialRate must be strictly larger than finalRate. (#1441) (cherry picked from commit a936cbf5fbe78fb160a2fa679cdf434cbed95426) --- .../crowdsale/price/IncreasingPriceCrowdsale.sol | 10 +++++++++- test/crowdsale/IncreasingPriceCrowdsale.test.js | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol b/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol index 4d2b44931..c86353c0f 100644 --- a/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol +++ b/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol @@ -22,11 +22,19 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale { */ constructor(uint256 initialRate, uint256 finalRate) internal { require(finalRate > 0); - require(initialRate >= finalRate); + require(initialRate > finalRate); _initialRate = initialRate; _finalRate = finalRate; } + /** + * The base rate function is overridden to revert, since this crowdsale doens't use it, and + * all calls to it are a mistake. + */ + function rate() public view returns(uint256) { + revert(); + } + /** * @return the initial rate of the crowdsale. */ diff --git a/test/crowdsale/IncreasingPriceCrowdsale.test.js b/test/crowdsale/IncreasingPriceCrowdsale.test.js index 51946b5ee..41906d224 100644 --- a/test/crowdsale/IncreasingPriceCrowdsale.test.js +++ b/test/crowdsale/IncreasingPriceCrowdsale.test.js @@ -34,13 +34,19 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser]) this.token = await SimpleToken.new(); }); - it('rejects a final rate larger than the initial rate', async function () { + it('reverts with a final rate larger than the initial rate', async function () { await shouldFail.reverting(IncreasingPriceCrowdsaleImpl.new( this.startTime, this.closingTime, wallet, this.token.address, initialRate, initialRate.plus(1) )); }); - it('rejects a final rate of zero', async function () { + it('reverts with a final equal to the initial rate', async function () { + await shouldFail.reverting(IncreasingPriceCrowdsaleImpl.new( + this.startTime, this.closingTime, wallet, this.token.address, initialRate, initialRate + )); + }); + + it('reverts with a final rate of zero', async function () { await shouldFail.reverting(IncreasingPriceCrowdsaleImpl.new( this.startTime, this.closingTime, wallet, this.token.address, initialRate, 0 )); @@ -59,6 +65,10 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser]) (await this.crowdsale.finalRate()).should.be.bignumber.equal(finalRate); }); + it('reverts when the base Crowdsale\'s rate function is called', async function () { + await shouldFail.reverting(this.crowdsale.rate()); + }); + it('returns a rate of 0 before the crowdsale starts', async function () { (await this.crowdsale.getCurrentRate()).should.be.bignumber.equal(0); });