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
404cdd79
Commit
404cdd79
authored
Mar 14, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revert channel builder test suite back to bare metal testing
parent
80377f72
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
136 additions
and
160 deletions
+136
-160
channel_builder_test.go
op-batcher/batcher/channel_builder_test.go
+136
-160
No files found.
op-batcher/batcher/channel_builder_test.go
View file @
404cdd79
...
@@ -7,22 +7,15 @@ import (
...
@@ -7,22 +7,15 @@ import (
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie"
"github.com/stretchr/testify/
suit
e"
"github.com/stretchr/testify/
requir
e"
)
)
// ChannelBuilderTestSuite encapsulates testing on the ChannelBuilder.
var
defaultTestChannelConfig
=
ChannelConfig
{
type
ChannelBuilderTestSuite
struct
{
suite
.
Suite
channelConfig
ChannelConfig
}
// SetupTest sets up the test suite.
func
(
testSuite
*
ChannelBuilderTestSuite
)
SetupTest
()
{
testSuite
.
channelConfig
=
ChannelConfig
{
SeqWindowSize
:
15
,
SeqWindowSize
:
15
,
ChannelTimeout
:
40
,
ChannelTimeout
:
40
,
MaxChannelDuration
:
1
,
MaxChannelDuration
:
1
,
...
@@ -31,25 +24,42 @@ func (testSuite *ChannelBuilderTestSuite) SetupTest() {
...
@@ -31,25 +24,42 @@ func (testSuite *ChannelBuilderTestSuite) SetupTest() {
TargetFrameSize
:
100000
,
TargetFrameSize
:
100000
,
TargetNumFrames
:
1
,
TargetNumFrames
:
1
,
ApproxComprRatio
:
0.4
,
ApproxComprRatio
:
0.4
,
}
}
}
// TestChannelBuilder runs the ChannelBuilderTestSuite.
// addNonsenseBlock is a helper function that adds a nonsense block
func
TestChannelBuilder
(
t
*
testing
.
T
)
{
// to the channel builder using the [channelBuilder.AddBlock] method.
suite
.
Run
(
t
,
new
(
ChannelBuilderTestSuite
))
func
addNonsenseBlock
(
cb
*
channelBuilder
)
error
{
lBlock
:=
types
.
NewBlock
(
&
types
.
Header
{
BaseFee
:
big
.
NewInt
(
10
),
Difficulty
:
common
.
Big0
,
Number
:
big
.
NewInt
(
100
),
},
nil
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
l1InfoTx
,
err
:=
derive
.
L1InfoDeposit
(
0
,
lBlock
,
eth
.
SystemConfig
{},
false
)
if
err
!=
nil
{
return
err
}
txs
:=
[]
*
types
.
Transaction
{
types
.
NewTx
(
l1InfoTx
)}
a
:=
types
.
NewBlock
(
&
types
.
Header
{
Number
:
big
.
NewInt
(
0
),
},
txs
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
err
=
cb
.
AddBlock
(
a
)
return
err
}
}
// TestBuilderNextFrame tests calling NextFrame on a ChannelBuilder with only one frame
// TestBuilderNextFrame tests calling NextFrame on a ChannelBuilder with only one frame
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestBuilderNextFrame
()
{
func
TestBuilderNextFrame
(
t
*
testing
.
T
)
{
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channelConfig
)
channelConfig
:=
defaultTestChannelConfig
testSuite
.
NoError
(
err
)
// Create a new channel builder
cb
,
err
:=
newChannelBuilder
(
channelConfig
)
require
.
NoError
(
t
,
err
)
// Mock the internals of `channelBuilder.outputFrame`
// Mock the internals of `channelBuilder.outputFrame`
// to construct a single frame
// to construct a single frame
co
:=
cb
.
co
co
:=
cb
.
co
var
buf
bytes
.
Buffer
var
buf
bytes
.
Buffer
fn
,
err
:=
co
.
OutputFrame
(
&
buf
,
testSuite
.
channelConfig
.
MaxFrameSize
)
fn
,
err
:=
co
.
OutputFrame
(
&
buf
,
channelConfig
.
MaxFrameSize
)
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// Push one frame into to the channel builder
// Push one frame into to the channel builder
expectedTx
:=
txID
{
chID
:
co
.
ID
(),
frameNumber
:
fn
}
expectedTx
:=
txID
{
chID
:
co
.
ID
(),
frameNumber
:
fn
}
...
@@ -57,237 +67,226 @@ func (testSuite *ChannelBuilderTestSuite) TestBuilderNextFrame() {
...
@@ -57,237 +67,226 @@ func (testSuite *ChannelBuilderTestSuite) TestBuilderNextFrame() {
cb
.
PushFrame
(
expectedTx
,
expectedBytes
)
cb
.
PushFrame
(
expectedTx
,
expectedBytes
)
// There should only be 1 frame in the channel builder
// There should only be 1 frame in the channel builder
testSuite
.
Equal
(
1
,
cb
.
NumFrames
())
require
.
Equal
(
t
,
1
,
cb
.
NumFrames
())
// We should be able to increment to the next frame
// We should be able to increment to the next frame
constructedTx
,
constructedBytes
:=
cb
.
NextFrame
()
constructedTx
,
constructedBytes
:=
cb
.
NextFrame
()
testSuite
.
Equal
(
expectedTx
,
constructedTx
)
require
.
Equal
(
t
,
expectedTx
,
constructedTx
)
testSuite
.
Equal
(
expectedBytes
,
constructedBytes
)
require
.
Equal
(
t
,
expectedBytes
,
constructedBytes
)
testSuite
.
Equal
(
0
,
cb
.
NumFrames
())
require
.
Equal
(
t
,
0
,
cb
.
NumFrames
())
// The next call should panic since the length of frames is 0
// The next call should panic since the length of frames is 0
defer
func
()
{
_
=
recover
()
}()
require
.
PanicsWithValue
(
t
,
"no next frame"
,
func
()
{
cb
.
NextFrame
()
})
cb
.
NextFrame
()
// If we get here, `NextFrame` did not panic as expected
testSuite
.
T
()
.
Errorf
(
"did not panic"
)
}
}
// TestBuilderInvalidFrameId tests that a panic is thrown when a frame is pushed with an invalid frame id
// TestBuilderInvalidFrameId tests that a panic is thrown when a frame is pushed with an invalid frame id
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestBuilderWrongFramePanic
()
{
func
TestBuilderWrongFramePanic
(
t
*
testing
.
T
)
{
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channelConfig
)
channelConfig
:=
defaultTestChannelConfig
testSuite
.
NoError
(
err
)
// Construct a channel builder
cb
,
err
:=
newChannelBuilder
(
channelConfig
)
require
.
NoError
(
t
,
err
)
// Mock the internals of `channelBuilder.outputFrame`
// Mock the internals of `channelBuilder.outputFrame`
// to construct a single frame
// to construct a single frame
co
,
err
:=
derive
.
NewChannelOut
()
co
,
err
:=
derive
.
NewChannelOut
()
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
var
buf
bytes
.
Buffer
var
buf
bytes
.
Buffer
fn
,
err
:=
co
.
OutputFrame
(
&
buf
,
testSuite
.
channelConfig
.
MaxFrameSize
)
fn
,
err
:=
co
.
OutputFrame
(
&
buf
,
channelConfig
.
MaxFrameSize
)
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// The frame push should panic since we constructed a new channel out
// The frame push should panic since we constructed a new channel out
// so the channel out id won't match
// so the channel out id won't match
defer
func
()
{
_
=
recover
()
}()
require
.
PanicsWithValue
(
t
,
"wrong channel"
,
func
()
{
// Push one frame into to the channel builder
tx
:=
txID
{
chID
:
co
.
ID
(),
frameNumber
:
fn
}
tx
:=
txID
{
chID
:
co
.
ID
(),
frameNumber
:
fn
}
cb
.
PushFrame
(
tx
,
buf
.
Bytes
())
cb
.
PushFrame
(
tx
,
buf
.
Bytes
())
})
// If we get here, `PushFrame` did not panic as expected
testSuite
.
T
()
.
Errorf
(
"did not panic"
)
}
func
addNonsenseBlock
(
cb
*
channelBuilder
)
error
{
lBlock
:=
types
.
NewBlock
(
&
types
.
Header
{
BaseFee
:
big
.
NewInt
(
10
),
Difficulty
:
common
.
Big0
,
Number
:
big
.
NewInt
(
100
),
},
nil
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
l1InfoTx
,
err
:=
derive
.
L1InfoDeposit
(
0
,
lBlock
,
eth
.
SystemConfig
{},
false
)
if
err
!=
nil
{
return
err
}
txs
:=
[]
*
types
.
Transaction
{
types
.
NewTx
(
l1InfoTx
)}
a
:=
types
.
NewBlock
(
&
types
.
Header
{
Number
:
big
.
NewInt
(
0
),
},
txs
,
nil
,
nil
,
trie
.
NewStackTrie
(
nil
))
err
=
cb
.
AddBlock
(
a
)
return
err
}
}
// TestOutputFrames tests the OutputFrames function
// TestOutputFrames tests the OutputFrames function
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestOutputFrames
()
{
func
TestOutputFrames
(
t
*
testing
.
T
)
{
channelConfig
:=
defaultTestChannelConfig
// Lower the max frame size so that we can test
// Lower the max frame size so that we can test
testSuite
.
channelConfig
.
MaxFrameSize
=
2
channelConfig
.
MaxFrameSize
=
2
// Construct the channel builder
// Construct the channel builder
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channelConfig
)
cb
,
err
:=
newChannelBuilder
(
channelConfig
)
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
testSuite
.
False
(
cb
.
IsFull
())
require
.
False
(
t
,
cb
.
IsFull
())
testSuite
.
Equal
(
0
,
cb
.
NumFrames
())
require
.
Equal
(
t
,
0
,
cb
.
NumFrames
())
// Calling OutputFrames without having called [AddBlock]
// Calling OutputFrames without having called [AddBlock]
// should return
`nil`.
// should return
no error
testSuite
.
Nil
(
cb
.
OutputFrames
())
require
.
NoError
(
t
,
cb
.
OutputFrames
())
// There should be no ready bytes yet
// There should be no ready bytes yet
readyBytes
:=
cb
.
co
.
ReadyBytes
()
readyBytes
:=
cb
.
co
.
ReadyBytes
()
testSuite
.
Equal
(
0
,
readyBytes
)
require
.
Equal
(
t
,
0
,
readyBytes
)
// Let's add a block
// Let's add a block
err
=
addNonsenseBlock
(
cb
)
err
=
addNonsenseBlock
(
cb
)
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// Check how many ready bytes
// Check how many ready bytes
readyBytes
=
cb
.
co
.
ReadyBytes
()
readyBytes
=
cb
.
co
.
ReadyBytes
()
testSuite
.
Equal
(
2
,
readyBytes
)
require
.
Equal
(
t
,
2
,
readyBytes
)
testSuite
.
Equal
(
0
,
cb
.
NumFrames
())
require
.
Equal
(
t
,
0
,
cb
.
NumFrames
())
// The channel should not be full
// The channel should not be full
// but we want to output the frames for testing anyways
// but we want to output the frames for testing anyways
isFull
:=
cb
.
IsFull
()
isFull
:=
cb
.
IsFull
()
testSuite
.
False
(
isFull
)
require
.
False
(
t
,
isFull
)
// Since we manually set the max frame size to 2,
// Since we manually set the max frame size to 2,
// we should be able to compress the two frames now
// we should be able to compress the two frames now
err
=
cb
.
OutputFrames
()
err
=
cb
.
OutputFrames
()
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// There should be one frame in the channel builder now
// There should be one frame in the channel builder now
testSuite
.
Equal
(
1
,
cb
.
NumFrames
())
require
.
Equal
(
t
,
1
,
cb
.
NumFrames
())
// There should no longer be any ready bytes
// There should no longer be any ready bytes
readyBytes
=
cb
.
co
.
ReadyBytes
()
readyBytes
=
cb
.
co
.
ReadyBytes
()
testSuite
.
Equal
(
0
,
readyBytes
)
require
.
Equal
(
t
,
0
,
readyBytes
)
}
}
// TestBuilderAddBlock tests the AddBlock function
// TestBuilderAddBlock tests the AddBlock function
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestBuilderAddBlock
()
{
func
TestBuilderAddBlock
(
t
*
testing
.
T
)
{
channelConfig
:=
defaultTestChannelConfig
// Lower the max frame size so that we can batch
// Lower the max frame size so that we can batch
testSuite
.
channelConfig
.
MaxFrameSize
=
2
channelConfig
.
MaxFrameSize
=
2
// Configure the Input Threshold params so we observe a full channel
// Configure the Input Threshold params so we observe a full channel
// In reality, we only need the input bytes (74) below to be greater than
// In reality, we only need the input bytes (74) below to be greater than
// or equal to the input threshold (3 * 2) / 1 = 6
// or equal to the input threshold (3 * 2) / 1 = 6
testSuite
.
channelConfig
.
TargetFrameSize
=
3
channelConfig
.
TargetFrameSize
=
3
testSuite
.
channelConfig
.
TargetNumFrames
=
2
channelConfig
.
TargetNumFrames
=
2
testSuite
.
channelConfig
.
ApproxComprRatio
=
1
channelConfig
.
ApproxComprRatio
=
1
// Construct the channel builder
// Construct the channel builder
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channelConfig
)
cb
,
err
:=
newChannelBuilder
(
channelConfig
)
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// Add a nonsense block to the channel builder
// Add a nonsense block to the channel builder
err
=
addNonsenseBlock
(
cb
)
err
=
addNonsenseBlock
(
cb
)
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// Check the fields reset in the AddBlock function
// Check the fields reset in the AddBlock function
testSuite
.
Equal
(
74
,
cb
.
co
.
InputBytes
())
require
.
Equal
(
t
,
74
,
cb
.
co
.
InputBytes
())
testSuite
.
Equal
(
1
,
len
(
cb
.
blocks
))
require
.
Equal
(
t
,
1
,
len
(
cb
.
blocks
))
testSuite
.
Equal
(
0
,
len
(
cb
.
frames
))
require
.
Equal
(
t
,
0
,
len
(
cb
.
frames
))
testSuite
.
True
(
cb
.
IsFull
())
require
.
True
(
t
,
cb
.
IsFull
())
// Since the channel output is full, the next call to AddBlock
// Since the channel output is full, the next call to AddBlock
// should return the channel out full error
// should return the channel out full error
err
=
addNonsenseBlock
(
cb
)
err
=
addNonsenseBlock
(
cb
)
testSuite
.
ErrorIs
(
err
,
ErrInputTargetReached
)
require
.
ErrorIs
(
t
,
err
,
ErrInputTargetReached
)
}
}
// TestBuilderReset tests the Reset function
// TestBuilderReset tests the Reset function
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestBuilderReset
()
{
func
TestBuilderReset
(
t
*
testing
.
T
)
{
channelConfig
:=
defaultTestChannelConfig
// Lower the max frame size so that we can batch
// Lower the max frame size so that we can batch
testSuite
.
channelConfig
.
MaxFrameSize
=
2
channelConfig
.
MaxFrameSize
=
2
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channelConfig
)
cb
,
err
:=
newChannelBuilder
(
channelConfig
)
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// Add a nonsense block to the channel builder
// Add a nonsense block to the channel builder
err
=
addNonsenseBlock
(
cb
)
err
=
addNonsenseBlock
(
cb
)
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// Check the fields reset in the Reset function
// Check the fields reset in the Reset function
testSuite
.
Equal
(
1
,
len
(
cb
.
blocks
))
require
.
Equal
(
t
,
1
,
len
(
cb
.
blocks
))
testSuite
.
Equal
(
0
,
len
(
cb
.
frames
))
require
.
Equal
(
t
,
0
,
len
(
cb
.
frames
))
// Timeout should be updated in the AddBlock internal call to `updateSwTimeout`
// Timeout should be updated in the AddBlock internal call to `updateSwTimeout`
timeout
:=
uint64
(
100
)
+
cb
.
cfg
.
SeqWindowSize
-
cb
.
cfg
.
SubSafetyMargin
timeout
:=
uint64
(
100
)
+
cb
.
cfg
.
SeqWindowSize
-
cb
.
cfg
.
SubSafetyMargin
testSuite
.
Equal
(
timeout
,
cb
.
timeout
)
require
.
Equal
(
t
,
timeout
,
cb
.
timeout
)
testSuite
.
Nil
(
cb
.
fullErr
)
require
.
NoError
(
t
,
cb
.
fullErr
)
// Output frames so we can set the channel builder frames
// Output frames so we can set the channel builder frames
err
=
cb
.
OutputFrames
()
err
=
cb
.
OutputFrames
()
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// Add another block to increment the block count
// Add another block to increment the block count
err
=
addNonsenseBlock
(
cb
)
err
=
addNonsenseBlock
(
cb
)
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// Check the fields reset in the Reset function
// Check the fields reset in the Reset function
testSuite
.
Equal
(
2
,
len
(
cb
.
blocks
))
require
.
Equal
(
t
,
2
,
len
(
cb
.
blocks
))
testSuite
.
Equal
(
1
,
len
(
cb
.
frames
))
require
.
Equal
(
t
,
1
,
len
(
cb
.
frames
))
testSuite
.
Equal
(
timeout
,
cb
.
timeout
)
require
.
Equal
(
t
,
timeout
,
cb
.
timeout
)
testSuite
.
Nil
(
cb
.
fullErr
)
require
.
NoError
(
t
,
cb
.
fullErr
)
// Reset the channel builder
// Reset the channel builder
err
=
cb
.
Reset
()
err
=
cb
.
Reset
()
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// Check the fields reset in the Reset function
// Check the fields reset in the Reset function
testSuite
.
Equal
(
0
,
len
(
cb
.
blocks
))
require
.
Equal
(
t
,
0
,
len
(
cb
.
blocks
))
testSuite
.
Equal
(
0
,
len
(
cb
.
frames
))
require
.
Equal
(
t
,
0
,
len
(
cb
.
frames
))
testSuite
.
Equal
(
uint64
(
0
),
cb
.
timeout
)
require
.
Equal
(
t
,
uint64
(
0
),
cb
.
timeout
)
testSuite
.
Nil
(
cb
.
fullErr
)
require
.
NoError
(
t
,
cb
.
fullErr
)
testSuite
.
Equal
(
0
,
cb
.
co
.
InputBytes
())
require
.
Equal
(
t
,
0
,
cb
.
co
.
InputBytes
())
testSuite
.
Equal
(
0
,
cb
.
co
.
ReadyBytes
())
require
.
Equal
(
t
,
0
,
cb
.
co
.
ReadyBytes
())
}
}
// TestBuilderRegisterL1Block tests the RegisterL1Block function
// TestBuilderRegisterL1Block tests the RegisterL1Block function
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestBuilderRegisterL1Block
()
{
func
TestBuilderRegisterL1Block
(
t
*
testing
.
T
)
{
channelConfig
:=
defaultTestChannelConfig
// Construct the channel builder
// Construct the channel builder
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channelConfig
)
cb
,
err
:=
newChannelBuilder
(
channelConfig
)
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// Assert params modified in RegisterL1Block
// Assert params modified in RegisterL1Block
testSuite
.
Equal
(
uint64
(
1
),
testSuite
.
channelConfig
.
MaxChannelDuration
)
require
.
Equal
(
t
,
uint64
(
1
),
channelConfig
.
MaxChannelDuration
)
testSuite
.
Equal
(
uint64
(
0
),
cb
.
timeout
)
require
.
Equal
(
t
,
uint64
(
0
),
cb
.
timeout
)
// Register a new L1 block
// Register a new L1 block
cb
.
RegisterL1Block
(
uint64
(
100
))
cb
.
RegisterL1Block
(
uint64
(
100
))
// Assert params modified in RegisterL1Block
// Assert params modified in RegisterL1Block
testSuite
.
Equal
(
uint64
(
1
),
testSuite
.
channelConfig
.
MaxChannelDuration
)
require
.
Equal
(
t
,
uint64
(
1
),
channelConfig
.
MaxChannelDuration
)
testSuite
.
Equal
(
uint64
(
101
),
cb
.
timeout
)
require
.
Equal
(
t
,
uint64
(
101
),
cb
.
timeout
)
}
}
// TestBuilderRegisterL1BlockZeroMaxChannelDuration tests the RegisterL1Block function
// TestBuilderRegisterL1BlockZeroMaxChannelDuration tests the RegisterL1Block function
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestBuilderRegisterL1BlockZeroMaxChannelDuration
()
{
func
TestBuilderRegisterL1BlockZeroMaxChannelDuration
(
t
*
testing
.
T
)
{
channelConfig
:=
defaultTestChannelConfig
// Set the max channel duration to 0
// Set the max channel duration to 0
testSuite
.
channelConfig
.
MaxChannelDuration
=
0
channelConfig
.
MaxChannelDuration
=
0
// Construct the channel builder
// Construct the channel builder
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channelConfig
)
cb
,
err
:=
newChannelBuilder
(
channelConfig
)
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// Assert params modified in RegisterL1Block
// Assert params modified in RegisterL1Block
testSuite
.
Equal
(
uint64
(
0
),
testSuite
.
channelConfig
.
MaxChannelDuration
)
require
.
Equal
(
t
,
uint64
(
0
),
channelConfig
.
MaxChannelDuration
)
testSuite
.
Equal
(
uint64
(
0
),
cb
.
timeout
)
require
.
Equal
(
t
,
uint64
(
0
),
cb
.
timeout
)
// Register a new L1 block
// Register a new L1 block
cb
.
RegisterL1Block
(
uint64
(
100
))
cb
.
RegisterL1Block
(
uint64
(
100
))
// Since the max channel duration is set to 0,
// Since the max channel duration is set to 0,
// the L1 block register should not update the timeout
// the L1 block register should not update the timeout
testSuite
.
Equal
(
uint64
(
0
),
testSuite
.
channelConfig
.
MaxChannelDuration
)
require
.
Equal
(
t
,
uint64
(
0
),
channelConfig
.
MaxChannelDuration
)
testSuite
.
Equal
(
uint64
(
0
),
cb
.
timeout
)
require
.
Equal
(
t
,
uint64
(
0
),
cb
.
timeout
)
}
}
// TestFramePublished tests the FramePublished function
// TestFramePublished tests the FramePublished function
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestFramePublished
()
{
func
TestFramePublished
(
t
*
testing
.
T
)
{
channelConfig
:=
defaultTestChannelConfig
// Construct the channel builder
// Construct the channel builder
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channelConfig
)
cb
,
err
:=
newChannelBuilder
(
channelConfig
)
testSuite
.
NoError
(
err
)
require
.
NoError
(
t
,
err
)
// Let's say the block number is fed in as 100
// Let's say the block number is fed in as 100
// and the channel timeout is 1000
// and the channel timeout is 1000
...
@@ -299,28 +298,5 @@ func (testSuite *ChannelBuilderTestSuite) TestFramePublished() {
...
@@ -299,28 +298,5 @@ func (testSuite *ChannelBuilderTestSuite) TestFramePublished() {
cb
.
FramePublished
(
l1BlockNum
)
cb
.
FramePublished
(
l1BlockNum
)
// Now the timeout will be 1000
// Now the timeout will be 1000
testSuite
.
Equal
(
uint64
(
1000
),
cb
.
timeout
)
require
.
Equal
(
t
,
uint64
(
1000
),
cb
.
timeout
)
}
// TestFramePublishedUnderflows tests the FramePublished function
//
// Realistically, this will not happen because the [ChannelTimeout] is _known_
// to be greater than the [SubSafetyMargin] when the ChannelConfig is configured
// via cli flags / environment variables.
func
(
testSuite
*
ChannelBuilderTestSuite
)
TestFramePublishedUnderflows
()
{
// Construct the channel builder
cb
,
err
:=
newChannelBuilder
(
testSuite
.
channelConfig
)
testSuite
.
NoError
(
err
)
// Let's say the block number is fed in as 0
// and the channel timeout is < the sub safety margin
l1BlockNum
:=
uint64
(
0
)
cb
.
cfg
.
ChannelTimeout
=
uint64
(
1
)
cb
.
cfg
.
SubSafetyMargin
=
uint64
(
2
)
// Then the frame published will underflow the timeout
cb
.
FramePublished
(
l1BlockNum
)
// Now the timeout will be the max uint64
testSuite
.
Equal
(
uint64
(
0xffffffffffffffff
),
cb
.
timeout
)
}
}
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