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
814e68f7
Commit
814e68f7
authored
Mar 15, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test channel manager clearing wipes state :test_tube:
parent
5bae9058
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
0 deletions
+115
-0
channel_manager_test.go
op-batcher/batcher/channel_manager_test.go
+115
-0
No files found.
op-batcher/batcher/channel_manager_test.go
View file @
814e68f7
...
@@ -128,6 +128,79 @@ func TestChannelManagerNextTxData(t *testing.T) {
...
@@ -128,6 +128,79 @@ func TestChannelManagerNextTxData(t *testing.T) {
require
.
Equal
(
t
,
expectedTxData
,
m
.
pendingTransactions
[
expectedChannelID
])
require
.
Equal
(
t
,
expectedTxData
,
m
.
pendingTransactions
[
expectedChannelID
])
}
}
// TestClearChannelManager tests clearing the channel manager.
func
TestClearChannelManager
(
t
*
testing
.
T
)
{
// Create a channel manager
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
rng
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
m
:=
NewChannelManager
(
log
,
ChannelConfig
{
// Need to set the channel timeout here so we don't clear pending
// channels on confirmation. This would result in [TxConfirmed]
// clearing confirmed transactions, and reseting the pendingChannels map
ChannelTimeout
:
10
,
// Have to set the max frame size here otherwise the channel builder would not
// be able to output any frames
MaxFrameSize
:
1
,
})
// Channel Manager state should be empty by default
require
.
Empty
(
t
,
m
.
blocks
)
require
.
Equal
(
t
,
common
.
Hash
{},
m
.
tip
)
require
.
Nil
(
t
,
m
.
pendingChannel
)
require
.
Empty
(
t
,
m
.
pendingTransactions
)
require
.
Empty
(
t
,
m
.
confirmedTransactions
)
// Add a block to the channel manager
a
,
_
:=
derivetest
.
RandomL2Block
(
rng
,
4
)
newL1Tip
:=
a
.
Hash
()
l1BlockID
:=
eth
.
BlockID
{
Hash
:
a
.
Hash
(),
Number
:
a
.
NumberU64
(),
}
err
:=
m
.
AddL2Block
(
a
)
require
.
NoError
(
t
,
err
)
// Make sure there is a channel builder
m
.
ensurePendingChannel
(
l1BlockID
)
require
.
NotNil
(
t
,
m
.
pendingChannel
)
require
.
Equal
(
t
,
0
,
len
(
m
.
confirmedTransactions
))
// Process the blocks
// We should have a pending channel with 1 frame
// and no more blocks since processBlocks consumes
// the list
err
=
m
.
processBlocks
()
require
.
NoError
(
t
,
err
)
err
=
m
.
pendingChannel
.
OutputFrames
()
require
.
NoError
(
t
,
err
)
_
,
err
=
m
.
nextTxData
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
0
,
len
(
m
.
blocks
))
require
.
Equal
(
t
,
newL1Tip
,
m
.
tip
)
require
.
Equal
(
t
,
1
,
len
(
m
.
pendingTransactions
))
// Add a new block so we can test clearing
// the channel manager with a full state
b
:=
types
.
NewBlock
(
&
types
.
Header
{
Number
:
big
.
NewInt
(
1
),
ParentHash
:
a
.
Hash
(),
},
nil
,
nil
,
nil
,
nil
)
err
=
m
.
AddL2Block
(
b
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
1
,
len
(
m
.
blocks
))
require
.
Equal
(
t
,
b
.
Hash
(),
m
.
tip
)
// Clear the channel manager
m
.
Clear
()
// Check that the entire channel manager state cleared
require
.
Empty
(
t
,
m
.
blocks
)
require
.
Equal
(
t
,
common
.
Hash
{},
m
.
tip
)
require
.
Nil
(
t
,
m
.
pendingChannel
)
require
.
Empty
(
t
,
m
.
pendingTransactions
)
require
.
Empty
(
t
,
m
.
confirmedTransactions
)
}
// TestChannelManagerTxConfirmed checks the [ChannelManager.TxConfirmed] function.
// TestChannelManagerTxConfirmed checks the [ChannelManager.TxConfirmed] function.
func
TestChannelManagerTxConfirmed
(
t
*
testing
.
T
)
{
func
TestChannelManagerTxConfirmed
(
t
*
testing
.
T
)
{
// Create a channel manager
// Create a channel manager
...
@@ -181,6 +254,48 @@ func TestChannelManagerTxConfirmed(t *testing.T) {
...
@@ -181,6 +254,48 @@ func TestChannelManagerTxConfirmed(t *testing.T) {
require
.
Equal
(
t
,
blockID
,
m
.
confirmedTransactions
[
expectedChannelID
])
require
.
Equal
(
t
,
blockID
,
m
.
confirmedTransactions
[
expectedChannelID
])
}
}
// TestChannelManagerTxFailed checks the [ChannelManager.TxFailed] function.
func
TestChannelManagerTxFailed
(
t
*
testing
.
T
)
{
// Create a channel manager
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
m
:=
NewChannelManager
(
log
,
ChannelConfig
{})
// Let's add a valid pending transaction to the channel
// manager so we can demonstrate correctness
m
.
ensurePendingChannel
(
eth
.
BlockID
{})
channelID
:=
m
.
pendingChannel
.
ID
()
frame
:=
frameData
{
data
:
[]
byte
{},
id
:
frameID
{
chID
:
channelID
,
frameNumber
:
uint16
(
0
),
},
}
m
.
pendingChannel
.
PushFrame
(
frame
)
require
.
Equal
(
t
,
1
,
m
.
pendingChannel
.
NumFrames
())
returnedTxData
,
err
:=
m
.
nextTxData
()
expectedTxData
:=
txData
{
frame
}
expectedChannelID
:=
expectedTxData
.
ID
()
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
expectedTxData
,
returnedTxData
)
require
.
Equal
(
t
,
0
,
m
.
pendingChannel
.
NumFrames
())
require
.
Equal
(
t
,
expectedTxData
,
m
.
pendingTransactions
[
expectedChannelID
])
require
.
Equal
(
t
,
1
,
len
(
m
.
pendingTransactions
))
// Trying to mark an unknown pending transaction as failed
// shouldn't modify state
m
.
TxFailed
(
frameID
{})
require
.
Equal
(
t
,
0
,
m
.
pendingChannel
.
NumFrames
())
require
.
Equal
(
t
,
expectedTxData
,
m
.
pendingTransactions
[
expectedChannelID
])
// Now we still have a pending transaction
// Let's mark it as failed
m
.
TxFailed
(
expectedChannelID
)
require
.
Empty
(
t
,
m
.
pendingTransactions
)
// There should be a frame in the pending channel now
require
.
Equal
(
t
,
1
,
m
.
pendingChannel
.
NumFrames
())
}
func
TestChannelManager_TxResend
(
t
*
testing
.
T
)
{
func
TestChannelManager_TxResend
(
t
*
testing
.
T
)
{
require
:=
require
.
New
(
t
)
require
:=
require
.
New
(
t
)
rng
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
rng
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
...
...
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