Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
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
张蕾
Geth-Modification
Commits
e79821ca
Commit
e79821ca
authored
Dec 13, 2018
by
tzapu
Committed by
Guillaume Ballet
Dec 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi: argument type and name were reversed (#17947)
argument type and name were reversed
parent
e57e4571
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
104 additions
and
10 deletions
+104
-10
event.go
accounts/abi/event.go
+3
-3
event_test.go
accounts/abi/event_test.go
+37
-4
method.go
accounts/abi/method.go
+3
-3
method_test.go
accounts/abi/method_test.go
+61
-0
No files found.
accounts/abi/event.go
View file @
e79821ca
...
@@ -36,12 +36,12 @@ type Event struct {
...
@@ -36,12 +36,12 @@ type Event struct {
func
(
e
Event
)
String
()
string
{
func
(
e
Event
)
String
()
string
{
inputs
:=
make
([]
string
,
len
(
e
.
Inputs
))
inputs
:=
make
([]
string
,
len
(
e
.
Inputs
))
for
i
,
input
:=
range
e
.
Inputs
{
for
i
,
input
:=
range
e
.
Inputs
{
inputs
[
i
]
=
fmt
.
Sprintf
(
"%v %v"
,
input
.
Name
,
input
.
Typ
e
)
inputs
[
i
]
=
fmt
.
Sprintf
(
"%v %v"
,
input
.
Type
,
input
.
Nam
e
)
if
input
.
Indexed
{
if
input
.
Indexed
{
inputs
[
i
]
=
fmt
.
Sprintf
(
"%v indexed %v"
,
input
.
Name
,
input
.
Typ
e
)
inputs
[
i
]
=
fmt
.
Sprintf
(
"%v indexed %v"
,
input
.
Type
,
input
.
Nam
e
)
}
}
}
}
return
fmt
.
Sprintf
(
"e %v(%v)"
,
e
.
Name
,
strings
.
Join
(
inputs
,
", "
))
return
fmt
.
Sprintf
(
"e
vent
%v(%v)"
,
e
.
Name
,
strings
.
Join
(
inputs
,
", "
))
}
}
// Id returns the canonical representation of the event's signature used by the
// Id returns the canonical representation of the event's signature used by the
...
...
accounts/abi/event_test.go
View file @
e79821ca
...
@@ -87,12 +87,12 @@ func TestEventId(t *testing.T) {
...
@@ -87,12 +87,12 @@ func TestEventId(t *testing.T) {
}{
}{
{
{
definition
:
`[
definition
:
`[
{ "type" : "event", "name" : "
b
alance", "inputs": [{ "name" : "in", "type": "uint256" }] },
{ "type" : "event", "name" : "
B
alance", "inputs": [{ "name" : "in", "type": "uint256" }] },
{ "type" : "event", "name" : "
c
heck", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] }
{ "type" : "event", "name" : "
C
heck", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] }
]`
,
]`
,
expectations
:
map
[
string
]
common
.
Hash
{
expectations
:
map
[
string
]
common
.
Hash
{
"
balance"
:
crypto
.
Keccak256Hash
([]
byte
(
"b
alance(uint256)"
)),
"
Balance"
:
crypto
.
Keccak256Hash
([]
byte
(
"B
alance(uint256)"
)),
"
check"
:
crypto
.
Keccak256Hash
([]
byte
(
"c
heck(address,uint256)"
)),
"
Check"
:
crypto
.
Keccak256Hash
([]
byte
(
"C
heck(address,uint256)"
)),
},
},
},
},
}
}
...
@@ -111,6 +111,39 @@ func TestEventId(t *testing.T) {
...
@@ -111,6 +111,39 @@ func TestEventId(t *testing.T) {
}
}
}
}
func
TestEventString
(
t
*
testing
.
T
)
{
var
table
=
[]
struct
{
definition
string
expectations
map
[
string
]
string
}{
{
definition
:
`[
{ "type" : "event", "name" : "Balance", "inputs": [{ "name" : "in", "type": "uint256" }] },
{ "type" : "event", "name" : "Check", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] },
{ "type" : "event", "name" : "Transfer", "inputs": [{ "name": "from", "type": "address", "indexed": true }, { "name": "to", "type": "address", "indexed": true }, { "name": "value", "type": "uint256" }] }
]`
,
expectations
:
map
[
string
]
string
{
"Balance"
:
"event Balance(uint256 in)"
,
"Check"
:
"event Check(address t, uint256 b)"
,
"Transfer"
:
"event Transfer(address indexed from, address indexed to, uint256 value)"
,
},
},
}
for
_
,
test
:=
range
table
{
abi
,
err
:=
JSON
(
strings
.
NewReader
(
test
.
definition
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
name
,
event
:=
range
abi
.
Events
{
if
event
.
String
()
!=
test
.
expectations
[
name
]
{
t
.
Errorf
(
"expected string to be %s, got %s"
,
test
.
expectations
[
name
],
event
.
String
())
}
}
}
}
// TestEventMultiValueWithArrayUnpack verifies that array fields will be counted after parsing array.
// TestEventMultiValueWithArrayUnpack verifies that array fields will be counted after parsing array.
func
TestEventMultiValueWithArrayUnpack
(
t
*
testing
.
T
)
{
func
TestEventMultiValueWithArrayUnpack
(
t
*
testing
.
T
)
{
definition
:=
`[{"name": "test", "type": "event", "inputs": [{"indexed": false, "name":"value1", "type":"uint8[2]"},{"indexed": false, "name":"value2", "type":"uint8"}]}]`
definition
:=
`[{"name": "test", "type": "event", "inputs": [{"indexed": false, "name":"value1", "type":"uint8[2]"},{"indexed": false, "name":"value2", "type":"uint8"}]}]`
...
...
accounts/abi/method.go
View file @
e79821ca
...
@@ -56,14 +56,14 @@ func (method Method) Sig() string {
...
@@ -56,14 +56,14 @@ func (method Method) Sig() string {
func
(
method
Method
)
String
()
string
{
func
(
method
Method
)
String
()
string
{
inputs
:=
make
([]
string
,
len
(
method
.
Inputs
))
inputs
:=
make
([]
string
,
len
(
method
.
Inputs
))
for
i
,
input
:=
range
method
.
Inputs
{
for
i
,
input
:=
range
method
.
Inputs
{
inputs
[
i
]
=
fmt
.
Sprintf
(
"%v %v"
,
input
.
Name
,
input
.
Typ
e
)
inputs
[
i
]
=
fmt
.
Sprintf
(
"%v %v"
,
input
.
Type
,
input
.
Nam
e
)
}
}
outputs
:=
make
([]
string
,
len
(
method
.
Outputs
))
outputs
:=
make
([]
string
,
len
(
method
.
Outputs
))
for
i
,
output
:=
range
method
.
Outputs
{
for
i
,
output
:=
range
method
.
Outputs
{
outputs
[
i
]
=
output
.
Type
.
String
()
if
len
(
output
.
Name
)
>
0
{
if
len
(
output
.
Name
)
>
0
{
outputs
[
i
]
=
fmt
.
Sprintf
(
"%v
"
,
output
.
Name
)
outputs
[
i
]
+=
fmt
.
Sprintf
(
" %v
"
,
output
.
Name
)
}
}
outputs
[
i
]
+=
output
.
Type
.
String
()
}
}
constant
:=
""
constant
:=
""
if
method
.
Const
{
if
method
.
Const
{
...
...
accounts/abi/method_test.go
0 → 100644
View file @
e79821ca
// Copyright 2016 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
abi
import
(
"strings"
"testing"
)
const
methoddata
=
`
[
{ "type" : "function", "name" : "balance", "constant" : true },
{ "type" : "function", "name" : "send", "constant" : false, "inputs" : [ { "name" : "amount", "type" : "uint256" } ] },
{ "type" : "function", "name" : "transfer", "constant" : false, "inputs" : [ { "name" : "from", "type" : "address" }, { "name" : "to", "type" : "address" }, { "name" : "value", "type" : "uint256" } ], "outputs" : [ { "name" : "success", "type" : "bool" } ] }
]`
func
TestMethodString
(
t
*
testing
.
T
)
{
var
table
=
[]
struct
{
method
string
expectation
string
}{
{
method
:
"balance"
,
expectation
:
"function balance() constant returns()"
,
},
{
method
:
"send"
,
expectation
:
"function send(uint256 amount) returns()"
,
},
{
method
:
"transfer"
,
expectation
:
"function transfer(address from, address to, uint256 value) returns(bool success)"
,
},
}
abi
,
err
:=
JSON
(
strings
.
NewReader
(
methoddata
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
_
,
test
:=
range
table
{
got
:=
abi
.
Methods
[
test
.
method
]
.
String
()
if
got
!=
test
.
expectation
{
t
.
Errorf
(
"expected string to be %s, got %s"
,
test
.
expectation
,
got
)
}
}
}
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