Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
exchain
nebula
Commits
413edbaf
Commit
413edbaf
authored
Feb 14, 2023
by
Sebastian Stammler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Add more test cases for Frame.UnmarshalBinary
parent
9aa6fd4f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
6 deletions
+42
-6
frame_test.go
op-node/rollup/derive/frame_test.go
+42
-6
No files found.
op-node/rollup/derive/frame_test.go
View file @
413edbaf
...
...
@@ -47,46 +47,82 @@ func TestFrameMarshaling(t *testing.T) {
}
}
func
TestFrameUnmarshalNoData
(
t
*
testing
.
T
)
{
frame0
:=
new
(
Frame
)
err
:=
frame0
.
UnmarshalBinary
(
bytes
.
NewReader
([]
byte
{}))
require
.
Error
(
t
,
err
)
require
.
ErrorIs
(
t
,
err
,
io
.
EOF
)
}
func
TestFrameUnmarshalTruncated
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
// 16 (channel_id) ++ 2 (frame_number) ++ 4 (frame_data_length) ++
// frame_data_length (frame_data) ++ 1 (is_last)
for
_
,
tr
:=
range
[]
struct
{
desc
string
truncate
func
([]
byte
)
[]
byte
genData
bool
// whether data should be generated
}{
{
desc
:
"truncate-channel_id-half"
,
truncate
:
func
(
data
[]
byte
)
[]
byte
{
return
data
[
:
8
]
},
},
{
desc
:
"truncate-frame_number-full"
,
truncate
:
func
(
data
[]
byte
)
[]
byte
{
return
data
[
:
16
]
},
},
{
desc
:
"truncate-frame_number-half"
,
truncate
:
func
(
data
[]
byte
)
[]
byte
{
return
data
[
:
17
]
},
},
{
desc
:
"truncate-frame_data_length-full"
,
truncate
:
func
(
data
[]
byte
)
[]
byte
{
return
data
[
:
18
]
// truncate full frame_data_length
return
data
[
:
18
]
},
},
{
desc
:
"truncate-frame_data_length-half"
,
truncate
:
func
(
data
[]
byte
)
[]
byte
{
return
data
[
:
20
]
// truncate half-way frame_data_length
return
data
[
:
20
]
},
genData
:
true
,
// for non-zero frame_data_length
},
{
desc
:
"truncate-data-full"
,
desc
:
"truncate-
frame_
data-full"
,
truncate
:
func
(
data
[]
byte
)
[]
byte
{
return
data
[
:
22
]
// truncate after frame_data_length
return
data
[
:
22
]
},
genData
:
true
,
// for non-zero frame_data_length
},
{
desc
:
"truncate-data-last-byte"
,
desc
:
"truncate-
frame_
data-last-byte"
,
truncate
:
func
(
data
[]
byte
)
[]
byte
{
return
data
[
:
len
(
data
)
-
2
]
},
genData
:
true
,
},
{
desc
:
"truncate-is_last"
,
truncate
:
func
(
data
[]
byte
)
[]
byte
{
return
data
[
:
len
(
data
)
-
1
]
},
genData
:
true
,
},
}
{
t
.
Run
(
tr
.
desc
,
func
(
t
*
testing
.
T
)
{
frame
:=
randomFrame
(
rng
)
var
opts
[]
frameOpt
if
!
tr
.
genData
{
opts
=
[]
frameOpt
{
frameWithDataLen
(
0
)}
}
frame
:=
randomFrame
(
rng
,
opts
...
)
var
data
bytes
.
Buffer
require
.
NoError
(
t
,
frame
.
MarshalBinary
(
&
data
))
...
...
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