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
4f014014
Commit
4f014014
authored
Mar 15, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add basic config validation tests :test_tube:
parent
06dda0c6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
9 deletions
+49
-9
channel_builder.go
op-batcher/batcher/channel_builder.go
+9
-9
channel_builder_test.go
op-batcher/batcher/channel_builder_test.go
+40
-0
No files found.
op-batcher/batcher/channel_builder.go
View file @
4f014014
...
...
@@ -12,13 +12,13 @@ import (
)
var
(
Err
MaxFrameSizeZero
=
errors
.
New
(
"max frame size cannot be zero"
)
Err
ChannelTimeoutTooSmall
=
errors
.
New
(
"channel timeout is less than the safety margin"
)
ErrInputTargetReached
=
errors
.
New
(
"target amount of input data reached"
)
ErrMaxFrameIndex
=
errors
.
New
(
"max frame index reached (uint16)"
)
ErrMaxDurationReached
=
errors
.
New
(
"max channel duration reached"
)
ErrChannelTimeoutClose
=
errors
.
New
(
"close to channel timeout"
)
ErrSeqWindowClose
=
errors
.
New
(
"close to sequencer window timeout"
)
Err
InvalidMaxFrameSize
=
errors
.
New
(
"max frame size cannot be zero"
)
Err
InvalidChannelTimeout
=
errors
.
New
(
"channel timeout is less than the safety margin"
)
ErrInputTargetReached
=
errors
.
New
(
"target amount of input data reached"
)
ErrMaxFrameIndex
=
errors
.
New
(
"max frame index reached (uint16)"
)
ErrMaxDurationReached
=
errors
.
New
(
"max channel duration reached"
)
ErrChannelTimeoutClose
=
errors
.
New
(
"close to channel timeout"
)
ErrSeqWindowClose
=
errors
.
New
(
"close to sequencer window timeout"
)
)
type
ChannelFullError
struct
{
...
...
@@ -75,14 +75,14 @@ func (cc *ChannelConfig) Check() error {
// The [ChannelTimeout] must be larger than the [SubSafetyMargin].
// Otherwise, new blocks would always be considered timed out.
if
cc
.
ChannelTimeout
<
cc
.
SubSafetyMargin
{
return
Err
ChannelTimeoutTooSmall
return
Err
InvalidChannelTimeout
}
// If the [MaxFrameSize] is set to 0, the channel builder
// will infinitely loop when trying to create frames in the
// [channelBuilder.OutputFrames] function.
if
cc
.
MaxFrameSize
==
0
{
return
Err
MaxFrameSizeZero
return
Err
InvalidMaxFrameSize
}
return
nil
...
...
op-batcher/batcher/channel_builder_test.go
0 → 100644
View file @
4f014014
package
batcher
import
(
"testing"
"github.com/stretchr/testify/require"
)
// defaultChannelConfig returns a valid, default [ChannelConfig] struct.
func
defaultChannelConfig
()
ChannelConfig
{
return
ChannelConfig
{
SeqWindowSize
:
15
,
ChannelTimeout
:
40
,
MaxChannelDuration
:
1
,
SubSafetyMargin
:
4
,
MaxFrameSize
:
120000
,
TargetFrameSize
:
100000
,
TargetNumFrames
:
1
,
ApproxComprRatio
:
0.4
,
}
}
// TestConfigValidation tests the validation of the [ChannelConfig] struct.
func
TestConfigValidation
(
t
*
testing
.
T
)
{
// Construct a valid config.
validChannelConfig
:=
defaultChannelConfig
()
require
.
NoError
(
t
,
validChannelConfig
.
Check
())
// Set the config to have a zero max frame size.
validChannelConfig
.
MaxFrameSize
=
0
require
.
ErrorIs
(
t
,
validChannelConfig
.
Check
(),
ErrInvalidMaxFrameSize
)
// Reset the config and test the Timeout error.
// NOTE: We should be fuzzing these values with the constraint that
// SubSafetyMargin > ChannelTimeout to ensure validation.
validChannelConfig
=
defaultChannelConfig
()
validChannelConfig
.
ChannelTimeout
=
0
validChannelConfig
.
SubSafetyMargin
=
1
require
.
ErrorIs
(
t
,
validChannelConfig
.
Check
(),
ErrInvalidChannelTimeout
)
}
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