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