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
c6d39019
Unverified
Commit
c6d39019
authored
Oct 16, 2023
by
pcw109550
Committed by
protolambda
Oct 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for span batch field size check
parent
177b78c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
1 deletion
+61
-1
span_batch_test.go
op-node/rollup/derive/span_batch_test.go
+61
-1
No files found.
op-node/rollup/derive/span_batch_test.go
View file @
c6d39019
...
...
@@ -2,6 +2,7 @@ package derive
import
(
"bytes"
"math"
"math/big"
"math/rand"
"testing"
...
...
@@ -542,9 +543,68 @@ func TestSpanBatchMaxTxData(t *testing.T) {
func
TestSpanBatchMaxOriginBitsLength
(
t
*
testing
.
T
)
{
var
sb
RawSpanBatch
sb
.
blockCount
=
0xFFFFFFFFFFFFFFFF
sb
.
blockCount
=
math
.
MaxUint64
r
:=
bytes
.
NewReader
([]
byte
{})
err
:=
sb
.
decodeOriginBits
(
r
)
assert
.
ErrorIs
(
t
,
err
,
ErrTooBigSpanBatchFieldSize
)
}
func
TestSpanBatchMaxBlockCount
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
0x77556691
))
chainID
:=
big
.
NewInt
(
rng
.
Int63n
(
1000
))
rawSpanBatch
:=
RandomRawSpanBatch
(
rng
,
chainID
)
rawSpanBatch
.
blockCount
=
math
.
MaxUint64
var
buf
bytes
.
Buffer
err
:=
rawSpanBatch
.
encodeBlockCount
(
&
buf
)
require
.
NoError
(
t
,
err
)
result
:=
buf
.
Bytes
()
r
:=
bytes
.
NewReader
(
result
)
var
sb
RawSpanBatch
err
=
sb
.
decodeBlockCount
(
r
)
require
.
ErrorIs
(
t
,
err
,
ErrTooBigSpanBatchFieldSize
)
}
func
TestSpanBatchMaxBlockTxCount
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
0x77556692
))
chainID
:=
big
.
NewInt
(
rng
.
Int63n
(
1000
))
rawSpanBatch
:=
RandomRawSpanBatch
(
rng
,
chainID
)
rawSpanBatch
.
blockTxCounts
[
0
]
=
math
.
MaxUint64
var
buf
bytes
.
Buffer
err
:=
rawSpanBatch
.
encodeBlockTxCounts
(
&
buf
)
require
.
NoError
(
t
,
err
)
result
:=
buf
.
Bytes
()
r
:=
bytes
.
NewReader
(
result
)
var
sb
RawSpanBatch
sb
.
blockCount
=
rawSpanBatch
.
blockCount
err
=
sb
.
decodeBlockTxCounts
(
r
)
require
.
ErrorIs
(
t
,
err
,
ErrTooBigSpanBatchFieldSize
)
}
func
TestSpanBatchTotalBlockTxCountNotOverflow
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
0x77556693
))
chainID
:=
big
.
NewInt
(
rng
.
Int63n
(
1000
))
rawSpanBatch
:=
RandomRawSpanBatch
(
rng
,
chainID
)
rawSpanBatch
.
blockTxCounts
[
0
]
=
MaxSpanBatchFieldSize
-
1
rawSpanBatch
.
blockTxCounts
[
1
]
=
MaxSpanBatchFieldSize
-
1
// we are sure that totalBlockTxCount will overflow on uint64
var
buf
bytes
.
Buffer
err
:=
rawSpanBatch
.
encodeBlockTxCounts
(
&
buf
)
require
.
NoError
(
t
,
err
)
result
:=
buf
.
Bytes
()
r
:=
bytes
.
NewReader
(
result
)
var
sb
RawSpanBatch
sb
.
blockTxCounts
=
rawSpanBatch
.
blockTxCounts
err
=
sb
.
decodeTxs
(
r
)
require
.
ErrorIs
(
t
,
err
,
ErrTooBigSpanBatchFieldSize
)
}
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