Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InitialRate must be strictly larger than finalRate. #1441

Merged
merged 4 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion contracts/crowdsale/price/IncreasingPriceCrowdsale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird. Can you please add a comment with the reason?

}

/**
* @return the initial rate of the crowdsale.
*/
Expand Down
14 changes: 12 additions & 2 deletions test/crowdsale/IncreasingPriceCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
Expand All @@ -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);
});
Expand Down