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

Made some TokenVesting public functions private. #1427

Merged
merged 3 commits into from Oct 17, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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]);

@@ -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);
}
});
});
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.