Bladeren bron

Made some TokenVesting public functions private. (#1427)

* Made some TokenVesting public functions private.

* Fixed linter error.
Nicolás Venturo 7 jaren geleden
bovenliggende
commit
df3c113711
2 gewijzigde bestanden met toevoegingen van 12 en 13 verwijderingen
  1. 5 5
      contracts/drafts/TokenVesting.sol
  2. 7 8
      test/drafts/TokenVesting.test.js

+ 5 - 5
contracts/drafts/TokenVesting.sol

@@ -114,7 +114,7 @@ contract TokenVesting is Ownable {
    * @param token ERC20 token which is being vested
    */
   function release(IERC20 token) public {
-    uint256 unreleased = releasableAmount(token);
+    uint256 unreleased = _releasableAmount(token);
 
     require(unreleased > 0);
 
@@ -136,7 +136,7 @@ contract TokenVesting is Ownable {
 
     uint256 balance = token.balanceOf(address(this));
 
-    uint256 unreleased = releasableAmount(token);
+    uint256 unreleased = _releasableAmount(token);
     uint256 refund = balance.sub(unreleased);
 
     _revoked[token] = true;
@@ -150,15 +150,15 @@ contract TokenVesting is Ownable {
    * @dev Calculates the amount that has already vested but hasn't been released yet.
    * @param token ERC20 token which is being vested
    */
-  function releasableAmount(IERC20 token) public view returns (uint256) {
-    return vestedAmount(token).sub(_released[token]);
+  function _releasableAmount(IERC20 token) private view returns (uint256) {
+    return _vestedAmount(token).sub(_released[token]);
   }
 
   /**
    * @dev Calculates the amount that has already vested.
    * @param token ERC20 token which is being vested
    */
-  function vestedAmount(IERC20 token) public view returns (uint256) {
+  function _vestedAmount(IERC20 token) private view returns (uint256) {
     uint256 currentBalance = token.balanceOf(this);
     uint256 totalBalance = currentBalance.add(_released[token]);
 

+ 7 - 8
test/drafts/TokenVesting.test.js

@@ -115,7 +115,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
     it('should return the non-vested tokens when revoked by owner', async function () {
       await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(12));
 
-      const vested = await this.vesting.vestedAmount(this.token.address);
+      const vested = vestedAmount(amount, await time.latest(), this.start, this.cliffDuration, this.duration);
 
       await this.vesting.revoke(this.token.address, { from: owner });
 
@@ -125,23 +125,22 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
     it('should keep the vested tokens when revoked by owner', async function () {
       await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(12));
 
-      const vestedPre = await this.vesting.vestedAmount(this.token.address);
+      const vestedPre = vestedAmount(amount, await time.latest(), this.start, this.cliffDuration, this.duration);
 
       await this.vesting.revoke(this.token.address, { from: owner });
 
-      const vestedPost = await this.vesting.vestedAmount(this.token.address);
+      const vestedPost = vestedAmount(amount, await time.latest(), this.start, this.cliffDuration, this.duration);
 
       vestedPre.should.bignumber.equal(vestedPost);
     });
 
     it('should fail to be revoked a second time', async function () {
-      await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(12));
-
-      await this.vesting.vestedAmount(this.token.address);
-
       await this.vesting.revoke(this.token.address, { from: owner });
-
       await shouldFail.reverting(this.vesting.revoke(this.token.address, { from: owner }));
     });
+
+    function vestedAmount (total, now, start, cliffDuration, duration) {
+      return (now < start + cliffDuration) ? 0 : Math.round(total * (now - start) / duration);
+    }
   });
 });