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
e911b4d5
Commit
e911b4d5
authored
Jan 12, 2018
by
AugustoL
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add findMethod function in ERC827Token test
parent
7bd95b1e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
84 deletions
+98
-84
ERC827Token.js
test/ERC827Token.js
+98
-84
No files found.
test/ERC827Token.js
View file @
e911b4d5
...
...
@@ -4,6 +4,7 @@ var Message = artifacts.require('./mock/MessageHelper.sol');
var
ERC827TokenMock
=
artifacts
.
require
(
'./mock/ERC827TokenMock.sol'
);
var
BigNumber
=
web3
.
BigNumber
;
var
_
=
require
(
'lodash'
);
var
ethjsABI
=
require
(
'ethjs-abi'
);
require
(
'chai'
)
.
use
(
require
(
'chai-as-promised'
))
...
...
@@ -13,6 +14,15 @@ require('chai')
contract
(
'ERC827 Token'
,
function
(
accounts
)
{
let
token
;
function
findMethod
(
abi
,
name
,
args
)
{
for
(
var
i
=
0
;
i
<
abi
.
length
;
i
++
)
{
const
methodArgs
=
_
.
map
(
abi
[
i
].
inputs
,
'type'
).
join
(
','
);
if
((
abi
[
i
].
name
===
name
)
&&
(
methodArgs
===
args
))
{
return
abi
[
i
];
}
}
}
beforeEach
(
async
function
()
{
token
=
await
ERC827TokenMock
.
new
(
accounts
[
0
],
100
);
});
...
...
@@ -111,86 +121,90 @@ contract('ERC827 Token', function (accounts) {
});
describe
(
'Test ERC827 methods'
,
function
()
{
it
(
'should return correct balances after transfer (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'
);
// Use method #8 tranfer of the abi to encode the data tx
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
);
new
BigNumber
(
100
).
should
.
be
.
bignumber
.
equal
(
await
token
.
balanceOf
(
message
.
contract
.
address
)
);
});
it
(
'should return correct allowance after approve (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'
);
// Use method #3 approve of the abi to encode the data tx
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
);
new
BigNumber
(
100
).
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'
,
async
function
()
{
const
message
=
await
Message
.
new
();
const
extraData
=
message
.
contract
.
showMessage
.
getData
(
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
);
await
token
.
approve
(
accounts
[
1
],
100
,
{
from
:
accounts
[
0
]
});
new
BigNumber
(
100
).
should
.
be
.
bignumber
.
equal
(
await
token
.
allowance
(
accounts
[
0
],
accounts
[
1
])
);
// Use method #7 transferFrom of the abi to encode the data tx
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
);
new
BigNumber
(
100
).
should
.
be
.
bignumber
.
equal
(
await
token
.
balanceOf
(
message
.
contract
.
address
)
);
});
it
(
'should return correct balances after transfer (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
,
'transfer'
,
'address,uint256,bytes'
);
const
transferData
=
ethjsABI
.
encodeMethod
(
abiMethod
,
[
message
.
contract
.
address
,
100
,
extraData
]
);
const
transaction
=
await
token
.
sendTransaction
(
{
from
:
accounts
[
0
],
data
:
transferData
}
);
assert
.
equal
(
2
,
transaction
.
receipt
.
logs
.
length
);
new
BigNumber
(
100
).
should
.
be
.
bignumber
.
equal
(
await
token
.
balanceOf
(
message
.
contract
.
address
)
);
});
it
(
'should return correct allowance after approve (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
,
'approve'
,
'address,uint256,bytes'
);
const
approveData
=
ethjsABI
.
encodeMethod
(
abiMethod
,
[
message
.
contract
.
address
,
100
,
extraData
]
);
const
transaction
=
await
token
.
sendTransaction
(
{
from
:
accounts
[
0
],
data
:
approveData
}
);
assert
.
equal
(
2
,
transaction
.
receipt
.
logs
.
length
);
new
BigNumber
(
100
).
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'
,
async
function
()
{
const
message
=
await
Message
.
new
();
const
extraData
=
message
.
contract
.
showMessage
.
getData
(
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
);
await
token
.
approve
(
accounts
[
1
],
100
,
{
from
:
accounts
[
0
]
});
new
BigNumber
(
100
).
should
.
be
.
bignumber
.
equal
(
await
token
.
allowance
(
accounts
[
0
],
accounts
[
1
])
);
const
abiMethod
=
findMethod
(
token
.
abi
,
'transferFrom'
,
'address,address,uint256,bytes'
);
const
transferFromData
=
ethjsABI
.
encodeMethod
(
abiMethod
,
[
accounts
[
0
],
message
.
contract
.
address
,
100
,
extraData
]
);
const
transaction
=
await
token
.
sendTransaction
(
{
from
:
accounts
[
1
],
data
:
transferFromData
}
);
assert
.
equal
(
2
,
transaction
.
receipt
.
logs
.
length
);
new
BigNumber
(
100
).
should
.
be
.
bignumber
.
equal
(
await
token
.
balanceOf
(
message
.
contract
.
address
)
);
});
it
(
'should fail inside approve (with data)'
,
async
function
()
{
const
message
=
await
Message
.
new
();
const
extraData
=
message
.
contract
.
fail
.
getData
();
// Use method #3 approve of the abi to encode the data tx
const
approveData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
3
]
,
const
abiMethod
=
findMethod
(
token
.
abi
,
'approve'
,
'address,uint256,bytes'
);
const
approveData
=
ethjsABI
.
encodeMethod
(
abiMethod
,
[
message
.
contract
.
address
,
10
,
extraData
]
);
await
token
.
sendTransaction
(
...
...
@@ -207,8 +221,8 @@ contract('ERC827 Token', function (accounts) {
const
extraData
=
message
.
contract
.
fail
.
getData
();
// Use method #8 tranfer of the abi to encode the data tx
const
transferData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
8
]
,
const
abiMethod
=
findMethod
(
token
.
abi
,
'transfer'
,
'address,uint256,bytes'
);
const
transferData
=
ethjsABI
.
encodeMethod
(
abiMethod
,
[
message
.
contract
.
address
,
10
,
extraData
]
);
await
token
.
sendTransaction
(
...
...
@@ -227,8 +241,8 @@ contract('ERC827 Token', function (accounts) {
await
token
.
approve
(
accounts
[
1
],
10
,
{
from
:
accounts
[
2
]
});
// Use method #7 tranferFrom of the abi to encode the data tx
const
transferFromData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
7
]
,
const
abiMethod
=
findMethod
(
token
.
abi
,
'transferFrom'
,
'address,address,uint256,bytes'
);
const
transferFromData
=
ethjsABI
.
encodeMethod
(
abiMethod
,
[
accounts
[
2
],
message
.
contract
.
address
,
10
,
extraData
]
);
await
token
.
sendTransaction
(
...
...
@@ -249,8 +263,8 @@ contract('ERC827 Token', function (accounts) {
web3
.
toHex
(
123456
),
666
,
'Transfer Done'
);
// Use method #3 approve of the abi to encode the data tx
const
approveData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
3
]
,
const
abiMethod
=
findMethod
(
token
.
abi
,
'approve'
,
'address,uint256,bytes'
);
const
approveData
=
ethjsABI
.
encodeMethod
(
abiMethod
,
[
token
.
contract
.
address
,
100
,
extraData
]
);
await
token
.
sendTransaction
(
...
...
@@ -265,8 +279,8 @@ contract('ERC827 Token', function (accounts) {
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
]
,
const
abiMethod
=
findMethod
(
token
.
abi
,
'transfer'
,
'address,uint256,bytes'
);
const
transferData
=
ethjsABI
.
encodeMethod
(
abiMethod
,
[
token
.
contract
.
address
,
100
,
extraData
]
);
await
token
.
sendTransaction
(
...
...
@@ -283,8 +297,8 @@ contract('ERC827 Token', function (accounts) {
await
token
.
approve
(
accounts
[
1
],
1
,
{
from
:
accounts
[
0
]
});
// Use method #7 tranferFrom of the abi to encode the data tx
const
transferFromData
=
ethjsABI
.
encodeMethod
(
token
.
abi
[
7
]
,
const
abiMethod
=
findMethod
(
token
.
abi
,
'transferFrom'
,
'address,address,uint256,bytes'
);
const
transferFromData
=
ethjsABI
.
encodeMethod
(
abiMethod
,
[
accounts
[
0
],
token
.
contract
.
address
,
1
,
extraData
]
);
await
token
.
sendTransaction
(
...
...
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