From 713b47225356225e46bba6698823fd96ba8ab463 Mon Sep 17 00:00:00 2001 From: Jorge Izquierdo Date: Sun, 21 May 2017 11:17:24 +0200 Subject: [PATCH] Add tests for non-revokable and revokable/burnable cases --- test/VestedToken.js | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test/VestedToken.js b/test/VestedToken.js index c4d4ba53f..8f65c333d 100644 --- a/test/VestedToken.js +++ b/test/VestedToken.js @@ -96,4 +96,61 @@ contract('VestedToken', function(accounts) { assert.equal(await token.balanceOf(accounts[7]), tokenAmount); }) }) + + describe('getting a non-revokable token grant', async () => { + const cliff = 10000 + const vesting = 20000 // seconds + + beforeEach(async () => { + await token.grantVestedTokens(receiver, tokenAmount, now, now + cliff, now + vesting, false, false, { from: granter }) + }) + + it('tokens are received', async () => { + assert.equal(await token.balanceOf(receiver), tokenAmount); + }) + + it('throws when granter attempts to revoke', async () => { + try { + await token.revokeTokenGrant(receiver, 0, { from: granter }); + } catch(error) { + return assertJump(error); + } + assert.fail('should have thrown before'); + }) + }) + + describe('getting a revokable/burnable token grant', async () => { + const cliff = 100000 + const vesting = 200000 // seconds + const burnAddress = '0x000000000000000000000000000000000000dead' + + beforeEach(async () => { + await token.grantVestedTokens(receiver, tokenAmount, now, now + cliff, now + vesting, true, true, { from: granter }) + }) + + it('tokens are received', async () => { + assert.equal(await token.balanceOf(receiver), tokenAmount); + }) + + it('can be revoked by granter and tokens are burned', async () => { + await token.revokeTokenGrant(receiver, 0, { from: granter }); + assert.equal(await token.balanceOf(receiver), 0); + assert.equal(await token.balanceOf(burnAddress), tokenAmount); + }) + + 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(burnAddress), tokenAmount * cliff / vesting); + }) + }) });