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
72f24f11
Commit
72f24f11
authored
Feb 14, 2023
by
Sebastian Stammler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Add tests for ParseFrames
parent
413edbaf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
1 deletion
+61
-1
frame.go
op-node/rollup/derive/frame.go
+1
-1
frame_test.go
op-node/rollup/derive/frame_test.go
+60
-0
No files found.
op-node/rollup/derive/frame.go
View file @
72f24f11
...
...
@@ -117,7 +117,7 @@ func eofAsUnexpectedMissing(err error) error {
return
err
}
// Frames
on
stored in L1 transactions with the following format:
// Frames
are
stored in L1 transactions with the following format:
// data = DerivationVersion0 ++ Frame(s)
// Where there is one or more frames concatenated together.
...
...
op-node/rollup/derive/frame_test.go
View file @
72f24f11
...
...
@@ -152,6 +152,66 @@ func TestFrameUnmarshalInvalidIsLast(t *testing.T) {
require
.
ErrorContains
(
t
,
err
,
"invalid byte"
)
}
func
TestParseFramesNoData
(
t
*
testing
.
T
)
{
frames
,
err
:=
ParseFrames
(
nil
)
require
.
Empty
(
t
,
frames
)
require
.
Error
(
t
,
err
)
}
func
TestParseFramesInvalidVer
(
t
*
testing
.
T
)
{
frames
,
err
:=
ParseFrames
([]
byte
{
42
})
require
.
Empty
(
t
,
frames
)
require
.
Error
(
t
,
err
)
}
func
TestParseFrames
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
numFrames
:=
rng
.
Intn
(
16
)
+
1
frames
:=
make
([]
Frame
,
0
,
numFrames
)
for
i
:=
0
;
i
<
numFrames
;
i
++
{
frames
=
append
(
frames
,
*
randomFrame
(
rng
))
}
data
,
err
:=
txMarshalFrames
(
frames
)
require
.
NoError
(
t
,
err
)
frames0
,
err
:=
ParseFrames
(
data
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
frames
,
frames0
)
}
func
TestParseFramesTruncated
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
numFrames
:=
rng
.
Intn
(
16
)
+
1
frames
:=
make
([]
Frame
,
0
,
numFrames
)
for
i
:=
0
;
i
<
numFrames
;
i
++
{
frames
=
append
(
frames
,
*
randomFrame
(
rng
))
}
data
,
err
:=
txMarshalFrames
(
frames
)
require
.
NoError
(
t
,
err
)
data
=
data
[
:
len
(
data
)
-
2
]
// truncate last 2 bytes
frames0
,
err
:=
ParseFrames
(
data
)
require
.
Error
(
t
,
err
)
require
.
ErrorIs
(
t
,
err
,
io
.
ErrUnexpectedEOF
)
require
.
Empty
(
t
,
frames0
)
}
// txMarshalFrames creates the tx payload for the given frames, i.e., it first
// writes the version byte to a buffer and then appends all binary-marshaled
// frames.
func
txMarshalFrames
(
frames
[]
Frame
)
([]
byte
,
error
)
{
var
data
bytes
.
Buffer
if
err
:=
data
.
WriteByte
(
DerivationVersion0
);
err
!=
nil
{
return
nil
,
err
}
for
_
,
frame
:=
range
frames
{
if
err
:=
frame
.
MarshalBinary
(
&
data
);
err
!=
nil
{
return
nil
,
err
}
}
return
data
.
Bytes
(),
nil
}
func
randomFrame
(
rng
*
rand
.
Rand
,
opts
...
frameOpt
)
*
Frame
{
var
id
ChannelID
_
,
err
:=
rng
.
Read
(
id
[
:
])
...
...
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