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
1f381414
Commit
1f381414
authored
Mar 26, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WhisperMessageArgs
parent
9ca87afd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
5 deletions
+104
-5
args.go
rpc/args.go
+13
-4
args_test.go
rpc/args_test.go
+91
-1
No files found.
rpc/args.go
View file @
1f381414
...
@@ -590,8 +590,8 @@ func (args *WhisperMessageArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -590,8 +590,8 @@ func (args *WhisperMessageArgs) UnmarshalJSON(b []byte) (err error) {
To
string
To
string
From
string
From
string
Topics
[]
string
Topics
[]
string
Priority
string
Priority
interface
{}
Ttl
string
Ttl
interface
{}
}
}
if
err
=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
if
err
=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
...
@@ -605,8 +605,17 @@ func (args *WhisperMessageArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -605,8 +605,17 @@ func (args *WhisperMessageArgs) UnmarshalJSON(b []byte) (err error) {
args
.
To
=
obj
[
0
]
.
To
args
.
To
=
obj
[
0
]
.
To
args
.
From
=
obj
[
0
]
.
From
args
.
From
=
obj
[
0
]
.
From
args
.
Topics
=
obj
[
0
]
.
Topics
args
.
Topics
=
obj
[
0
]
.
Topics
args
.
Priority
=
uint32
(
common
.
Big
(
obj
[
0
]
.
Priority
)
.
Int64
())
args
.
Ttl
=
uint32
(
common
.
Big
(
obj
[
0
]
.
Ttl
)
.
Int64
())
var
num
int64
if
err
:=
numString
(
obj
[
0
]
.
Priority
,
&
num
);
err
!=
nil
{
return
err
}
args
.
Priority
=
uint32
(
num
)
if
err
:=
numString
(
obj
[
0
]
.
Ttl
,
&
num
);
err
!=
nil
{
return
err
}
args
.
Ttl
=
uint32
(
num
)
return
nil
return
nil
}
}
...
...
rpc/args_test.go
View file @
1f381414
...
@@ -1009,7 +1009,7 @@ func TestWhisperMessageArgs(t *testing.T) {
...
@@ -1009,7 +1009,7 @@ func TestWhisperMessageArgs(t *testing.T) {
expected
.
Payload
=
"0x68656c6c6f20776f726c64"
expected
.
Payload
=
"0x68656c6c6f20776f726c64"
expected
.
Priority
=
100
expected
.
Priority
=
100
expected
.
Ttl
=
100
expected
.
Ttl
=
100
expected
.
Topics
=
[]
string
{
"0x68656c6c6f20776f726c64"
}
//
expected.Topics = []string{"0x68656c6c6f20776f726c64"}
args
:=
new
(
WhisperMessageArgs
)
args
:=
new
(
WhisperMessageArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
...
@@ -1041,6 +1041,96 @@ func TestWhisperMessageArgs(t *testing.T) {
...
@@ -1041,6 +1041,96 @@ func TestWhisperMessageArgs(t *testing.T) {
// }
// }
}
}
func
TestWhisperMessageArgsInt
(
t
*
testing
.
T
)
{
input
:=
`[{"from":"0xc931d93e97ab07fe42d923478ba2465f2",
"topics": ["0x68656c6c6f20776f726c64"],
"payload":"0x68656c6c6f20776f726c64",
"ttl": 12,
"priority": 16}]`
expected
:=
new
(
WhisperMessageArgs
)
expected
.
From
=
"0xc931d93e97ab07fe42d923478ba2465f2"
expected
.
To
=
""
expected
.
Payload
=
"0x68656c6c6f20776f726c64"
expected
.
Priority
=
16
expected
.
Ttl
=
12
// expected.Topics = []string{"0x68656c6c6f20776f726c64"}
args
:=
new
(
WhisperMessageArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
expected
.
From
!=
args
.
From
{
t
.
Errorf
(
"From shoud be %#v but is %#v"
,
expected
.
From
,
args
.
From
)
}
if
expected
.
To
!=
args
.
To
{
t
.
Errorf
(
"To shoud be %#v but is %#v"
,
expected
.
To
,
args
.
To
)
}
if
expected
.
Payload
!=
args
.
Payload
{
t
.
Errorf
(
"Value shoud be %#v but is %#v"
,
expected
.
Payload
,
args
.
Payload
)
}
if
expected
.
Ttl
!=
args
.
Ttl
{
t
.
Errorf
(
"Ttl shoud be %v but is %v"
,
expected
.
Ttl
,
args
.
Ttl
)
}
if
expected
.
Priority
!=
args
.
Priority
{
t
.
Errorf
(
"Priority shoud be %v but is %v"
,
expected
.
Priority
,
args
.
Priority
)
}
// if expected.Topics != args.Topics {
// t.Errorf("Topic shoud be %#v but is %#v", expected.Topic, args.Topic)
// }
}
func
TestWhisperMessageArgsInvalid
(
t
*
testing
.
T
)
{
input
:=
`{}`
args
:=
new
(
WhisperMessageArgs
)
str
:=
ExpectDecodeParamError
(
json
.
Unmarshal
([]
byte
(
input
),
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestWhisperMessageArgsEmpty
(
t
*
testing
.
T
)
{
input
:=
`[]`
args
:=
new
(
WhisperMessageArgs
)
str
:=
ExpectInsufficientParamsError
(
json
.
Unmarshal
([]
byte
(
input
),
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestWhisperMessageArgsTtlBool
(
t
*
testing
.
T
)
{
input
:=
`[{"from":"0xc931d93e97ab07fe42d923478ba2465f2",
"topics": ["0x68656c6c6f20776f726c64"],
"payload":"0x68656c6c6f20776f726c64",
"ttl": true,
"priority": "0x64"}]`
args
:=
new
(
WhisperMessageArgs
)
str
:=
ExpectInvalidTypeError
(
json
.
Unmarshal
([]
byte
(
input
),
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestWhisperMessageArgsPriorityBool
(
t
*
testing
.
T
)
{
input
:=
`[{"from":"0xc931d93e97ab07fe42d923478ba2465f2",
"topics": ["0x68656c6c6f20776f726c64"],
"payload":"0x68656c6c6f20776f726c64",
"ttl": "0x12",
"priority": true}]`
args
:=
new
(
WhisperMessageArgs
)
str
:=
ExpectInvalidTypeError
(
json
.
Unmarshal
([]
byte
(
input
),
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestFilterIdArgs
(
t
*
testing
.
T
)
{
func
TestFilterIdArgs
(
t
*
testing
.
T
)
{
input
:=
`["0x7"]`
input
:=
`["0x7"]`
expected
:=
new
(
FilterIdArgs
)
expected
:=
new
(
FilterIdArgs
)
...
...
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