Skip to content

Commit

Permalink
TM: Use shared TimeHelpersMock for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo committed Apr 12, 2019
1 parent 4bde044 commit 18a683e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
7 changes: 2 additions & 5 deletions apps/token-manager/contracts/test/mocks/TokenManagerMock.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
pragma solidity 0.4.24;

import "../../TokenManager.sol";
import "@aragon/test-helpers/contracts/TimeHelpersMock.sol";

contract TokenManagerMock is TokenManager, TimeHelpersMock {

contract TokenManagerMock is TokenManager {
uint256 mockTime;

function mock_setTimestamp(uint256 i) public { mockTime = i; }
function getTimestamp() internal view returns (uint256) { return mockTime; }
}
14 changes: 7 additions & 7 deletions apps/token-manager/test/tokenmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract('Token Manager', accounts => {

const receipt = await dao.newAppInstance('0x1234', tokenManagerBase.address, '0x', false, { from: root })
tokenManager = TokenManager.at(receipt.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy)
tokenManager.mock_setTimestamp(NOW_TIME)
tokenManager.mockSetTimestamp(NOW_TIME)

await acl.createPermission(ANY_ADDR, tokenManager.address, MINT_ROLE, root, { from: root })
await acl.createPermission(ANY_ADDR, tokenManager.address, ISSUE_ROLE, root, { from: root })
Expand Down Expand Up @@ -376,22 +376,22 @@ contract('Token Manager', accounts => {
})

it('can start transferring on cliff', async () => {
await tokenManager.mock_setTimestamp(cliffDate)
await tokenManager.mockSetTimestamp(cliffDate)

await token.transfer(holder2, 10, { from: holder })
assert.equal(await token.balanceOf(holder2), 10, 'should have received tokens')
assert.equal(await tokenManager.spendableBalanceOf(holder), 0, 'should not be able to spend more tokens')
})

it('can transfer all tokens after vesting', async () => {
await tokenManager.mock_setTimestamp(vestingDate)
await tokenManager.mockSetTimestamp(vestingDate)

await token.transfer(holder2, totalTokens, { from: holder })
assert.equal(await token.balanceOf(holder2), totalTokens, 'should have received tokens')
})

it('can transfer half mid vesting', async () => {
await tokenManager.mock_setTimestamp(startDate + (vestingDate - startDate) / 2)
await tokenManager.mockSetTimestamp(startDate + (vestingDate - startDate) / 2)

await token.transfer(holder2, 20, { from: holder })

Expand All @@ -413,15 +413,15 @@ contract('Token Manager', accounts => {
})

it('cannot transfer all tokens right before vesting', async () => {
await tokenManager.mock_setTimestamp(vestingDate - 10)
await tokenManager.mockSetTimestamp(vestingDate - 10)

return assertRevert(async () => {
await token.transfer(holder2, totalTokens, { from: holder })
})
})

it('can be revoked and not vested tokens are transfered to token manager', async () => {
await tokenManager.mock_setTimestamp(cliffDate)
await tokenManager.mockSetTimestamp(cliffDate)
await tokenManager.revokeVesting(holder, 0)

await token.transfer(holder2, 5, { from: holder })
Expand Down Expand Up @@ -459,7 +459,7 @@ contract('Token Manager', accounts => {
})

// Can't create a new vesting even after other vestings have finished
await tokenManager.mock_setTimestamp(vestingDate)
await tokenManager.mockSetTimestamp(vestingDate)
await assertRevert(async () => {
await tokenManager.assignVested(holder, 1, startDate, cliffDate, vestingDate, false)
})
Expand Down

0 comments on commit 18a683e

Please sign in to comment.