浏览代码

Simplify IndividuallyCappedCrowdsale interface (#1296)

* remove concept of User and remove setGroupCap

* fix linting error

* remove mention of users from comments
Francisco Giordano 7 年之前
父节点
当前提交
bf95602404

+ 11 - 28
contracts/crowdsale/validation/IndividuallyCappedCrowdsale.sol

@@ -7,7 +7,7 @@ import "../../ownership/Ownable.sol";
 
 /**
  * @title IndividuallyCappedCrowdsale
- * @dev Crowdsale with per-user caps.
+ * @dev Crowdsale with per-beneficiary caps.
  */
 contract IndividuallyCappedCrowdsale is Ownable, Crowdsale {
   using SafeMath for uint256;
@@ -16,53 +16,36 @@ contract IndividuallyCappedCrowdsale is Ownable, Crowdsale {
   mapping(address => uint256) private caps_;
 
   /**
-   * @dev Sets a specific user's maximum contribution.
+   * @dev Sets a specific beneficiary's maximum contribution.
    * @param _beneficiary Address to be capped
    * @param _cap Wei limit for individual contribution
    */
-  function setUserCap(address _beneficiary, uint256 _cap) external onlyOwner {
+  function setCap(address _beneficiary, uint256 _cap) external onlyOwner {
     caps_[_beneficiary] = _cap;
   }
 
   /**
-   * @dev Sets a group of users' maximum contribution.
-   * @param _beneficiaries List of addresses to be capped
-   * @param _cap Wei limit for individual contribution
-   */
-  function setGroupCap(
-    address[] _beneficiaries,
-    uint256 _cap
-  )
-    external
-    onlyOwner
-  {
-    for (uint256 i = 0; i < _beneficiaries.length; i++) {
-      caps_[_beneficiaries[i]] = _cap;
-    }
-  }
-
-  /**
-   * @dev Returns the cap of a specific user.
+   * @dev Returns the cap of a specific beneficiary.
    * @param _beneficiary Address whose cap is to be checked
-   * @return Current cap for individual user
+   * @return Current cap for individual beneficiary
    */
-  function getUserCap(address _beneficiary) public view returns (uint256) {
+  function getCap(address _beneficiary) public view returns (uint256) {
     return caps_[_beneficiary];
   }
 
   /**
-   * @dev Returns the amount contributed so far by a sepecific user.
+   * @dev Returns the amount contributed so far by a specific beneficiary.
    * @param _beneficiary Address of contributor
-   * @return User contribution so far
+   * @return Beneficiary contribution so far
    */
-  function getUserContribution(address _beneficiary)
+  function getContribution(address _beneficiary)
     public view returns (uint256)
   {
     return contributions_[_beneficiary];
   }
 
   /**
-   * @dev Extend parent behavior requiring purchase to respect the user's funding cap.
+   * @dev Extend parent behavior requiring purchase to respect the beneficiary's funding cap.
    * @param _beneficiary Token purchaser
    * @param _weiAmount Amount of wei contributed
    */
@@ -78,7 +61,7 @@ contract IndividuallyCappedCrowdsale is Ownable, Crowdsale {
   }
 
   /**
-   * @dev Extend parent behavior to update user contributions
+   * @dev Extend parent behavior to update beneficiary contributions
    * @param _beneficiary Token purchaser
    * @param _weiAmount Amount of wei contributed
    */

+ 4 - 39
test/crowdsale/IndividuallyCappedCrowdsale.test.js

@@ -23,8 +23,8 @@ contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charli
     beforeEach(async function () {
       this.token = await SimpleToken.new();
       this.crowdsale = await CappedCrowdsale.new(rate, wallet, this.token.address);
-      await this.crowdsale.setUserCap(alice, capAlice);
-      await this.crowdsale.setUserCap(bob, capBob);
+      await this.crowdsale.setCap(alice, capAlice);
+      await this.crowdsale.setCap(bob, capBob);
       await this.token.transfer(this.crowdsale.address, tokenSupply);
     });
 
@@ -56,47 +56,12 @@ contract('IndividuallyCappedCrowdsale', function ([_, wallet, alice, bob, charli
 
     describe('reporting state', function () {
       it('should report correct cap', async function () {
-        (await this.crowdsale.getUserCap(alice)).should.be.bignumber.equal(capAlice);
+        (await this.crowdsale.getCap(alice)).should.be.bignumber.equal(capAlice);
       });
 
       it('should report actual contribution', async function () {
         await this.crowdsale.buyTokens(alice, { value: lessThanCapAlice });
-        (await this.crowdsale.getUserContribution(alice)).should.be.bignumber.equal(lessThanCapAlice);
-      });
-    });
-  });
-
-  describe('group capping', function () {
-    beforeEach(async function () {
-      this.token = await SimpleToken.new();
-      this.crowdsale = await CappedCrowdsale.new(rate, wallet, this.token.address);
-      await this.crowdsale.setGroupCap([bob, charlie], capBob);
-      await this.token.transfer(this.crowdsale.address, tokenSupply);
-    });
-
-    describe('accepting payments', function () {
-      it('should accept payments within cap', async function () {
-        await this.crowdsale.buyTokens(bob, { value: lessThanCapBoth });
-        await this.crowdsale.buyTokens(charlie, { value: lessThanCapBoth });
-      });
-
-      it('should reject payments outside cap', async function () {
-        await this.crowdsale.buyTokens(bob, { value: capBob });
-        await expectThrow(this.crowdsale.buyTokens(bob, { value: 1 }), EVMRevert);
-        await this.crowdsale.buyTokens(charlie, { value: capBob });
-        await expectThrow(this.crowdsale.buyTokens(charlie, { value: 1 }), EVMRevert);
-      });
-
-      it('should reject payments that exceed cap', async function () {
-        await expectThrow(this.crowdsale.buyTokens(bob, { value: capBob.plus(1) }), EVMRevert);
-        await expectThrow(this.crowdsale.buyTokens(charlie, { value: capBob.plus(1) }), EVMRevert);
-      });
-    });
-
-    describe('reporting state', function () {
-      it('should report correct cap', async function () {
-        (await this.crowdsale.getUserCap(bob)).should.be.bignumber.equal(capBob);
-        (await this.crowdsale.getUserCap(charlie)).should.be.bignumber.equal(capBob);
+        (await this.crowdsale.getContribution(alice)).should.be.bignumber.equal(lessThanCapAlice);
       });
     });
   });