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
685d2087
Commit
685d2087
authored
Jan 15, 2018
by
AugustoL
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add increase and decrease approval functions to ERC827 with tests
parent
e911b4d5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
1 deletions
+101
-1
ERC827.sol
contracts/token/ERC827.sol
+44
-0
ERC827Token.js
test/ERC827Token.js
+57
-1
No files found.
contracts/token/ERC827.sol
View file @
685d2087
...
@@ -78,4 +78,48 @@ contract ERC827 is StandardToken {
...
@@ -78,4 +78,48 @@ contract ERC827 is StandardToken {
return true;
return true;
}
}
/**
* @dev Addition to StandardToken methods. Increase the amount of tokens that
* an owner allowed to a spender and execute a call with the sent data.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
* @param _data ABI-encoded contract call to call `_spender` address.
*/
function increaseApproval(address _spender, uint _addedValue, bytes _data) public returns (bool) {
require(_spender != address(this));
super.approve(_spender, _addedValue);
require(_spender.call(_data));
return true;
}
/**
* @dev Addition to StandardToken methods. Decrease the amount of tokens that
* an owner allowed to a spender and execute a call with the sent data.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
* @param _data ABI-encoded contract call to call `_spender` address.
*/
function decreaseApproval(address _spender, uint _subtractedValue, bytes _data) public returns (bool) {
require(_spender != address(this));
super.decreaseApproval(_spender, _subtractedValue);
require(_spender.call(_data));
return true;
}
}
}
test/ERC827Token.js
View file @
685d2087
...
@@ -94,7 +94,13 @@ contract('ERC827 Token', function (accounts) {
...
@@ -94,7 +94,13 @@ contract('ERC827 Token', function (accounts) {
});
});
it
(
'should increase by 50 then decrease by 10'
,
async
function
()
{
it
(
'should increase by 50 then decrease by 10'
,
async
function
()
{
await
token
.
increaseApproval
(
accounts
[
1
],
50
);
const
abiMethod
=
findMethod
(
token
.
abi
,
'increaseApproval'
,
'address,uint256'
);
const
increaseApprovalData
=
ethjsABI
.
encodeMethod
(
abiMethod
,
[
accounts
[
1
],
50
]
);
await
token
.
sendTransaction
(
{
from
:
accounts
[
0
],
data
:
increaseApprovalData
}
);
let
postIncrease
=
await
token
.
allowance
(
accounts
[
0
],
accounts
[
1
]);
let
postIncrease
=
await
token
.
allowance
(
accounts
[
0
],
accounts
[
1
]);
preApproved
.
plus
(
50
).
should
.
be
.
bignumber
.
equal
(
postIncrease
);
preApproved
.
plus
(
50
).
should
.
be
.
bignumber
.
equal
(
postIncrease
);
await
token
.
decreaseApproval
(
accounts
[
1
],
10
);
await
token
.
decreaseApproval
(
accounts
[
1
],
10
);
...
@@ -169,6 +175,56 @@ contract('ERC827 Token', function (accounts) {
...
@@ -169,6 +175,56 @@ contract('ERC827 Token', function (accounts) {
});
});
it
(
it
(
'should return correct allowance after increaseApproval (with data) and show the event on receiver contract'
,
async
function
()
{
const
message
=
await
Message
.
new
();
const
extraData
=
message
.
contract
.
showMessage
.
getData
(
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
);
const
abiMethod
=
findMethod
(
token
.
abi
,
'increaseApproval'
,
'address,uint256,bytes'
);
const
increaseApprovalData
=
ethjsABI
.
encodeMethod
(
abiMethod
,
[
message
.
contract
.
address
,
50
,
extraData
]
);
const
transaction
=
await
token
.
sendTransaction
(
{
from
:
accounts
[
0
],
data
:
increaseApprovalData
}
);
assert
.
equal
(
2
,
transaction
.
receipt
.
logs
.
length
);
new
BigNumber
(
50
).
should
.
be
.
bignumber
.
equal
(
await
token
.
allowance
(
accounts
[
0
],
message
.
contract
.
address
)
);
});
it
(
'should return correct allowance after decreaseApproval (with data) and show the event on receiver contract'
,
async
function
()
{
const
message
=
await
Message
.
new
();
await
token
.
approve
(
message
.
contract
.
address
,
100
);
const
extraData
=
message
.
contract
.
showMessage
.
getData
(
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
);
const
abiMethod
=
findMethod
(
token
.
abi
,
'decreaseApproval'
,
'address,uint256,bytes'
);
const
decreaseApprovalData
=
ethjsABI
.
encodeMethod
(
abiMethod
,
[
message
.
contract
.
address
,
60
,
extraData
]
);
const
transaction
=
await
token
.
sendTransaction
(
{
from
:
accounts
[
0
],
data
:
decreaseApprovalData
}
);
assert
.
equal
(
2
,
transaction
.
receipt
.
logs
.
length
);
new
BigNumber
(
40
).
should
.
be
.
bignumber
.
equal
(
await
token
.
allowance
(
accounts
[
0
],
message
.
contract
.
address
)
);
});
it
(
'should return correct balances after transferFrom (with data) and show the event on receiver contract'
'should return correct balances after transferFrom (with data) and show the event on receiver contract'
,
async
function
()
{
,
async
function
()
{
const
message
=
await
Message
.
new
();
const
message
=
await
Message
.
new
();
...
...
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