Improve encapsulation on ERCs (#1270)
* Improve encapsulation on ERC165 * Improve encapsulation on ERC20 * Improve encapsulation on ERC721 * Add tests, use standard getters * fix tests * Fix lint * move interface ids to implementation contracts * Do not prefix getters
This commit is contained in:
committed by
Francisco Giordano
parent
45c0c072d1
commit
7bb87237f3
@ -19,35 +19,44 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
|
||||
|
||||
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.beneficiary()).should.be.equal(beneficiary);
|
||||
(await this.vesting.cliff()).should.be.bignumber.equal(this.start + this.cliffDuration);
|
||||
(await this.vesting.start()).should.be.bignumber.equal(this.start);
|
||||
(await this.vesting.duration()).should.be.bignumber.equal(this.duration);
|
||||
(await this.vesting.revocable()).should.be.equal(true);
|
||||
});
|
||||
|
||||
it('cannot be released before cliff', async function () {
|
||||
await expectThrow(
|
||||
this.vesting.release(this.token.address),
|
||||
@ -56,33 +65,34 @@ 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;
|
||||
|
||||
(await this.token.balanceOf(beneficiary)).should.bignumber.equal(
|
||||
amount.mul(releaseTime - this.start).div(this.duration).floor()
|
||||
);
|
||||
const releasedAmount = amount.mul(releaseTime - this.start).div(this.duration).floor();
|
||||
(await this.token.balanceOf(beneficiary)).should.bignumber.equal(releasedAmount);
|
||||
(await this.vesting.released(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.released(this.token.address)).should.bignumber.equal(expectedVesting);
|
||||
}
|
||||
});
|
||||
|
||||
@ -90,15 +100,17 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
|
||||
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.released(this.token.address)).should.bignumber.equal(amount);
|
||||
});
|
||||
|
||||
it('should be revoked by owner if revocable is set', async function () {
|
||||
await this.vesting.revoke(this.token.address, { from: owner });
|
||||
(await this.vesting.revoked(this.token.address)).should.equal(true);
|
||||
});
|
||||
|
||||
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(
|
||||
@ -108,7 +120,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);
|
||||
|
||||
@ -118,7 +130,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);
|
||||
|
||||
@ -130,7 +142,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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user