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
c62d5422
Commit
c62d5422
authored
Jun 21, 2017
by
Bas van Kervel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whisper: use hexutil.UnmarshalFixedText for topic parsing
parent
a4e4c76c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
34 deletions
+27
-34
consolecmd.go
cmd/geth/consolecmd.go
+1
-1
topic.go
whisper/whisperv5/topic.go
+6
-16
topic_test.go
whisper/whisperv5/topic_test.go
+20
-17
No files found.
cmd/geth/consolecmd.go
View file @
c62d5422
...
...
@@ -35,7 +35,7 @@ var (
Action
:
utils
.
MigrateFlags
(
localConsole
),
Name
:
"console"
,
Usage
:
"Start an interactive JavaScript environment"
,
Flags
:
append
(
append
(
nodeFlags
,
rpcFlags
...
),
console
Flags
...
),
Flags
:
append
(
append
(
append
(
nodeFlags
,
rpcFlags
...
),
consoleFlags
...
),
whisper
Flags
...
),
Category
:
"CONSOLE COMMANDS"
,
Description
:
`
The Geth console is an interactive shell for the JavaScript runtime environment
...
...
whisper/whisperv5/topic.go
View file @
c62d5422
...
...
@@ -19,9 +19,6 @@
package
whisperv5
import
(
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)
...
...
@@ -47,19 +44,12 @@ func (topic *TopicType) String() string {
return
string
(
common
.
ToHex
(
topic
[
:
]))
}
func
(
t
*
TopicType
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
hexutil
.
Bytes
(
t
[
:
]))
// MarshalText returns the hex representation of t.
func
(
t
TopicType
)
MarshalText
()
([]
byte
,
error
)
{
return
hexutil
.
Bytes
(
t
[
:
])
.
MarshalText
()
}
// UnmarshalJSON parses a hex representation to a topic.
func
(
t
*
TopicType
)
UnmarshalJSON
(
input
[]
byte
)
error
{
var
data
hexutil
.
Bytes
if
err
:=
json
.
Unmarshal
(
input
,
&
data
);
err
!=
nil
{
return
err
}
if
len
(
data
)
!=
TopicLength
{
return
fmt
.
Errorf
(
"unmarshalJSON failed: topic must be exactly %d bytes(%d)"
,
TopicLength
,
len
(
input
))
}
*
t
=
BytesToTopic
(
data
)
return
nil
// UnmarshalText parses a hex representation to a topic.
func
(
t
*
TopicType
)
UnmarshalText
(
input
[]
byte
)
error
{
return
hexutil
.
UnmarshalFixedText
(
"Topic"
,
input
,
t
[
:
])
}
whisper/whisperv5/topic_test.go
View file @
c62d5422
...
...
@@ -16,7 +16,10 @@
package
whisperv5
import
"testing"
import
(
"encoding/json"
"testing"
)
var
topicStringTests
=
[]
struct
{
topic
TopicType
...
...
@@ -53,15 +56,6 @@ var bytesToTopicTests = []struct {
{
topic
:
TopicType
{
0x00
,
0x00
,
0x00
,
0x00
},
data
:
nil
},
}
func
TestBytesToTopic
(
t
*
testing
.
T
)
{
for
i
,
tst
:=
range
bytesToTopicTests
{
top
:=
BytesToTopic
(
tst
.
data
)
if
top
!=
tst
.
topic
{
t
.
Fatalf
(
"failed test %d: have %v, want %v."
,
i
,
t
,
tst
.
topic
)
}
}
}
var
unmarshalTestsGood
=
[]
struct
{
topic
TopicType
data
[]
byte
...
...
@@ -94,14 +88,23 @@ var unmarshalTestsUgly = []struct {
{
topic
:
TopicType
{
0x01
,
0x00
,
0x00
,
0x00
},
data
:
[]
byte
(
`"0x00000001"`
)},
}
func
TestBytesToTopic
(
t
*
testing
.
T
)
{
for
i
,
tst
:=
range
bytesToTopicTests
{
top
:=
BytesToTopic
(
tst
.
data
)
if
top
!=
tst
.
topic
{
t
.
Fatalf
(
"failed test %d: have %v, want %v."
,
i
,
t
,
tst
.
topic
)
}
}
}
func
TestUnmarshalTestsGood
(
t
*
testing
.
T
)
{
for
i
,
tst
:=
range
unmarshalTestsGood
{
var
top
TopicType
err
:=
top
.
UnmarshalJSON
(
tst
.
data
)
err
:=
json
.
Unmarshal
(
tst
.
data
,
&
top
)
if
err
!=
nil
{
t
.
Fatal
f
(
"failed test %d. input: %v. err: %v"
,
i
,
tst
.
data
,
err
)
t
.
Error
f
(
"failed test %d. input: %v. err: %v"
,
i
,
tst
.
data
,
err
)
}
else
if
top
!=
tst
.
topic
{
t
.
Fatal
f
(
"failed test %d: have %v, want %v."
,
i
,
t
,
tst
.
topic
)
t
.
Error
f
(
"failed test %d: have %v, want %v."
,
i
,
t
,
tst
.
topic
)
}
}
}
...
...
@@ -110,7 +113,7 @@ func TestUnmarshalTestsBad(t *testing.T) {
// in this test UnmarshalJSON() is supposed to fail
for
i
,
tst
:=
range
unmarshalTestsBad
{
var
top
TopicType
err
:=
top
.
UnmarshalJSON
(
tst
.
data
)
err
:=
json
.
Unmarshal
(
tst
.
data
,
&
top
)
if
err
==
nil
{
t
.
Fatalf
(
"failed test %d. input: %v."
,
i
,
tst
.
data
)
}
...
...
@@ -121,11 +124,11 @@ func TestUnmarshalTestsUgly(t *testing.T) {
// in this test UnmarshalJSON() is NOT supposed to fail, but result should be wrong
for
i
,
tst
:=
range
unmarshalTestsUgly
{
var
top
TopicType
err
:=
top
.
UnmarshalJSON
(
tst
.
data
)
err
:=
json
.
Unmarshal
(
tst
.
data
,
&
top
)
if
err
!=
nil
{
t
.
Fatal
f
(
"failed test %d. input: %v."
,
i
,
tst
.
data
)
t
.
Error
f
(
"failed test %d. input: %v."
,
i
,
tst
.
data
)
}
else
if
top
==
tst
.
topic
{
t
.
Fatal
f
(
"failed test %d: have %v, want %v."
,
i
,
top
,
tst
.
topic
)
t
.
Error
f
(
"failed test %d: have %v, want %v."
,
i
,
top
,
tst
.
topic
)
}
}
}
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