Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
128c4c0
Improve encapsulation on ERC165
Sep 3, 2018
0d8a5e4
Improve encapsulation on ERC20
Sep 3, 2018
1c365fe
Improve encapsulation on ERC721
Sep 3, 2018
9ebdae6
Add tests, use standard getters
Sep 3, 2018
963a00b
fix tests
Sep 3, 2018
4d8db8d
Fix lint
Sep 3, 2018
dc7b21e
Merge branch 'master' into refactor/1174/private-state-vars-erc
Sep 4, 2018
0b0d6c6
move interface ids to implementation contracts
frangio Sep 4, 2018
68094d1
Do not prefix getters
Sep 5, 2018
2ea79e9
Merge branch 'master' into refactor/1174/private-state-vars-erc
Sep 5, 2018
5fc3742
Improve encapsulation on Pausable
Sep 3, 2018
172b720
add the underscore
Sep 3, 2018
86bbab3
Improve encapsulation on ownership
Sep 3, 2018
faed52d
fix rebase
Sep 3, 2018
21ae177
fix ownership
Sep 3, 2018
917a019
Improve encapsulation on payments
Sep 3, 2018
478d974
Add missing tests
Sep 4, 2018
0fecbac
add missing test
Sep 4, 2018
9449572
Do not prefix getters
Sep 5, 2018
1856f07
Fix tests.
Sep 5, 2018
f61acdc
Improve encapsulation on Crowdsales
Sep 3, 2018
44d113a
add missing tests
Sep 3, 2018
0257670
remove only
Sep 3, 2018
5a476d1
Do not prefix getters
Sep 5, 2018
85a0fc3
Update modifiers to call public view functions.
Sep 5, 2018
24761a5
remove isMinter
Sep 5, 2018
c14d597
fix is owner call
Sep 5, 2018
ba7fa16
fix isOpen
Sep 5, 2018
776d47a
Merge branch 'master' into feature/1179/modifiers-call-functions
Sep 6, 2018
7a37725
Fix merge
Sep 6, 2018
52352ce
Improve encapsulation on TimedCrowdsale
Sep 6, 2018
63b93cc
Add missing parentheses
Sep 6, 2018
b6bddb2
Merge branch 'master' into refactor/1174/private-state-vars-timed-cro…
frangio Sep 6, 2018
369b8d6
remove duplicate function definition
frangio Sep 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tests
  • Loading branch information
Leo Arias committed Sep 3, 2018
commit 963a00bfa6b587e9be728750bea5689c5b1e8ebf
14 changes: 7 additions & 7 deletions contracts/token/ERC20/TokenVesting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,27 @@ contract TokenVesting is Ownable {
* _beneficiary, gradually in a linear fashion until _start + _duration. By then all
* of the balance will have vested.
* @param _beneficiary address of the beneficiary to whom vested tokens are transferred
* @param _cliff duration in seconds of the cliff in which tokens will begin to vest
* @param _cliffDuration duration in seconds of the cliff in which tokens will begin to vest
* @param _start the time (as Unix time) at which point vesting starts
* @param _duration duration in seconds of the period in which the tokens will vest
* @param _revocable whether the vesting is revocable or not
*/
constructor(
address _beneficiary,
uint256 _start,
uint256 _cliff,
uint256 _cliffDuration,
uint256 _duration,
bool _revocable
)
public
{
require(_beneficiary != address(0));
require(_cliff <= _duration);
require(_cliffDuration <= _duration);

beneficiary_ = _beneficiary;
revocable_ = _revocable;
duration_ = _duration;
cliff_ = _start.add(_cliff);
cliff_ = _start.add(_cliffDuration);
start_ = _start;
}

Expand Down Expand Up @@ -97,10 +97,10 @@ contract TokenVesting is Ownable {
}

/**
* @return the amount released to an account.
* @return the amount of the token released.
*/
function getReleased(address _account) public view returns(uint256) {
return released_[_account];
function getReleased(address _token) public view returns(uint256) {
return released_[_token];
}

/**
Expand Down
44 changes: 22 additions & 22 deletions test/token/ERC20/TokenVesting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,46 @@ require('chai')
const ERC20Mintable = artifacts.require('ERC20Mintable');
const TokenVesting = artifacts.require('TokenVesting');

contract('TokenVesting', function ([_, owner, beneficiary]) {
contract.only('TokenVesting', function ([_, owner, beneficiary]) {
const amount = new BigNumber(1000);
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

beforeEach(async function () {
this.start = (await latestTime()) + duration.minutes(1); // +1 minute so it starts after contract instantiation
this.cliff = duration.years(1);
this.cliffDuration = duration.years(1);
this.duration = duration.years(2);
});

it('rejects a duration shorter than the cliff', async function () {
const cliff = this.duration;
const duration = this.cliff;
const cliffDuration = this.duration;
const duration = this.cliffDuration;

cliff.should.be.gt(duration);
cliffDuration.should.be.gt(duration);

await expectThrow(
TokenVesting.new(beneficiary, this.start, cliff, duration, true, { from: owner })
TokenVesting.new(beneficiary, this.start, cliffDuration, duration, true, { from: owner })
);
});

it('requires a valid beneficiary', async function () {
await expectThrow(
TokenVesting.new(ZERO_ADDRESS, this.start, this.cliff, this.duration, true, { from: owner })
TokenVesting.new(ZERO_ADDRESS, this.start, this.cliffDuration, this.duration, true, { from: owner })
);
});

context('once deployed', function () {
beforeEach(async function () {
this.vesting = await TokenVesting.new(beneficiary, this.start, this.cliff, this.duration, true, { from: owner });
this.vesting = await TokenVesting.new(beneficiary, this.start, this.cliffDuration, this.duration, true, { from: owner });

this.token = await ERC20Mintable.new({ from: owner });
await this.token.mint(this.vesting.address, amount, { from: owner });
});

it('can get state', async function () {
(await this.vesting.getBeneficiary()).should.be.equal(beneficiary);
(await this.vesting.getCliff()).should.be.equal(this.cliff);
(await this.vesting.getStart()).should.be.equal(this.start);
(await this.vesting.getDuration()).should.be.equal(this.duration);
(await this.vesting.getCliff()).should.be.bignumber.equal(this.start + this.cliffDuration);
(await this.vesting.getStart()).should.be.bignumber.equal(this.start);
(await this.vesting.getDuration()).should.be.bignumber.equal(this.duration);
(await this.vesting.isRevocable()).should.be.equal(true);
});

Expand All @@ -64,42 +64,42 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
});

it('can be released after cliff', async function () {
await increaseTimeTo(this.start + this.cliff + duration.weeks(1));
await increaseTimeTo(this.start + this.cliffDuration + duration.weeks(1));
await this.vesting.release(this.token.address);
});

it('should release proper amount after cliff', async function () {
await increaseTimeTo(this.start + this.cliff);
await increaseTimeTo(this.start + this.cliffDuration);

const { receipt } = await this.vesting.release(this.token.address);
const block = await ethGetBlock(receipt.blockNumber);
const releaseTime = block.timestamp;

const releasedAmount = amount.mul(releaseTime - this.start).div(this.duration).floor();
(await this.token.balanceOf(beneficiary)).should.bignumber.equal(releasedAmount);
(await this.vesting.getReleased(beneficiary)).should.bignumber.equal(releasedAmount);
(await this.vesting.getReleased(this.token.address)).should.bignumber.equal(releasedAmount);
});

it('should linearly release tokens during vesting period', async function () {
const vestingPeriod = this.duration - this.cliff;
const vestingPeriod = this.duration - this.cliffDuration;
const checkpoints = 4;

for (let i = 1; i <= checkpoints; i++) {
const now = this.start + this.cliff + i * (vestingPeriod / checkpoints);
const now = this.start + this.cliffDuration + i * (vestingPeriod / checkpoints);
await increaseTimeTo(now);

await this.vesting.release(this.token.address);
const expectedVesting = amount.mul(now - this.start).div(this.duration).floor();
(await this.token.balanceOf(beneficiary)).should.bignumber.equal(expectedVesting);
(await this.vesting.getReleased(beneficiary)).should.bignumber.equal(expectedVesting);
(await this.vesting.getReleased(this.token.address)).should.bignumber.equal(expectedVesting);
}
});

it('should have released all after end', async function () {
await increaseTimeTo(this.start + this.duration);
await this.vesting.release(this.token.address);
(await this.token.balanceOf(beneficiary)).should.bignumber.equal(amount);
(await this.vesting.getReleased(beneficiary)).should.bignumber.equal(amount);
(await this.vesting.getReleased(this.token.address)).should.bignumber.equal(amount);
});

it('should be revoked by owner if revocable is set', async function () {
Expand All @@ -109,7 +109,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {

it('should fail to be revoked by owner if revocable not set', async function () {
const vesting = await TokenVesting.new(
beneficiary, this.start, this.cliff, this.duration, false, { from: owner }
beneficiary, this.start, this.cliffDuration, this.duration, false, { from: owner }
);

await expectThrow(
Expand All @@ -119,7 +119,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
});

it('should return the non-vested tokens when revoked by owner', async function () {
await increaseTimeTo(this.start + this.cliff + duration.weeks(12));
await increaseTimeTo(this.start + this.cliffDuration + duration.weeks(12));

const vested = await this.vesting.vestedAmount(this.token.address);

Expand All @@ -129,7 +129,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
});

it('should keep the vested tokens when revoked by owner', async function () {
await increaseTimeTo(this.start + this.cliff + duration.weeks(12));
await increaseTimeTo(this.start + this.cliffDuration + duration.weeks(12));

const vestedPre = await this.vesting.vestedAmount(this.token.address);

Expand All @@ -141,7 +141,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
});

it('should fail to be revoked a second time', async function () {
await increaseTimeTo(this.start + this.cliff + duration.weeks(12));
await increaseTimeTo(this.start + this.cliffDuration + duration.weeks(12));

await this.vesting.vestedAmount(this.token.address);

Expand Down