Unverified Commit 36043ecc by Nicolás Venturo Committed by GitHub

Merge pull request #27 from nventuro/init-asserts

Added assertions to leaf initializers of (some) pseudo-abstract contr…
parents 19610325 ecd6c57f
......@@ -141,6 +141,10 @@ contract Crowdsale is Initializable {
// Internal interface (extensible)
// -----------------------------------------
function _hasBeenInitialized() internal view returns (bool) {
return ((_rate > 0) && (_wallet != address(0)) && (_token != address(0)));
}
/**
* @dev Validation of an incoming purchase. Use require statements to revert state when conditions are not met. Use `super` in contracts that inherit from Crowdsale to extend their validations.
* Example from CappedCrowdsale.sol's _preValidatePurchase method:
......
......@@ -26,6 +26,9 @@ contract RefundableCrowdsale is Initializable, FinalizableCrowdsale {
* @param goal Funding goal
*/
function initialize(uint256 goal) public initializer {
// FinalizableCrowdsale depends on TimedCrowdsale
assert(TimedCrowdsale._hasBeenInitialized());
require(goal > 0);
// conditional added to make initializer idempotent in case of diamond inheritance
......
......@@ -22,6 +22,8 @@ contract AllowanceCrowdsale is Initializable, Crowdsale {
* @param tokenWallet Address holding the tokens, which has approved allowance to the crowdsale
*/
function initialize(address tokenWallet) public initializer {
assert(Crowdsale._hasBeenInitialized());
require(tokenWallet != address(0));
_tokenWallet = tokenWallet;
}
......
......@@ -23,6 +23,8 @@ contract IncreasingPriceCrowdsale is Initializable, TimedCrowdsale {
* @param finalRate Number of tokens a buyer gets per wei at the end of the crowdsale
*/
function initialize(uint256 initialRate, uint256 finalRate) public initializer {
assert(TimedCrowdsale._hasBeenInitialized());
require(finalRate > 0);
require(initialRate >= finalRate);
_initialRate = initialRate;
......
......@@ -19,6 +19,8 @@ contract CappedCrowdsale is Initializable, Crowdsale {
* @param cap Max amount of wei to be contributed
*/
function initialize(uint256 cap) public initializer {
assert(Crowdsale._hasBeenInitialized());
require(cap > 0);
_cap = cap;
}
......
......@@ -17,6 +17,8 @@ contract IndividuallyCappedCrowdsale is Initializable, Crowdsale, CapperRole {
mapping(address => uint256) private _caps;
function initialize(address sender) public initializer {
assert(Crowdsale._hasBeenInitialized());
CapperRole.initialize(sender);
}
......
......@@ -29,6 +29,8 @@ contract TimedCrowdsale is Initializable, Crowdsale {
* @param closingTime Crowdsale closing time
*/
function initialize(uint256 openingTime, uint256 closingTime) public initializer {
assert(Crowdsale._hasBeenInitialized());
// solium-disable-next-line security/no-block-members
require(openingTime >= block.timestamp);
require(closingTime >= openingTime);
......@@ -68,6 +70,10 @@ contract TimedCrowdsale is Initializable, Crowdsale {
return block.timestamp > _closingTime;
}
function _hasBeenInitialized() internal view returns (bool) {
return ((_openingTime > 0) && (_closingTime > 0));
}
/**
* @dev Extend parent behavior requiring to be within contributing period
* @param beneficiary Token purchaser
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment