Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
0a5af4b8
Commit
0a5af4b8
authored
Feb 13, 2017
by
Jorge Izquierdo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change operations order for rounding. Make tests use blocktime as reference time rather than date.
parent
74dfd351
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
28 deletions
+22
-28
VestedToken.sol
contracts/token/VestedToken.sol
+4
-3
VestedToken.js
test/VestedToken.js
+18
-25
No files found.
contracts/token/VestedToken.sol
View file @
0a5af4b8
pragma solidity ^0.4.
4
;
pragma solidity ^0.4.
8
;
import "./StandardToken.sol";
...
...
@@ -37,6 +37,7 @@ contract VestedToken is StandardToken {
balances[msg.sender] = safeAdd(balances[msg.sender], nonVested);
balances[_holder] = safeSub(balances[_holder], nonVested);
Transfer(_holder, msg.sender, nonVested);
}
function tokenGrantsCount(address _holder) constant returns (uint index) {
...
...
@@ -63,12 +64,12 @@ contract VestedToken is StandardToken {
if (time < cliff) return 0;
if (time > vesting) return tokens;
uint256 cliffTokens = safe
Mul(tokens, safeDiv(safeSub(cliff, start), safeSub(vesting, start)
));
uint256 cliffTokens = safe
Div(safeMul(tokens, safeSub(cliff, start)), safeSub(vesting, start
));
vestedTokens = cliffTokens;
uint256 vestingTokens = safeSub(tokens, cliffTokens);
vestedTokens = safeAdd(vestedTokens, safe
Mul(vestingTokens, safeDiv(safeSub(time, cliff), safeSub(vesting, start)
)));
vestedTokens = safeAdd(vestedTokens, safe
Div(safeMul(vestingTokens, safeSub(time, cliff)), safeSub(vesting, start
)));
}
function nonVestedTokens(TokenGrant grant, uint64 time) private constant returns (uint256) {
...
...
test/VestedToken.js
View file @
0a5af4b8
...
...
@@ -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
=
10
000
const
vesting
=
20
000
// 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
);
})
})
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment