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
12aadbed
Commit
12aadbed
authored
Mar 06, 2017
by
Jorge Izquierdo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move check to transferFrom and add tests
parent
23703280
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
5 deletions
+22
-5
VestedToken.sol
contracts/token/VestedToken.sol
+5
-5
VestedToken.js
test/VestedToken.js
+17
-0
No files found.
contracts/token/VestedToken.sol
View file @
12aadbed
...
@@ -15,17 +15,17 @@ contract VestedToken is StandardToken {
...
@@ -15,17 +15,17 @@ contract VestedToken is StandardToken {
mapping (address => TokenGrant[]) public grants;
mapping (address => TokenGrant[]) public grants;
modifier canTransfer(uint _value) {
modifier canTransfer(
address _sender,
uint _value) {
if (_value > transferableTokens(
msg.
sender, uint64(now))) throw;
if (_value > transferableTokens(
_
sender, uint64(now))) throw;
_;
_;
}
}
function transfer(address _to, uint _value) canTransfer(_value) returns (bool success) {
function transfer(address _to, uint _value) canTransfer(
msg.sender,
_value) returns (bool success) {
return super.transfer(_to, _value);
return super.transfer(_to, _value);
}
}
function
approve(address _spender, uint _value) canTransfer(
_value) returns (bool success) {
function
transferFrom(address _from, address _to, uint _value) canTransfer(_from,
_value) returns (bool success) {
return super.
approve(_spender
, _value);
return super.
transferFrom(_from, _to
, _value);
}
}
function grantVestedTokens(
function grantVestedTokens(
...
...
test/VestedToken.js
View file @
12aadbed
...
@@ -52,6 +52,16 @@ contract('VestedToken', function(accounts) {
...
@@ -52,6 +52,16 @@ contract('VestedToken', function(accounts) {
assert
.
fail
(
'should have thrown before'
);
assert
.
fail
(
'should have thrown before'
);
})
})
it
(
'throws when trying to transfer from non vested tokens'
,
async
()
=>
{
try
{
await
token
.
approve
(
accounts
[
7
],
1
,
{
from
:
receiver
})
await
token
.
transferFrom
(
receiver
,
accounts
[
7
],
tokenAmount
,
{
from
:
accounts
[
7
]
})
}
catch
(
error
)
{
return
assertJump
(
error
);
}
assert
.
fail
(
'should have thrown before'
);
})
it
(
'can be revoked by granter'
,
async
()
=>
{
it
(
'can be revoked by granter'
,
async
()
=>
{
await
token
.
revokeTokenGrant
(
receiver
,
0
,
{
from
:
granter
});
await
token
.
revokeTokenGrant
(
receiver
,
0
,
{
from
:
granter
});
assert
.
equal
(
await
token
.
balanceOf
(
receiver
),
0
);
assert
.
equal
(
await
token
.
balanceOf
(
receiver
),
0
);
...
@@ -78,5 +88,12 @@ contract('VestedToken', function(accounts) {
...
@@ -78,5 +88,12 @@ contract('VestedToken', function(accounts) {
await
token
.
transfer
(
accounts
[
7
],
tokenAmount
,
{
from
:
receiver
})
await
token
.
transfer
(
accounts
[
7
],
tokenAmount
,
{
from
:
receiver
})
assert
.
equal
(
await
token
.
balanceOf
(
accounts
[
7
]),
tokenAmount
);
assert
.
equal
(
await
token
.
balanceOf
(
accounts
[
7
]),
tokenAmount
);
})
})
it
(
'can approve and transferFrom all tokens after vesting ends'
,
async
()
=>
{
await
timer
(
vesting
+
1
);
await
token
.
approve
(
accounts
[
7
],
tokenAmount
,
{
from
:
receiver
})
await
token
.
transferFrom
(
receiver
,
accounts
[
7
],
tokenAmount
,
{
from
:
accounts
[
7
]
})
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