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
a3de625a
Unverified
Commit
a3de625a
authored
Nov 02, 2022
by
Joshua Gutow
Committed by
GitHub
Nov 02, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Add unit tests to origin selector (#3860)
parent
8fccc433
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
135 additions
and
0 deletions
+135
-0
origin_selector_test.go
op-node/rollup/driver/origin_selector_test.go
+135
-0
No files found.
op-node/rollup/driver/origin_selector_test.go
0 → 100644
View file @
a3de625a
package
driver
import
(
"context"
"testing"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-node/testutils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
)
// TestOriginSelectorAdvances ensures that the origin selector
// advances the origin
//
// There are 2 L1 blocks at time 20 & 25. The L2 Head is at time 24.
// The next L2 time is 26 which is after the next L1 block time. There
// is no conf depth to stop the origin selection so block `b` should
// be the next L1 origin
func
TestOriginSelectorAdvances
(
t
*
testing
.
T
)
{
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
cfg
:=
&
rollup
.
Config
{
MaxSequencerDrift
:
500
,
BlockTime
:
2
,
}
l1
:=
&
testutils
.
MockL1Source
{}
a
:=
eth
.
L1BlockRef
{
Hash
:
common
.
Hash
{
'a'
},
Number
:
10
,
Time
:
20
,
}
b
:=
eth
.
L1BlockRef
{
Hash
:
common
.
Hash
{
'b'
},
Number
:
11
,
Time
:
25
,
ParentHash
:
a
.
Hash
,
}
l2Head
:=
eth
.
L2BlockRef
{
L1Origin
:
a
.
ID
(),
Time
:
24
,
}
l1
.
ExpectL1BlockRefByHash
(
a
.
Hash
,
a
,
nil
)
l1
.
ExpectL1BlockRefByNumber
(
b
.
Number
,
b
,
nil
)
s
:=
NewL1OriginSelector
(
log
,
cfg
,
l1
,
0
)
next
,
err
:=
s
.
FindL1Origin
(
context
.
Background
(),
b
,
l2Head
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
b
,
next
)
}
// TestOriginSelectorRespectsOriginTiming ensures that the origin selector
// does not pick an origin that is ahead of the next L2 block time
//
// There are 2 L1 blocks at time 20 & 25. The L2 Head is at time 22.
// The next L2 time is 24 which is before the next L1 block time. There
// is no conf depth to stop the LOS from potentially selecting block `b`
// but it should select block `a` because the L2 block time must be ahead
// of the the timestamp of it's L1 origin.
func
TestOriginSelectorRespectsOriginTiming
(
t
*
testing
.
T
)
{
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
cfg
:=
&
rollup
.
Config
{
MaxSequencerDrift
:
500
,
BlockTime
:
2
,
}
l1
:=
&
testutils
.
MockL1Source
{}
a
:=
eth
.
L1BlockRef
{
Hash
:
common
.
Hash
{
'a'
},
Number
:
10
,
Time
:
20
,
}
b
:=
eth
.
L1BlockRef
{
Hash
:
common
.
Hash
{
'b'
},
Number
:
11
,
Time
:
25
,
ParentHash
:
a
.
Hash
,
}
l2Head
:=
eth
.
L2BlockRef
{
L1Origin
:
a
.
ID
(),
Time
:
22
,
}
l1
.
ExpectL1BlockRefByHash
(
a
.
Hash
,
a
,
nil
)
l1
.
ExpectL1BlockRefByNumber
(
b
.
Number
,
b
,
nil
)
s
:=
NewL1OriginSelector
(
log
,
cfg
,
l1
,
0
)
next
,
err
:=
s
.
FindL1Origin
(
context
.
Background
(),
b
,
l2Head
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
a
,
next
)
}
// TestOriginSelectorRespectsConfDepth ensures that the origin selector
// will respects the confirmation depth requirement
//
// There are 2 L1 blocks at time 20 & 25. The L2 Head is at time 27.
// The next L2 time is 29 which enough to normally select block `b`
// as the origin, however block `b` is the L1 Head & the sequencer
// needs to wait until that block is confirmed enough before advancing.
func
TestOriginSelectorRespectsConfDepth
(
t
*
testing
.
T
)
{
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
cfg
:=
&
rollup
.
Config
{
MaxSequencerDrift
:
500
,
BlockTime
:
2
,
}
l1
:=
&
testutils
.
MockL1Source
{}
a
:=
eth
.
L1BlockRef
{
Hash
:
common
.
Hash
{
'a'
},
Number
:
10
,
Time
:
20
,
}
b
:=
eth
.
L1BlockRef
{
Hash
:
common
.
Hash
{
'b'
},
Number
:
11
,
Time
:
25
,
ParentHash
:
a
.
Hash
,
}
l2Head
:=
eth
.
L2BlockRef
{
L1Origin
:
a
.
ID
(),
Time
:
27
,
}
l1
.
ExpectL1BlockRefByHash
(
a
.
Hash
,
a
,
nil
)
l1
.
ExpectL1BlockRefByNumber
(
b
.
Number
,
b
,
nil
)
s
:=
NewL1OriginSelector
(
log
,
cfg
,
l1
,
10
)
next
,
err
:=
s
.
FindL1Origin
(
context
.
Background
(),
b
,
l2Head
)
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
a
,
next
)
}
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