add release function, deprecate claim

This commit is contained in:
Francisco Giordano
2017-07-05 11:24:59 -03:00
parent 7434b3d6d2
commit 5e423bc353
2 changed files with 20 additions and 12 deletions

View File

@ -27,10 +27,18 @@ contract TokenTimelock {
} }
/** /**
* @dev beneficiary claims tokens held by time lock * @notice Transfers tokens held by timelock to beneficiary.
* Deprecated: please use TokenTimelock#release instead.
*/ */
function claim() { function claim() {
require(msg.sender == beneficiary); require(msg.sender == beneficiary);
release();
}
/**
* @notice Transfers tokens held by timelock to beneficiary.
*/
function release() {
require(now >= releaseTime); require(now >= releaseTime);
uint amount = token.balanceOf(this); uint amount = token.balanceOf(this);

View File

@ -24,33 +24,33 @@ contract('TokenTimelock', function ([_, owner, beneficiary]) {
await this.token.mint(this.timelock.address, amount, {from: owner}) await this.token.mint(this.timelock.address, amount, {from: owner})
}) })
it('cannot be claimed before time limit', async function () { it('cannot be released before time limit', async function () {
await this.timelock.claim({from: beneficiary}).should.be.rejected await this.timelock.release().should.be.rejected
}) })
it('cannot be claimed just before time limit', async function () { it('cannot be released just before time limit', async function () {
await increaseTime(moment.duration(0.99, 'year')) await increaseTime(moment.duration(0.99, 'year'))
await this.timelock.claim({from: beneficiary}).should.be.rejected await this.timelock.release().should.be.rejected
}) })
it('can be claimed just after limit', async function () { it('can be released just after limit', async function () {
await increaseTime(moment.duration(1.01, 'year')) await increaseTime(moment.duration(1.01, 'year'))
await this.timelock.claim({from: beneficiary}).should.be.fulfilled await this.timelock.release().should.be.fulfilled
const balance = await this.token.balanceOf(beneficiary) const balance = await this.token.balanceOf(beneficiary)
balance.should.be.bignumber.equal(amount) balance.should.be.bignumber.equal(amount)
}) })
it('can be claimed after time limit', async function () { it('can be released after time limit', async function () {
await increaseTime(moment.duration(2, 'year')) await increaseTime(moment.duration(2, 'year'))
await this.timelock.claim({from: beneficiary}).should.be.fulfilled await this.timelock.release().should.be.fulfilled
const balance = await this.token.balanceOf(beneficiary) const balance = await this.token.balanceOf(beneficiary)
balance.should.be.bignumber.equal(amount) balance.should.be.bignumber.equal(amount)
}) })
it('cannot be claimed twice', async function () { it('cannot be released twice', async function () {
await increaseTime(moment.duration(2, 'year')) await increaseTime(moment.duration(2, 'year'))
await this.timelock.claim({from: beneficiary}).should.be.fulfilled await this.timelock.release().should.be.fulfilled
await this.timelock.claim({from: beneficiary}).should.be.rejected await this.timelock.release().should.be.rejected
const balance = await this.token.balanceOf(beneficiary) const balance = await this.token.balanceOf(beneficiary)
balance.should.be.bignumber.equal(amount) balance.should.be.bignumber.equal(amount)
}) })