|
@@ -2,29 +2,32 @@ const assertJump = require('./helpers/assertJump');
|
|
|
const timer = require('./helpers/timer');
|
|
|
|
|
|
contract('VestedToken', function(accounts) {
|
|
|
- let token = null
|
|
|
- let now = 0
|
|
|
+
|
|
|
+ let token = null;
|
|
|
+ let now = 0;
|
|
|
|
|
|
- const tokenAmount = 50
|
|
|
+ const tokenAmount = 50;
|
|
|
|
|
|
- const granter = accounts[0]
|
|
|
- const receiver = accounts[1]
|
|
|
+ const granter = accounts[3];
|
|
|
+ const receiver = accounts[4];
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
- token = await VestedTokenMock.new(granter, 100);
|
|
|
+ token = await VestedTokenMock.new(granter, tokenAmount*2);
|
|
|
now = +new Date()/1000;
|
|
|
- })
|
|
|
+ var block = await web3.eth.getBlock('latest');
|
|
|
+ now = block.timestamp;
|
|
|
+ });
|
|
|
|
|
|
it('granter can grant tokens without vesting', async () => {
|
|
|
- await token.transfer(receiver, tokenAmount, { from: granter })
|
|
|
+ await token.transfer(receiver, tokenAmount, { from: granter });
|
|
|
|
|
|
assert.equal(await token.balanceOf(receiver), tokenAmount);
|
|
|
assert.equal(await token.transferableTokens(receiver, +new Date()/1000), tokenAmount);
|
|
|
})
|
|
|
|
|
|
describe('getting a token grant', async () => {
|
|
|
- const cliff = 1
|
|
|
- const vesting = 2 // seconds
|
|
|
+ const cliff = 10;
|
|
|
+ const vesting = 20; // seconds
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
await token.grantVestedTokens(receiver, tokenAmount, now, now + cliff, now + vesting, { from: granter })
|
|
@@ -44,7 +47,7 @@ contract('VestedToken', function(accounts) {
|
|
|
|
|
|
it('throws when trying to transfer non vested tokens', async () => {
|
|
|
try {
|
|
|
- await token.transfer(accounts[7], 1, { from: receiver })
|
|
|
+ await token.transfer(accounts[9], 1, { from: receiver })
|
|
|
} catch(error) {
|
|
|
return assertJump(error);
|
|
|
}
|
|
@@ -59,23 +62,27 @@ contract('VestedToken', function(accounts) {
|
|
|
|
|
|
it('cannot be revoked by non granter', async () => {
|
|
|
try {
|
|
|
- await token.revokeTokenGrant(receiver, 0, { from: accounts[3] });
|
|
|
+ await token.revokeTokenGrant(receiver, 0, { from: accounts[9] });
|
|
|
} catch(error) {
|
|
|
return assertJump(error);
|
|
|
}
|
|
|
assert.fail('should have thrown before');
|
|
|
})
|
|
|
|
|
|
- it('can be revoked by granter and non vested tokens are returned', async () => {
|
|
|
+ it.only('can be revoked by granter and non vested tokens are returned', async () => {
|
|
|
await timer(cliff);
|
|
|
await token.revokeTokenGrant(receiver, 0, { from: granter });
|
|
|
- assert.equal(await token.balanceOf(receiver), tokenAmount * cliff / vesting);
|
|
|
+ var balance = await token.balanceOf(receiver);
|
|
|
+ var expectedBalance = tokenAmount * cliff / vesting;
|
|
|
+ console.log('real balance', balance.toString());
|
|
|
+ console.log('expected ', expectedBalance);
|
|
|
+ assert.equal(balance, expectedBalance);
|
|
|
})
|
|
|
|
|
|
it('can transfer all tokens after vesting ends', async () => {
|
|
|
await timer(vesting + 1);
|
|
|
- await token.transfer(accounts[7], tokenAmount, { from: receiver })
|
|
|
- assert.equal(await token.balanceOf(accounts[7]), tokenAmount);
|
|
|
+ await token.transfer(accounts[9], tokenAmount, { from: receiver })
|
|
|
+ assert.equal(await token.balanceOf(accounts[9]), tokenAmount);
|
|
|
})
|
|
|
})
|
|
|
});
|