fix a problem when revoke is called twice
This commit is contained in:
@ -27,6 +27,7 @@ contract TokenVesting is Ownable {
|
|||||||
bool revocable;
|
bool revocable;
|
||||||
|
|
||||||
mapping (address => uint256) released;
|
mapping (address => uint256) released;
|
||||||
|
mapping (address => bool) revoked;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Creates a vesting contract that vests its balance of any ERC20 token to the
|
* @dev Creates a vesting contract that vests its balance of any ERC20 token to the
|
||||||
@ -65,17 +66,22 @@ contract TokenVesting is Ownable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice Allows the owner to revoke the vesting. Tokens already vested remain in the contract.
|
* @notice Allows the owner to revoke the vesting. Tokens already vested
|
||||||
|
* remain in the contract, the rest are returned to the owner.
|
||||||
* @param token ERC20 token which is being vested
|
* @param token ERC20 token which is being vested
|
||||||
*/
|
*/
|
||||||
function revoke(ERC20Basic token) onlyOwner {
|
function revoke(ERC20Basic token) onlyOwner {
|
||||||
require(revocable);
|
require(revocable);
|
||||||
|
require(!revoked[token]);
|
||||||
|
|
||||||
uint256 balance = token.balanceOf(this);
|
uint256 balance = token.balanceOf(this);
|
||||||
|
|
||||||
uint256 vested = vestedAmount(token);
|
uint256 vested = vestedAmount(token);
|
||||||
|
uint256 vesting = balance - vested;
|
||||||
|
|
||||||
token.transfer(owner, balance - vested);
|
revoked[token] = true;
|
||||||
|
|
||||||
|
token.transfer(owner, vesting);
|
||||||
|
|
||||||
Revoked();
|
Revoked();
|
||||||
}
|
}
|
||||||
@ -87,7 +93,7 @@ contract TokenVesting is Ownable {
|
|||||||
function vestedAmount(ERC20Basic token) constant returns (uint256) {
|
function vestedAmount(ERC20Basic token) constant returns (uint256) {
|
||||||
if (now < cliff) {
|
if (now < cliff) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (now >= start + duration) {
|
} else if (now >= start + duration || revoked[token]) {
|
||||||
return token.balanceOf(this);
|
return token.balanceOf(this);
|
||||||
} else {
|
} else {
|
||||||
uint256 currentBalance = token.balanceOf(this);
|
uint256 currentBalance = token.balanceOf(this);
|
||||||
|
|||||||
@ -80,8 +80,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return the non-vested tokens when revoked by owner', async function () {
|
it('should return the non-vested tokens when revoked by owner', async function () {
|
||||||
await increaseTimeTo(this.start + this.cliff + duration.weeks(1));
|
await increaseTimeTo(this.start + this.cliff + duration.weeks(12));
|
||||||
await this.vesting.release(this.token.address);
|
|
||||||
|
|
||||||
const vested = await this.vesting.vestedAmount(this.token.address);
|
const vested = await this.vesting.vestedAmount(this.token.address);
|
||||||
const balance = await this.token.balanceOf(this.vesting.address);
|
const balance = await this.token.balanceOf(this.vesting.address);
|
||||||
@ -93,15 +92,25 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should keep the vested tokens when revoked by owner', async function () {
|
it('should keep the vested tokens when revoked by owner', async function () {
|
||||||
await increaseTimeTo(this.start + this.cliff + duration.weeks(1));
|
await increaseTimeTo(this.start + this.cliff + duration.weeks(12));
|
||||||
await this.vesting.release(this.token.address);
|
|
||||||
|
const vestedPre = await this.vesting.vestedAmount(this.token.address);
|
||||||
|
|
||||||
|
await this.vesting.revoke(this.token.address, { from: owner });
|
||||||
|
|
||||||
|
const vestedPost = await this.vesting.vestedAmount(this.token.address);
|
||||||
|
|
||||||
|
vestedPre.should.bignumber.equal(vestedPost);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail to be revoked a second time', async function () {
|
||||||
|
await increaseTimeTo(this.start + this.cliff + duration.weeks(12));
|
||||||
|
|
||||||
const vested = await this.vesting.vestedAmount(this.token.address);
|
const vested = await this.vesting.vestedAmount(this.token.address);
|
||||||
|
|
||||||
await this.vesting.revoke(this.token.address, { from: owner });
|
await this.vesting.revoke(this.token.address, { from: owner });
|
||||||
|
|
||||||
const balance = await this.token.balanceOf(this.vesting.address);
|
await this.vesting.revoke(this.token.address, { from: owner }).should.be.rejectedWith(EVMThrow);
|
||||||
balance.should.bignumber.equal(vested);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user