Browse Source

Internal crowdsales (#1439)

* Made some internal crowdsale methods internal.

* Made all Crowdsale constructors internal.
Nicolás Venturo 7 years ago
parent
commit
d9fdffe88e

+ 3 - 1
contracts/crowdsale/Crowdsale.sol

@@ -57,7 +57,7 @@ contract Crowdsale {
    * @param wallet Address where collected funds will be forwarded to
    * @param token Address of the token being sold
    */
-  constructor(uint256 rate, address wallet, IERC20 token) public {
+  constructor(uint256 rate, address wallet, IERC20 token) internal {
     require(rate > 0);
     require(wallet != address(0));
     require(token != address(0));
@@ -152,6 +152,7 @@ contract Crowdsale {
     uint256 weiAmount
   )
     internal
+    view
   {
     require(beneficiary != address(0));
     require(weiAmount != 0);
@@ -167,6 +168,7 @@ contract Crowdsale {
     uint256 weiAmount
   )
     internal
+    view
   {
     // optional override
   }

+ 1 - 1
contracts/crowdsale/distribution/FinalizableCrowdsale.sol

@@ -15,7 +15,7 @@ contract FinalizableCrowdsale is TimedCrowdsale {
 
   event CrowdsaleFinalized();
 
-  constructor() public {
+  constructor() internal {
     _finalized = false;
   }
 

+ 2 - 0
contracts/crowdsale/distribution/PostDeliveryCrowdsale.sol

@@ -13,6 +13,8 @@ contract PostDeliveryCrowdsale is TimedCrowdsale {
 
   mapping(address => uint256) private _balances;
 
+  constructor() internal {}
+
   /**
    * @dev Withdraw tokens only after crowdsale ends.
    * @param beneficiary Whose tokens will be withdrawn.

+ 1 - 1
contracts/crowdsale/distribution/RefundableCrowdsale.sol

@@ -22,7 +22,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
    * @dev Constructor, creates RefundEscrow.
    * @param goal Funding goal
    */
-  constructor(uint256 goal) public {
+  constructor(uint256 goal) internal {
     require(goal > 0);
     _escrow = new RefundEscrow(wallet());
     _goal = goal;

+ 1 - 1
contracts/crowdsale/emission/AllowanceCrowdsale.sol

@@ -19,7 +19,7 @@ contract AllowanceCrowdsale is Crowdsale {
    * @dev Constructor, takes token wallet address.
    * @param tokenWallet Address holding the tokens, which has approved allowance to the crowdsale
    */
-  constructor(address tokenWallet) public {
+  constructor(address tokenWallet) internal {
     require(tokenWallet != address(0));
     _tokenWallet = tokenWallet;
   }

+ 1 - 0
contracts/crowdsale/emission/MintedCrowdsale.sol

@@ -9,6 +9,7 @@ import "../../token/ERC20/ERC20Mintable.sol";
  * Token ownership should be transferred to MintedCrowdsale for minting.
  */
 contract MintedCrowdsale is Crowdsale {
+  constructor() internal {}
 
   /**
    * @dev Overrides delivery by minting tokens upon purchase.

+ 1 - 1
contracts/crowdsale/price/IncreasingPriceCrowdsale.sol

@@ -20,7 +20,7 @@ contract IncreasingPriceCrowdsale is TimedCrowdsale {
    * @param initialRate Number of tokens a buyer gets per wei at the start of the crowdsale
    * @param finalRate Number of tokens a buyer gets per wei at the end of the crowdsale
    */
-  constructor(uint256 initialRate, uint256 finalRate) public {
+  constructor(uint256 initialRate, uint256 finalRate) internal {
     require(finalRate > 0);
     require(initialRate >= finalRate);
     _initialRate = initialRate;

+ 2 - 1
contracts/crowdsale/validation/CappedCrowdsale.sol

@@ -16,7 +16,7 @@ contract CappedCrowdsale is Crowdsale {
    * @dev Constructor, takes maximum amount of wei accepted in the crowdsale.
    * @param cap Max amount of wei to be contributed
    */
-  constructor(uint256 cap) public {
+  constructor(uint256 cap) internal {
     require(cap > 0);
     _cap = cap;
   }
@@ -46,6 +46,7 @@ contract CappedCrowdsale is Crowdsale {
     uint256 weiAmount
   )
     internal
+    view
   {
     super._preValidatePurchase(beneficiary, weiAmount);
     require(weiRaised().add(weiAmount) <= _cap);

+ 3 - 0
contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol

@@ -14,6 +14,8 @@ contract IndividuallyCappedCrowdsale is Crowdsale, CapperRole {
   mapping(address => uint256) private _contributions;
   mapping(address => uint256) private _caps;
 
+  constructor() internal {}
+
   /**
    * @dev Sets a specific beneficiary's maximum contribution.
    * @param beneficiary Address to be capped
@@ -53,6 +55,7 @@ contract IndividuallyCappedCrowdsale is Crowdsale, CapperRole {
     uint256 weiAmount
   )
     internal
+    view
   {
     super._preValidatePurchase(beneficiary, weiAmount);
     require(

+ 2 - 1
contracts/crowdsale/validation/TimedCrowdsale.sol

@@ -26,7 +26,7 @@ contract TimedCrowdsale is Crowdsale {
    * @param openingTime Crowdsale opening time
    * @param closingTime Crowdsale closing time
    */
-  constructor(uint256 openingTime, uint256 closingTime) public {
+  constructor(uint256 openingTime, uint256 closingTime) internal {
     // solium-disable-next-line security/no-block-members
     require(openingTime >= block.timestamp);
     require(closingTime >= openingTime);
@@ -77,6 +77,7 @@ contract TimedCrowdsale is Crowdsale {
   )
     internal
     onlyWhileOpen
+    view
   {
     super._preValidatePurchase(beneficiary, weiAmount);
   }

+ 9 - 0
contracts/mocks/CrowdsaleMock.sol

@@ -0,0 +1,9 @@
+pragma solidity ^0.4.24;
+
+import "../crowdsale/Crowdsale.sol";
+
+contract CrowdsaleMock is Crowdsale {
+  constructor(uint256 rate, address wallet, IERC20 token) public
+    Crowdsale(rate, wallet, token) {
+  }
+}

+ 1 - 1
test/crowdsale/Crowdsale.test.js

@@ -10,7 +10,7 @@ require('chai')
   .use(require('chai-bignumber')(BigNumber))
   .should();
 
-const Crowdsale = artifacts.require('Crowdsale');
+const Crowdsale = artifacts.require('CrowdsaleMock');
 const SimpleToken = artifacts.require('SimpleToken');
 
 contract('Crowdsale', function ([_, investor, wallet, purchaser]) {