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
4a81e5af
Unverified
Commit
4a81e5af
authored
Nov 02, 2022
by
Roberto Bayardo
Committed by
GitHub
Nov 02, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rlp: add more tests for nil pointer / optional field encoding (#26077)
parent
621b423a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
decode_test.go
rlp/decode_test.go
+34
-0
encode_test.go
rlp/encode_test.go
+4
-0
No files found.
rlp/decode_test.go
View file @
4a81e5af
...
...
@@ -439,6 +439,16 @@ type optionalPtrField struct {
B
*
[
3
]
byte
`rlp:"optional"`
}
type
nonOptionalPtrField
struct
{
A
uint
B
*
[
3
]
byte
}
type
multipleOptionalFields
struct
{
A
*
[
3
]
byte
`rlp:"optional"`
B
*
[
3
]
byte
`rlp:"optional"`
}
type
optionalPtrFieldNil
struct
{
A
uint
B
*
[
3
]
byte
`rlp:"optional,nil"`
...
...
@@ -744,6 +754,30 @@ var decodeTests = []decodeTest{
ptr
:
new
(
optionalPtrField
),
value
:
optionalPtrField
{
A
:
1
,
B
:
&
[
3
]
byte
{
1
,
2
,
3
}},
},
{
// all optional fields nil
input
:
"C0"
,
ptr
:
new
(
multipleOptionalFields
),
value
:
multipleOptionalFields
{
A
:
nil
,
B
:
nil
},
},
{
// all optional fields set
input
:
"C88301020383010203"
,
ptr
:
new
(
multipleOptionalFields
),
value
:
multipleOptionalFields
{
A
:
&
[
3
]
byte
{
1
,
2
,
3
},
B
:
&
[
3
]
byte
{
1
,
2
,
3
}},
},
{
// nil optional field appears before a non-nil one
input
:
"C58083010203"
,
ptr
:
new
(
multipleOptionalFields
),
error
:
"rlp: input string too short for [3]uint8, decoding into (rlp.multipleOptionalFields).A"
,
},
{
// decode a nil ptr into a ptr that is not nil or not optional
input
:
"C20180"
,
ptr
:
new
(
nonOptionalPtrField
),
error
:
"rlp: input string too short for [3]uint8, decoding into (rlp.nonOptionalPtrField).B"
,
},
{
input
:
"C101"
,
ptr
:
new
(
optionalPtrFieldNil
),
...
...
rlp/encode_test.go
View file @
4a81e5af
...
...
@@ -290,6 +290,10 @@ var encTests = []encTest{
{
val
:
&
optionalBigIntField
{
A
:
1
},
output
:
"C101"
},
{
val
:
&
optionalPtrField
{
A
:
1
},
output
:
"C101"
},
{
val
:
&
optionalPtrFieldNil
{
A
:
1
},
output
:
"C101"
},
{
val
:
&
multipleOptionalFields
{
A
:
nil
,
B
:
nil
},
output
:
"C0"
},
{
val
:
&
multipleOptionalFields
{
A
:
&
[
3
]
byte
{
1
,
2
,
3
},
B
:
&
[
3
]
byte
{
1
,
2
,
3
}},
output
:
"C88301020383010203"
},
{
val
:
&
multipleOptionalFields
{
A
:
nil
,
B
:
&
[
3
]
byte
{
1
,
2
,
3
}},
output
:
"C58083010203"
},
// encodes without error but decode will fail
{
val
:
&
nonOptionalPtrField
{
A
:
1
},
output
:
"C20180"
},
// encodes without error but decode will fail
// nil
{
val
:
(
*
uint
)(
nil
),
output
:
"80"
},
...
...
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