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
9a798189
Commit
9a798189
authored
Dec 06, 2023
by
pcw109550
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Span batch unit test upsert for protectedBits
parent
b9ed1518
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
span_batch_txs_test.go
op-node/rollup/derive/span_batch_txs_test.go
+50
-0
No files found.
op-node/rollup/derive/span_batch_txs_test.go
View file @
9a798189
...
...
@@ -112,6 +112,44 @@ func TestSpanBatchTxsYParityBits(t *testing.T) {
require
.
Equal
(
t
,
yParityBits
,
sbt
.
yParityBits
)
}
func
TestSpanBatchTxsProtectedBits
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
0x7331
))
chainID
:=
big
.
NewInt
(
rng
.
Int63n
(
1000
))
rawSpanBatch
:=
RandomRawSpanBatch
(
rng
,
chainID
)
protectedBits
:=
rawSpanBatch
.
txs
.
protectedBits
txTypes
:=
rawSpanBatch
.
txs
.
txTypes
totalBlockTxCount
:=
rawSpanBatch
.
txs
.
totalBlockTxCount
totalLegacyTxCount
:=
rawSpanBatch
.
txs
.
totalLegacyTxCount
var
sbt
spanBatchTxs
sbt
.
protectedBits
=
protectedBits
sbt
.
totalBlockTxCount
=
totalBlockTxCount
sbt
.
txTypes
=
txTypes
sbt
.
totalLegacyTxCount
=
totalLegacyTxCount
var
buf
bytes
.
Buffer
err
:=
sbt
.
encodeProtectedBits
(
&
buf
)
require
.
NoError
(
t
,
err
)
// protectedBit field is fixed length: single bit
protectedBitBufferLen
:=
totalLegacyTxCount
/
8
require
.
NoError
(
t
,
err
)
if
totalLegacyTxCount
%
8
!=
0
{
protectedBitBufferLen
++
}
require
.
Equal
(
t
,
buf
.
Len
(),
int
(
protectedBitBufferLen
))
result
:=
buf
.
Bytes
()
sbt
.
protectedBits
=
nil
r
:=
bytes
.
NewReader
(
result
)
err
=
sbt
.
decodeProtectedBits
(
r
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
protectedBits
,
sbt
.
protectedBits
)
}
func
TestSpanBatchTxsTxSigs
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
0x73311337
))
chainID
:=
big
.
NewInt
(
rng
.
Int63n
(
1000
))
...
...
@@ -289,6 +327,7 @@ func TestSpanBatchTxsRecoverV(t *testing.T) {
spanBatchTxs
.
yParityBits
=
yParityBits
spanBatchTxs
.
txSigs
=
txSigs
spanBatchTxs
.
txTypes
=
txTypes
spanBatchTxs
.
protectedBits
=
protectedBits
// recover txSig.v
err
:=
spanBatchTxs
.
recoverV
(
chainID
)
require
.
NoError
(
t
,
err
)
...
...
@@ -362,6 +401,7 @@ func TestSpanBatchTxsRecoverVInvalidTxType(t *testing.T) {
sbt
.
txTypes
=
[]
int
{
types
.
DepositTxType
}
sbt
.
txSigs
=
[]
spanBatchSignature
{{
v
:
0
,
r
:
nil
,
s
:
nil
}}
sbt
.
yParityBits
=
new
(
big
.
Int
)
sbt
.
protectedBits
=
new
(
big
.
Int
)
err
:=
sbt
.
recoverV
(
chainID
)
require
.
ErrorContains
(
t
,
err
,
"invalid tx type"
)
...
...
@@ -407,3 +447,13 @@ func TestSpanBatchTxsMaxYParityBitsLength(t *testing.T) {
err
:=
sb
.
decodeOriginBits
(
r
)
require
.
ErrorIs
(
t
,
err
,
ErrTooBigSpanBatchSize
)
}
func
TestSpanBatchTxsMaxProtectedBitsLength
(
t
*
testing
.
T
)
{
var
sb
RawSpanBatch
sb
.
txs
=
&
spanBatchTxs
{}
sb
.
txs
.
totalLegacyTxCount
=
0xFFFFFFFFFFFFFFFF
r
:=
bytes
.
NewReader
([]
byte
{})
err
:=
sb
.
txs
.
decodeProtectedBits
(
r
)
require
.
ErrorIs
(
t
,
err
,
ErrTooBigSpanBatchSize
)
}
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