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
7bd95b1e
Commit
7bd95b1e
authored
Jan 11, 2018
by
AugustoL
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Overload ERC20 funcitons with new _data argument
parent
4ecdf312
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
67 deletions
+101
-67
ERC827.sol
contracts/token/ERC827.sol
+4
-4
ERC827Token.js
test/ERC827Token.js
+97
-63
No files found.
contracts/token/ERC827.sol
View file @
7bd95b1e
...
@@ -13,7 +13,7 @@ import "./StandardToken.sol";
...
@@ -13,7 +13,7 @@ import "./StandardToken.sol";
contract ERC827 is StandardToken {
contract ERC827 is StandardToken {
/**
/**
@dev
`approveData` is an a
ddition to ERC20 token methods. It allows to
@dev
A
ddition to ERC20 token methods. It allows to
approve the transfer of value and execute a call with the sent data.
approve the transfer of value and execute a call with the sent data.
Beware that changing an allowance with this method brings the risk that
Beware that changing an allowance with this method brings the risk that
...
@@ -29,7 +29,7 @@ contract ERC827 is StandardToken {
...
@@ -29,7 +29,7 @@ contract ERC827 is StandardToken {
@return true if the call function was executed successfully
@return true if the call function was executed successfully
*/
*/
function approve
Data
(address _spender, uint256 _value, bytes _data) public returns (bool) {
function approve(address _spender, uint256 _value, bytes _data) public returns (bool) {
require(_spender != address(this));
require(_spender != address(this));
super.approve(_spender, _value);
super.approve(_spender, _value);
...
@@ -49,7 +49,7 @@ contract ERC827 is StandardToken {
...
@@ -49,7 +49,7 @@ contract ERC827 is StandardToken {
@return true if the call function was executed successfully
@return true if the call function was executed successfully
*/
*/
function transfer
Data
(address _to, uint256 _value, bytes _data) public returns (bool) {
function transfer(address _to, uint256 _value, bytes _data) public returns (bool) {
require(_to != address(this));
require(_to != address(this));
super.transfer(_to, _value);
super.transfer(_to, _value);
...
@@ -69,7 +69,7 @@ contract ERC827 is StandardToken {
...
@@ -69,7 +69,7 @@ contract ERC827 is StandardToken {
@return true if the call function was executed successfully
@return true if the call function was executed successfully
*/
*/
function transfer
Data
From(address _from, address _to, uint256 _value, bytes _data) public returns (bool) {
function transferFrom(address _from, address _to, uint256 _value, bytes _data) public returns (bool) {
require(_to != address(this));
require(_to != address(this));
super.transferFrom(_from, _to, _value);
super.transferFrom(_from, _to, _value);
...
...
test/ERC827Token.js
View file @
7bd95b1e
...
@@ -4,7 +4,7 @@ var Message = artifacts.require('./mock/MessageHelper.sol');
...
@@ -4,7 +4,7 @@ var Message = artifacts.require('./mock/MessageHelper.sol');
var
ERC827TokenMock
=
artifacts
.
require
(
'./mock/ERC827TokenMock.sol'
);
var
ERC827TokenMock
=
artifacts
.
require
(
'./mock/ERC827TokenMock.sol'
);
var
BigNumber
=
web3
.
BigNumber
;
var
BigNumber
=
web3
.
BigNumber
;
var
ethjsABI
=
require
(
'ethjs-abi'
);
require
(
'chai'
)
require
(
'chai'
)
.
use
(
require
(
'chai-as-promised'
))
.
use
(
require
(
'chai-as-promised'
))
.
use
(
require
(
'chai-bignumber'
)(
BigNumber
))
.
use
(
require
(
'chai-bignumber'
)(
BigNumber
))
...
@@ -110,33 +110,21 @@ contract('ERC827 Token', function (accounts) {
...
@@ -110,33 +110,21 @@ contract('ERC827 Token', function (accounts) {
.
should
.
be
.
rejectedWith
(
EVMRevert
);
.
should
.
be
.
rejectedWith
(
EVMRevert
);
});
});
it
(
'should return correct balances after approve and show the event on receiver contract'
,
async
function
()
{
describe
(
'Test ERC827 methods'
,
function
()
{
let
message
=
await
Message
.
new
();
let
data
=
message
.
contract
.
showMessage
.
getData
(
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
);
let
transaction
=
await
token
.
approveData
(
message
.
contract
.
address
,
100
,
data
,
{
from
:
accounts
[
0
]
}
);
assert
.
equal
(
2
,
transaction
.
receipt
.
logs
.
length
);
it
(
'should return correct balances after transfer (with data) and show the event on receiver contract'
,
async
function
()
{
const
message
=
await
Message
.
new
();
new
BigNumber
(
100
).
should
.
be
.
bignumber
.
equal
(
const
extraData
=
message
.
contract
.
showMessage
.
getData
(
await
token
.
allowance
(
accounts
[
0
],
message
.
contract
.
address
)
);
});
it
(
'should return correct balances after transferData and show the event on receiver contract'
,
async
function
()
{
let
message
=
await
Message
.
new
();
let
data
=
message
.
contract
.
showMessage
.
getData
(
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
);
);
let
transaction
=
await
token
.
transferData
(
// Use method #8 tranfer of the abi to encode the data tx
message
.
contract
.
address
,
100
,
data
,
{
from
:
accounts
[
0
]
}
const
transferData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
8
],
[
message
.
contract
.
address
,
100
,
extraData
]
);
const
transaction
=
await
token
.
sendTransaction
(
{
from
:
accounts
[
0
],
data
:
transferData
}
);
);
assert
.
equal
(
2
,
transaction
.
receipt
.
logs
.
length
);
assert
.
equal
(
2
,
transaction
.
receipt
.
logs
.
length
);
...
@@ -146,15 +134,19 @@ contract('ERC827 Token', function (accounts) {
...
@@ -146,15 +134,19 @@ contract('ERC827 Token', function (accounts) {
);
);
});
});
it
(
'should return correct allowance after approveData
and show the event on receiver contract'
,
async
function
()
{
it
(
'should return correct allowance after approve (with data)
and show the event on receiver contract'
,
async
function
()
{
le
t
message
=
await
Message
.
new
();
cons
t
message
=
await
Message
.
new
();
let
d
ata
=
message
.
contract
.
showMessage
.
getData
(
const
extraD
ata
=
message
.
contract
.
showMessage
.
getData
(
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
);
);
let
transaction
=
await
token
.
approveData
(
// Use method #3 approve of the abi to encode the data tx
message
.
contract
.
address
,
100
,
data
,
{
from
:
accounts
[
0
]
}
const
approveData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
3
],
[
message
.
contract
.
address
,
100
,
extraData
]
);
const
transaction
=
await
token
.
sendTransaction
(
{
from
:
accounts
[
0
],
data
:
approveData
}
);
);
assert
.
equal
(
2
,
transaction
.
receipt
.
logs
.
length
);
assert
.
equal
(
2
,
transaction
.
receipt
.
logs
.
length
);
...
@@ -164,10 +156,10 @@ contract('ERC827 Token', function (accounts) {
...
@@ -164,10 +156,10 @@ contract('ERC827 Token', function (accounts) {
);
);
});
});
it
(
'should return correct balances after transferFrom
and show the event on receiver contract'
,
async
function
()
{
it
(
'should return correct balances after transferFrom (with data)
and show the event on receiver contract'
,
async
function
()
{
le
t
message
=
await
Message
.
new
();
cons
t
message
=
await
Message
.
new
();
let
d
ata
=
message
.
contract
.
showMessage
.
getData
(
const
extraD
ata
=
message
.
contract
.
showMessage
.
getData
(
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
);
);
...
@@ -177,8 +169,12 @@ contract('ERC827 Token', function (accounts) {
...
@@ -177,8 +169,12 @@ contract('ERC827 Token', function (accounts) {
await
token
.
allowance
(
accounts
[
0
],
accounts
[
1
])
await
token
.
allowance
(
accounts
[
0
],
accounts
[
1
])
);
);
let
transaction
=
await
token
.
transferDataFrom
(
// Use method #7 transferFrom of the abi to encode the data tx
accounts
[
0
],
message
.
contract
.
address
,
100
,
data
,
{
from
:
accounts
[
1
]
}
const
transferFromData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
7
],
[
accounts
[
0
],
message
.
contract
.
address
,
100
,
extraData
]
);
const
transaction
=
await
token
.
sendTransaction
(
{
from
:
accounts
[
1
],
data
:
transferFromData
}
);
);
assert
.
equal
(
2
,
transaction
.
receipt
.
logs
.
length
);
assert
.
equal
(
2
,
transaction
.
receipt
.
logs
.
length
);
...
@@ -188,14 +184,17 @@ contract('ERC827 Token', function (accounts) {
...
@@ -188,14 +184,17 @@ contract('ERC827 Token', function (accounts) {
);
);
});
});
it
(
'should fail inside approveData
'
,
async
function
()
{
it
(
'should fail inside approve (with data)
'
,
async
function
()
{
le
t
message
=
await
Message
.
new
();
cons
t
message
=
await
Message
.
new
();
let
d
ata
=
message
.
contract
.
fail
.
getData
();
const
extraD
ata
=
message
.
contract
.
fail
.
getData
();
await
token
.
approveData
(
// Use method #3 approve of the abi to encode the data tx
message
.
contract
.
address
,
10
,
data
,
const
approveData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
3
],
{
from
:
accounts
[
1
]
}
[
message
.
contract
.
address
,
10
,
extraData
]
);
await
token
.
sendTransaction
(
{
from
:
accounts
[
0
],
data
:
approveData
}
).
should
.
be
.
rejectedWith
(
EVMRevert
);
).
should
.
be
.
rejectedWith
(
EVMRevert
);
// approval should not have gone through so allowance is still 0
// approval should not have gone through so allowance is still 0
...
@@ -203,14 +202,17 @@ contract('ERC827 Token', function (accounts) {
...
@@ -203,14 +202,17 @@ contract('ERC827 Token', function (accounts) {
.
equal
(
await
token
.
allowance
(
accounts
[
1
],
message
.
contract
.
address
));
.
equal
(
await
token
.
allowance
(
accounts
[
1
],
message
.
contract
.
address
));
});
});
it
(
'should fail inside transferData
'
,
async
function
()
{
it
(
'should fail inside transfer (with data)
'
,
async
function
()
{
le
t
message
=
await
Message
.
new
();
cons
t
message
=
await
Message
.
new
();
let
d
ata
=
message
.
contract
.
fail
.
getData
();
const
extraD
ata
=
message
.
contract
.
fail
.
getData
();
await
token
.
transferData
(
// Use method #8 tranfer of the abi to encode the data tx
message
.
contract
.
address
,
10
,
data
,
const
transferData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
8
],
{
from
:
accounts
[
0
]
}
[
message
.
contract
.
address
,
10
,
extraData
]
);
await
token
.
sendTransaction
(
{
from
:
accounts
[
0
],
data
:
transferData
}
).
should
.
be
.
rejectedWith
(
EVMRevert
);
).
should
.
be
.
rejectedWith
(
EVMRevert
);
// transfer should not have gone through, so balance is still 0
// transfer should not have gone through, so balance is still 0
...
@@ -218,44 +220,76 @@ contract('ERC827 Token', function (accounts) {
...
@@ -218,44 +220,76 @@ contract('ERC827 Token', function (accounts) {
.
equal
(
await
token
.
balanceOf
(
message
.
contract
.
address
));
.
equal
(
await
token
.
balanceOf
(
message
.
contract
.
address
));
});
});
it
(
'should fail inside transferDataFrom
'
,
async
function
()
{
it
(
'should fail inside transferFrom (with data)
'
,
async
function
()
{
le
t
message
=
await
Message
.
new
();
cons
t
message
=
await
Message
.
new
();
let
d
ata
=
message
.
contract
.
fail
.
getData
();
const
extraD
ata
=
message
.
contract
.
fail
.
getData
();
await
token
.
approve
(
accounts
[
1
],
10
,
{
from
:
accounts
[
2
]
});
await
token
.
approve
(
accounts
[
1
],
10
,
{
from
:
accounts
[
2
]
});
await
token
.
transferDataFrom
(
// Use method #7 tranferFrom of the abi to encode the data tx
accounts
[
2
],
message
.
contract
.
address
,
10
,
data
,
const
transferFromData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
7
],
{
from
:
accounts
[
1
]
}
[
accounts
[
2
],
message
.
contract
.
address
,
10
,
extraData
]
);
await
token
.
sendTransaction
(
{
from
:
accounts
[
1
],
data
:
transferFromData
}
).
should
.
be
.
rejectedWith
(
EVMRevert
);
).
should
.
be
.
rejectedWith
(
EVMRevert
);
// transferData
From should have failed so balance is still 0 but allowance is 10
// transfer
From should have failed so balance is still 0 but allowance is 10
new
BigNumber
(
10
).
should
.
be
.
bignumber
new
BigNumber
(
10
).
should
.
be
.
bignumber
.
equal
(
await
token
.
allowance
(
accounts
[
2
],
accounts
[
1
]));
.
equal
(
await
token
.
allowance
(
accounts
[
2
],
accounts
[
1
]));
new
BigNumber
(
0
).
should
.
be
.
bignumber
new
BigNumber
(
0
).
should
.
be
.
bignumber
.
equal
(
await
token
.
balanceOf
(
message
.
contract
.
address
));
.
equal
(
await
token
.
balanceOf
(
message
.
contract
.
address
));
});
});
it
(
'should fail approveData when using token contract address as receiver'
,
async
function
()
{
it
(
'should fail approve (with data) when using token contract address as receiver'
,
async
function
()
{
let
data
=
token
.
contract
.
approve
.
getData
(
accounts
[
5
],
66
);
const
message
=
await
Message
.
new
();
const
extraData
=
message
.
contract
.
showMessage
.
getData
(
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
);
await
token
.
approveData
(
// Use method #3 approve of the abi to encode the data tx
token
.
contract
.
address
,
100
,
data
,
const
approveData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
3
],
{
from
:
accounts
[
0
]
}
[
token
.
contract
.
address
,
100
,
extraData
]
);
await
token
.
sendTransaction
(
{
from
:
accounts
[
0
],
data
:
approveData
}
).
should
.
be
.
rejectedWith
(
EVMRevert
);
).
should
.
be
.
rejectedWith
(
EVMRevert
);
});
});
it
(
'should fail transferData when using token contract address as receiver'
,
async
function
()
{
it
(
'should fail transfer (with data) when using token contract address as receiver'
,
async
function
()
{
await
token
.
transferData
(
const
message
=
await
Message
.
new
();
token
.
contract
.
address
,
100
,
web3
.
toHex
(
0
),
{
from
:
accounts
[
0
]
}
const
extraData
=
message
.
contract
.
showMessage
.
getData
(
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
);
// Use method #8 tranfer of the abi to encode the data tx
const
transferData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
8
],
[
token
.
contract
.
address
,
100
,
extraData
]
);
await
token
.
sendTransaction
(
{
from
:
accounts
[
0
],
data
:
transferData
}
).
should
.
be
.
rejectedWith
(
EVMRevert
);
).
should
.
be
.
rejectedWith
(
EVMRevert
);
});
});
it
(
'should fail transferDataFrom when using token contract address as receiver'
,
async
function
()
{
it
(
'should fail transferFrom (with data) when using token contract address as receiver'
,
async
function
()
{
const
message
=
await
Message
.
new
();
const
extraData
=
message
.
contract
.
showMessage
.
getData
(
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
);
await
token
.
approve
(
accounts
[
1
],
1
,
{
from
:
accounts
[
0
]
});
await
token
.
approve
(
accounts
[
1
],
1
,
{
from
:
accounts
[
0
]
});
await
token
.
transferDataFrom
(
accounts
[
0
],
token
.
contract
.
address
,
1
,
web3
.
toHex
(
0
),
{
from
:
accounts
[
1
]
}
// Use method #7 tranferFrom of the abi to encode the data tx
const
transferFromData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
7
],
[
accounts
[
0
],
token
.
contract
.
address
,
1
,
extraData
]
);
await
token
.
sendTransaction
(
{
from
:
accounts
[
1
],
data
:
transferFromData
}
).
should
.
be
.
rejectedWith
(
EVMRevert
);
).
should
.
be
.
rejectedWith
(
EVMRevert
);
});
});
});
});
});
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