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
e80cfdb2
Commit
e80cfdb2
authored
Mar 13, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start channel building tests
parent
35d4a37c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
2 deletions
+83
-2
channel_builder.go
op-batcher/batcher/channel_builder.go
+3
-1
channel_builder_test.go
op-batcher/batcher/channel_builder_test.go
+79
-0
channel_manager.go
op-batcher/batcher/channel_manager.go
+1
-1
No files found.
op-batcher/batcher/channel_builder.go
View file @
e80cfdb2
...
@@ -79,7 +79,9 @@ type channelBuilder struct {
...
@@ -79,7 +79,9 @@ type channelBuilder struct {
frames
[]
taggedData
frames
[]
taggedData
}
}
func
newChannelBuilder
(
cfg
ChannelConfig
)
(
*
channelBuilder
,
error
)
{
// NewChannelBuilder creates a new channel builder or returns an error if the
// channel out could not be created.
func
NewChannelBuilder
(
cfg
ChannelConfig
)
(
*
channelBuilder
,
error
)
{
co
,
err
:=
derive
.
NewChannelOut
()
co
,
err
:=
derive
.
NewChannelOut
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
op-batcher/batcher/channel_builder_test.go
0 → 100644
View file @
e80cfdb2
package
batcher
import
(
"bytes"
"testing"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/stretchr/testify/require"
)
var
defaultTestConfig
=
ChannelConfig
{
SeqWindowSize
:
15
,
ChannelTimeout
:
40
,
MaxChannelDuration
:
1
,
SubSafetyMargin
:
4
,
MaxFrameSize
:
120000
,
TargetFrameSize
:
100000
,
TargetNumFrames
:
1
,
ApproxComprRatio
:
0.4
,
}
// TestBuilderNextFrame tests calling NextFrame on a ChannelBuilder with only one frame
func
TestBuilderNextFrame
(
t
*
testing
.
T
)
{
cb
,
err
:=
NewChannelBuilder
(
defaultTestConfig
)
require
.
NoError
(
t
,
err
)
// Mock the internals of `channelBuilder.outputFrame`
// to construct a single frame
co
:=
cb
.
co
var
buf
bytes
.
Buffer
fn
,
err
:=
co
.
OutputFrame
(
&
buf
,
defaultTestConfig
.
MaxFrameSize
)
require
.
NoError
(
t
,
err
)
// Push one frame into to the channel builder
expectedTx
:=
txID
{
chID
:
co
.
ID
(),
frameNumber
:
fn
}
expectedBytes
:=
buf
.
Bytes
()
cb
.
PushFrame
(
expectedTx
,
expectedBytes
)
// There should only be 1 frame in the channel builder
require
.
Equal
(
t
,
1
,
cb
.
NumFrames
())
// We should be able to increment to the next frame
constructedTx
,
constructedBytes
:=
cb
.
NextFrame
()
require
.
Equal
(
t
,
expectedTx
,
constructedTx
)
require
.
Equal
(
t
,
expectedBytes
,
constructedBytes
)
require
.
Equal
(
t
,
0
,
cb
.
NumFrames
())
// The next call should panic since the length of frames is 0
defer
func
()
{
_
=
recover
()
}()
cb
.
NextFrame
()
// If we get here, `NextFrame` did not panic as expected
t
.
Errorf
(
"did not panic"
)
}
// TestBuilderInvalidFrameId tests that a panic is thrown when a frame is pushed with an invalid frame id
func
TestBuilderWrongFramePanic
(
t
*
testing
.
T
)
{
cb
,
err
:=
NewChannelBuilder
(
defaultTestConfig
)
require
.
NoError
(
t
,
err
)
// Mock the internals of `channelBuilder.outputFrame`
// to construct a single frame
co
,
err
:=
derive
.
NewChannelOut
()
require
.
NoError
(
t
,
err
)
var
buf
bytes
.
Buffer
fn
,
err
:=
co
.
OutputFrame
(
&
buf
,
defaultTestConfig
.
MaxFrameSize
)
require
.
NoError
(
t
,
err
)
// The frame push should panic since we constructed a new channel out
// so the channel out id won't match
defer
func
()
{
_
=
recover
()
}()
// Push one frame into to the channel builder
tx
:=
txID
{
chID
:
co
.
ID
(),
frameNumber
:
fn
}
cb
.
PushFrame
(
tx
,
buf
.
Bytes
())
// If we get here, `PushFrame` did not panic as expected
t
.
Errorf
(
"did not panic"
)
}
op-batcher/batcher/channel_manager.go
View file @
e80cfdb2
...
@@ -229,7 +229,7 @@ func (s *channelManager) ensurePendingChannel(l1Head eth.BlockID) error {
...
@@ -229,7 +229,7 @@ func (s *channelManager) ensurePendingChannel(l1Head eth.BlockID) error {
return
nil
return
nil
}
}
cb
,
err
:=
n
ewChannelBuilder
(
s
.
cfg
)
cb
,
err
:=
N
ewChannelBuilder
(
s
.
cfg
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"creating new channel: %w"
,
err
)
return
fmt
.
Errorf
(
"creating new channel: %w"
,
err
)
}
}
...
...
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