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
56365753
Commit
56365753
authored
Aug 28, 2017
by
Francisco Giordano
Committed by
GitHub
Aug 28, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #415 from frangio/merge-411-manually
Check that destination of token transfers is not 0x0
parents
307d34e0
00f80c72
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
1 deletions
+36
-1
BasicToken.sol
contracts/token/BasicToken.sol
+2
-0
StandardToken.sol
contracts/token/StandardToken.sol
+2
-0
BasicToken.js
test/BasicToken.js
+11
-1
StandardToken.js
test/StandardToken.js
+21
-0
No files found.
contracts/token/BasicToken.sol
View file @
56365753
...
@@ -20,6 +20,8 @@ contract BasicToken is ERC20Basic {
...
@@ -20,6 +20,8 @@ contract BasicToken is ERC20Basic {
* @param _value The amount to be transferred.
* @param _value The amount to be transferred.
*/
*/
function transfer(address _to, uint256 _value) returns (bool) {
function transfer(address _to, uint256 _value) returns (bool) {
require(_to != address(0));
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
Transfer(msg.sender, _to, _value);
...
...
contracts/token/StandardToken.sol
View file @
56365753
...
@@ -24,6 +24,8 @@ contract StandardToken is ERC20, BasicToken {
...
@@ -24,6 +24,8 @@ contract StandardToken is ERC20, BasicToken {
* @param _value uint256 the amount of tokens to be transferred
* @param _value uint256 the amount of tokens to be transferred
*/
*/
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
require(_to != address(0));
var _allowance = allowed[_from][msg.sender];
var _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
...
...
test/BasicToken.js
View file @
56365753
...
@@ -22,7 +22,7 @@ contract('BasicToken', function(accounts) {
...
@@ -22,7 +22,7 @@ contract('BasicToken', function(accounts) {
assert
.
equal
(
secondAccountBalance
,
100
);
assert
.
equal
(
secondAccountBalance
,
100
);
});
});
it
(
"should throw an error when trying to transfer more than balance"
,
async
function
()
{
it
(
'should throw an error when trying to transfer more than balance'
,
async
function
()
{
let
token
=
await
BasicTokenMock
.
new
(
accounts
[
0
],
100
);
let
token
=
await
BasicTokenMock
.
new
(
accounts
[
0
],
100
);
try
{
try
{
let
transfer
=
await
token
.
transfer
(
accounts
[
1
],
101
);
let
transfer
=
await
token
.
transfer
(
accounts
[
1
],
101
);
...
@@ -32,4 +32,14 @@ contract('BasicToken', function(accounts) {
...
@@ -32,4 +32,14 @@ contract('BasicToken', function(accounts) {
}
}
});
});
it
(
'should throw an error when trying to transfer to 0x0'
,
async
function
()
{
let
token
=
await
BasicTokenMock
.
new
(
accounts
[
0
],
100
);
try
{
let
transfer
=
await
token
.
transfer
(
0x0
,
100
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertJump
(
error
);
}
});
});
});
test/StandardToken.js
View file @
56365753
...
@@ -88,4 +88,25 @@ contract('StandardToken', function(accounts) {
...
@@ -88,4 +88,25 @@ contract('StandardToken', function(accounts) {
})
})
});
});
it
(
'should throw an error when trying to transfer to 0x0'
,
async
function
()
{
let
token
=
await
StandardTokenMock
.
new
(
accounts
[
0
],
100
);
try
{
let
transfer
=
await
token
.
transfer
(
0x0
,
100
);
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertJump
(
error
);
}
});
it
(
'should throw an error when trying to transferFrom to 0x0'
,
async
function
()
{
let
token
=
await
StandardTokenMock
.
new
(
accounts
[
0
],
100
);
await
token
.
approve
(
accounts
[
1
],
100
);
try
{
let
transfer
=
await
token
.
transferFrom
(
accounts
[
0
],
0x0
,
100
,
{
from
:
accounts
[
1
]});
assert
.
fail
(
'should have thrown before'
);
}
catch
(
error
)
{
assertJump
(
error
);
}
});
});
});
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