parent
fb0a96332c
commit
8d9e12eda3
@ -1,7 +1,11 @@ |
|||||||
pragma solidity ^0.4.4; |
pragma solidity ^0.4.4; |
||||||
import "./StandardTokenMock.sol"; |
|
||||||
|
|
||||||
contract GrantableTokenMock is StandardTokenMock { |
import '../token/GrantableToken.sol'; |
||||||
function GrantableTokenMock(address initialAccount, uint initialBalance) |
|
||||||
StandardTokenMock(initialAccount, initialBalance) {} |
// mock class using StandardToken |
||||||
|
contract GrantableTokenMock is GrantableToken { |
||||||
|
function GrantableTokenMock(address initialAccount, uint initialBalance) { |
||||||
|
balances[initialAccount] = initialBalance; |
||||||
|
totalSupply = initialBalance; |
||||||
|
} |
||||||
} |
} |
||||||
|
@ -1,66 +0,0 @@ |
|||||||
const assertJump = require('./helpers/assertJump'); |
|
||||||
|
|
||||||
contract('GrantableToken', function(accounts) { |
|
||||||
|
|
||||||
it("should return the correct totalSupply after construction", async function() { |
|
||||||
let token = await StandardTokenMock.new(accounts[0], 100); |
|
||||||
let totalSupply = await token.totalSupply(); |
|
||||||
|
|
||||||
assert.equal(totalSupply, 100); |
|
||||||
}) |
|
||||||
|
|
||||||
it("should return the correct allowance amount after approval", async function() { |
|
||||||
let token = await StandardTokenMock.new(); |
|
||||||
let approve = await token.approve(accounts[1], 100); |
|
||||||
let allowance = await token.allowance(accounts[0], accounts[1]); |
|
||||||
|
|
||||||
assert.equal(allowance, 100); |
|
||||||
}); |
|
||||||
|
|
||||||
it("should return correct balances after transfer", async function() { |
|
||||||
let token = await StandardTokenMock.new(accounts[0], 100); |
|
||||||
let transfer = await token.transfer(accounts[1], 100); |
|
||||||
let balance0 = await token.balanceOf(accounts[0]); |
|
||||||
assert.equal(balance0, 0); |
|
||||||
|
|
||||||
let balance1 = await token.balanceOf(accounts[1]); |
|
||||||
assert.equal(balance1, 100); |
|
||||||
}); |
|
||||||
|
|
||||||
it("should throw an error when trying to transfer more than balance", async function() { |
|
||||||
let token = await StandardTokenMock.new(accounts[0], 100); |
|
||||||
try { |
|
||||||
let transfer = await token.transfer(accounts[1], 101); |
|
||||||
} catch(error) { |
|
||||||
return assertJump(error); |
|
||||||
} |
|
||||||
assert.fail('should have thrown before'); |
|
||||||
}); |
|
||||||
|
|
||||||
it("should return correct balances after transfering from another account", async function() { |
|
||||||
let token = await StandardTokenMock.new(accounts[0], 100); |
|
||||||
let approve = await token.approve(accounts[1], 100); |
|
||||||
let transferFrom = await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]}); |
|
||||||
|
|
||||||
let balance0 = await token.balanceOf(accounts[0]); |
|
||||||
assert.equal(balance0, 0); |
|
||||||
|
|
||||||
let balance1 = await token.balanceOf(accounts[2]); |
|
||||||
assert.equal(balance1, 100); |
|
||||||
|
|
||||||
let balance2 = await token.balanceOf(accounts[1]); |
|
||||||
assert.equal(balance2, 0); |
|
||||||
}); |
|
||||||
|
|
||||||
it("should throw an error when trying to transfer more than allowed", async function() { |
|
||||||
let token = await StandardTokenMock.new(); |
|
||||||
let approve = await token.approve(accounts[1], 99); |
|
||||||
try { |
|
||||||
let transfer = await token.transferFrom(accounts[0], accounts[2], 100, {from: accounts[1]}); |
|
||||||
} catch (error) { |
|
||||||
return assertJump(error); |
|
||||||
} |
|
||||||
assert.fail('should have thrown before'); |
|
||||||
}); |
|
||||||
|
|
||||||
}); |
|
@ -0,0 +1,81 @@ |
|||||||
|
const assertJump = require('./helpers/assertJump'); |
||||||
|
const timer = require('./helpers/timer'); |
||||||
|
|
||||||
|
contract('GrantableToken', function(accounts) { |
||||||
|
let token = null |
||||||
|
let now = 0 |
||||||
|
|
||||||
|
const tokenAmount = 50 |
||||||
|
|
||||||
|
const granter = accounts[0] |
||||||
|
const receiver = accounts[1] |
||||||
|
|
||||||
|
beforeEach(async () => { |
||||||
|
token = await GrantableTokenMock.new(granter, 100); |
||||||
|
now = +new Date()/1000; |
||||||
|
}) |
||||||
|
|
||||||
|
it('granter can grant tokens without vesting', async () => { |
||||||
|
await token.grantTokens(receiver, tokenAmount, { from: granter }) |
||||||
|
|
||||||
|
assert.equal(await token.balanceOf(receiver), tokenAmount); |
||||||
|
assert.equal(await token.transferrableTokens(receiver, +new Date()/1000), tokenAmount); |
||||||
|
}) |
||||||
|
|
||||||
|
describe('getting a token grant', async () => { |
||||||
|
const cliff = 1 |
||||||
|
const vesting = 2 // seconds
|
||||||
|
|
||||||
|
beforeEach(async () => { |
||||||
|
await token.grantVestedTokens(receiver, tokenAmount, now, now + cliff, now + vesting, { from: granter }) |
||||||
|
}) |
||||||
|
|
||||||
|
it('tokens are received', async () => { |
||||||
|
assert.equal(await token.balanceOf(receiver), tokenAmount); |
||||||
|
}) |
||||||
|
|
||||||
|
it('has 0 transferrable tokens before cliff', async () => { |
||||||
|
assert.equal(await token.transferrableTokens(receiver, now), 0); |
||||||
|
}) |
||||||
|
|
||||||
|
it('all tokens are transferrable after vesting', async () => { |
||||||
|
assert.equal(await token.transferrableTokens(receiver, now + vesting + 1), tokenAmount); |
||||||
|
}) |
||||||
|
|
||||||
|
it('throws when trying to transfer non vested tokens', async () => { |
||||||
|
try { |
||||||
|
await token.transfer(accounts[7], 1, { from: receiver }) |
||||||
|
} catch(error) { |
||||||
|
return assertJump(error); |
||||||
|
} |
||||||
|
assert.fail('should have thrown before'); |
||||||
|
}) |
||||||
|
|
||||||
|
it('can be revoked by granter', async () => { |
||||||
|
await token.revokeTokenGrant(receiver, 0, { from: granter }); |
||||||
|
assert.equal(await token.balanceOf(receiver), 0); |
||||||
|
assert.equal(await token.balanceOf(granter), 100); |
||||||
|
}) |
||||||
|
|
||||||
|
it('cannot be revoked by non granter', async () => { |
||||||
|
try { |
||||||
|
await token.revokeTokenGrant(receiver, 0, { from: accounts[3] }); |
||||||
|
} catch(error) { |
||||||
|
return assertJump(error); |
||||||
|
} |
||||||
|
assert.fail('should have thrown before'); |
||||||
|
}) |
||||||
|
|
||||||
|
it('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); |
||||||
|
}) |
||||||
|
|
||||||
|
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); |
||||||
|
}) |
||||||
|
}) |
||||||
|
}); |
@ -0,0 +1,5 @@ |
|||||||
|
module.exports = s => { |
||||||
|
return new Promise(resolve => { |
||||||
|
setTimeout(() => resolve(), s * 1000 + 600) // 600ms breathing room for testrpc to sync
|
||||||
|
}) |
||||||
|
} |
Loading…
Reference in new issue