From 2e848e12d118a9975b8b79bb018d007c430c4f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Thu, 18 Oct 2018 16:36:27 -0300 Subject: [PATCH] IncPriceCrowdsale consistently returns 0 outside of the crowdsale window. (#1442) (cherry picked from commit 9155bfe27f2ad2423e5ec5d4205cc42cc4aba566) --- contracts/crowdsale/price/IncreasingPriceCrowdsale.sol | 4 ++++ test/crowdsale/IncreasingPriceCrowdsale.test.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol b/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol index 70189a168..4d2b44931 100644 --- a/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol +++ b/contracts/crowdsale/price/IncreasingPriceCrowdsale.sol @@ -47,6 +47,10 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale { * @return The number of tokens a buyer gets per wei at a given time */ function getCurrentRate() public view returns (uint256) { + if (!isOpen()) { + return 0; + } + // solium-disable-next-line security/no-block-members uint256 elapsedTime = block.timestamp.sub(openingTime()); uint256 timeRange = closingTime().sub(openingTime()); diff --git a/test/crowdsale/IncreasingPriceCrowdsale.test.js b/test/crowdsale/IncreasingPriceCrowdsale.test.js index a76186bbc..51946b5ee 100644 --- a/test/crowdsale/IncreasingPriceCrowdsale.test.js +++ b/test/crowdsale/IncreasingPriceCrowdsale.test.js @@ -59,6 +59,15 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser]) (await this.crowdsale.finalRate()).should.be.bignumber.equal(finalRate); }); + it('returns a rate of 0 before the crowdsale starts', async function () { + (await this.crowdsale.getCurrentRate()).should.be.bignumber.equal(0); + }); + + it('returns a rate of 0 after the crowdsale ends', async function () { + await time.increaseTo(this.afterClosingTime); + (await this.crowdsale.getCurrentRate()).should.be.bignumber.equal(0); + }); + it('at start', async function () { await time.increaseTo(this.startTime); await this.crowdsale.buyTokens(investor, { value, from: purchaser });