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
6f103820
Commit
6f103820
authored
Dec 06, 2023
by
Tei Im
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure to test all TX types including unprotected tx
parent
46ff55c6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
146 additions
and
100 deletions
+146
-100
batch_test.go
op-node/rollup/derive/batch_test.go
+12
-11
span_batch_test.go
op-node/rollup/derive/span_batch_test.go
+7
-3
span_batch_tx_test.go
op-node/rollup/derive/span_batch_tx_test.go
+18
-9
span_batch_txs_test.go
op-node/rollup/derive/span_batch_txs_test.go
+109
-77
No files found.
op-node/rollup/derive/batch_test.go
View file @
6f103820
...
...
@@ -19,7 +19,7 @@ import (
)
func
RandomRawSpanBatch
(
rng
*
rand
.
Rand
,
chainId
*
big
.
Int
)
*
RawSpanBatch
{
blockCount
:=
uint64
(
1
+
rng
.
Int
()
&
0xFF
)
blockCount
:=
uint64
(
4
+
rng
.
Int
()
&
0xFF
)
// at least 4
originBits
:=
new
(
big
.
Int
)
for
i
:=
0
;
i
<
int
(
blockCount
);
i
++
{
bit
:=
uint
(
0
)
...
...
@@ -30,11 +30,8 @@ func RandomRawSpanBatch(rng *rand.Rand, chainId *big.Int) *RawSpanBatch {
}
var
blockTxCounts
[]
uint64
totalblockTxCounts
:=
uint64
(
0
)
blockTxCounts
=
append
(
blockTxCounts
,
4
)
totalblockTxCounts
+=
4
for
i
:=
1
;
i
<
int
(
blockCount
);
i
++
{
blockTxCount
:=
uint64
(
rng
.
Intn
(
16
))
for
i
:=
0
;
i
<
int
(
blockCount
);
i
++
{
blockTxCount
:=
1
+
uint64
(
rng
.
Intn
(
16
))
blockTxCounts
=
append
(
blockTxCounts
,
blockTxCount
)
totalblockTxCounts
+=
blockTxCount
}
...
...
@@ -42,11 +39,15 @@ func RandomRawSpanBatch(rng *rand.Rand, chainId *big.Int) *RawSpanBatch {
var
txs
[][]
byte
for
i
:=
0
;
i
<
int
(
totalblockTxCounts
);
i
++
{
var
tx
*
types
.
Transaction
// ensure unprotected txs are included
if
i
<
4
||
testutils
.
RandomBool
(
rng
)
{
tx
=
testutils
.
RandomLegacyTxNotProtected
(
rng
)
}
else
{
tx
=
testutils
.
RandomTx
(
rng
,
new
(
big
.
Int
)
.
SetUint64
(
rng
.
Uint64
()),
londonSigner
)
switch
i
%
4
{
case
0
:
tx
=
testutils
.
RandomLegacyTx
(
rng
,
types
.
HomesteadSigner
{})
case
1
:
tx
=
testutils
.
RandomLegacyTx
(
rng
,
londonSigner
)
case
2
:
tx
=
testutils
.
RandomAccessListTx
(
rng
,
londonSigner
)
case
3
:
tx
=
testutils
.
RandomDynamicFeeTx
(
rng
,
londonSigner
)
}
rawTx
,
err
:=
tx
.
MarshalBinary
()
if
err
!=
nil
{
...
...
op-node/rollup/derive/span_batch_test.go
View file @
6f103820
...
...
@@ -447,9 +447,10 @@ func TestSpanBatchToSingularBatch(t *testing.T) {
func
TestSpanBatchReadTxData
(
t
*
testing
.
T
)
{
cases
:=
[]
spanBatchTxTest
{
{
"legacy tx"
,
32
,
testutils
.
RandomLegacyTx
},
{
"access list tx"
,
32
,
testutils
.
RandomAccessListTx
},
{
"dynamic fee tx"
,
32
,
testutils
.
RandomDynamicFeeTx
},
{
"unprotected legacy tx"
,
32
,
testutils
.
RandomLegacyTx
,
false
},
{
"legacy tx"
,
32
,
testutils
.
RandomLegacyTx
,
true
},
{
"access list tx"
,
32
,
testutils
.
RandomAccessListTx
,
true
},
{
"dynamic fee tx"
,
32
,
testutils
.
RandomDynamicFeeTx
,
true
},
}
for
i
,
testCase
:=
range
cases
{
...
...
@@ -457,6 +458,9 @@ func TestSpanBatchReadTxData(t *testing.T) {
rng
:=
rand
.
New
(
rand
.
NewSource
(
int64
(
0x109550
+
i
)))
chainID
:=
new
(
big
.
Int
)
.
SetUint64
(
rng
.
Uint64
())
signer
:=
types
.
NewLondonSigner
(
chainID
)
if
!
testCase
.
protected
{
signer
=
types
.
HomesteadSigner
{}
}
var
rawTxs
[][]
byte
var
txs
[]
*
types
.
Transaction
...
...
op-node/rollup/derive/span_batch_tx_test.go
View file @
6f103820
...
...
@@ -15,13 +15,15 @@ type spanBatchTxTest struct {
name
string
trials
int
mkTx
func
(
rng
*
rand
.
Rand
,
signer
types
.
Signer
)
*
types
.
Transaction
protected
bool
}
func
TestSpanBatchTxConvert
(
t
*
testing
.
T
)
{
cases
:=
[]
spanBatchTxTest
{
{
"legacy tx"
,
32
,
testutils
.
RandomLegacyTx
},
{
"access list tx"
,
32
,
testutils
.
RandomAccessListTx
},
{
"dynamic fee tx"
,
32
,
testutils
.
RandomDynamicFeeTx
},
{
"unprotected legacy tx"
,
32
,
testutils
.
RandomLegacyTx
,
false
},
{
"legacy tx"
,
32
,
testutils
.
RandomLegacyTx
,
true
},
{
"access list tx"
,
32
,
testutils
.
RandomAccessListTx
,
true
},
{
"dynamic fee tx"
,
32
,
testutils
.
RandomDynamicFeeTx
,
true
},
}
for
i
,
testCase
:=
range
cases
{
...
...
@@ -29,6 +31,9 @@ func TestSpanBatchTxConvert(t *testing.T) {
rng
:=
rand
.
New
(
rand
.
NewSource
(
int64
(
0x1331
+
i
)))
chainID
:=
big
.
NewInt
(
rng
.
Int63n
(
1000
))
signer
:=
types
.
NewLondonSigner
(
chainID
)
if
!
testCase
.
protected
{
signer
=
types
.
HomesteadSigner
{}
}
for
txIdx
:=
0
;
txIdx
<
testCase
.
trials
;
txIdx
++
{
tx
:=
testCase
.
mkTx
(
rng
,
signer
)
...
...
@@ -54,9 +59,10 @@ func TestSpanBatchTxConvert(t *testing.T) {
func
TestSpanBatchTxRoundTrip
(
t
*
testing
.
T
)
{
cases
:=
[]
spanBatchTxTest
{
{
"legacy tx"
,
32
,
testutils
.
RandomLegacyTx
},
{
"access list tx"
,
32
,
testutils
.
RandomAccessListTx
},
{
"dynamic fee tx"
,
32
,
testutils
.
RandomDynamicFeeTx
},
{
"unprotected legacy tx"
,
32
,
testutils
.
RandomLegacyTx
,
false
},
{
"legacy tx"
,
32
,
testutils
.
RandomLegacyTx
,
true
},
{
"access list tx"
,
32
,
testutils
.
RandomAccessListTx
,
true
},
{
"dynamic fee tx"
,
32
,
testutils
.
RandomDynamicFeeTx
,
true
},
}
for
i
,
testCase
:=
range
cases
{
...
...
@@ -64,6 +70,9 @@ func TestSpanBatchTxRoundTrip(t *testing.T) {
rng
:=
rand
.
New
(
rand
.
NewSource
(
int64
(
0x1332
+
i
)))
chainID
:=
big
.
NewInt
(
rng
.
Int63n
(
1000
))
signer
:=
types
.
NewLondonSigner
(
chainID
)
if
!
testCase
.
protected
{
signer
=
types
.
HomesteadSigner
{}
}
for
txIdx
:=
0
;
txIdx
<
testCase
.
trials
;
txIdx
++
{
tx
:=
testCase
.
mkTx
(
rng
,
signer
)
...
...
op-node/rollup/derive/span_batch_txs_test.go
View file @
6f103820
...
...
@@ -14,6 +14,12 @@ import (
"github.com/ethereum-optimism/optimism/op-service/testutils"
)
type
txTypeTest
struct
{
name
string
mkTx
func
(
rng
*
rand
.
Rand
,
signer
types
.
Signer
)
*
types
.
Transaction
signer
types
.
Signer
}
func
TestSpanBatchTxsContractCreationBits
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
0x1234567
))
chainID
:=
big
.
NewInt
(
rng
.
Int63n
(
1000
))
...
...
@@ -304,6 +310,15 @@ func TestSpanBatchTxsRecoverV(t *testing.T) {
londonSigner
:=
types
.
NewLondonSigner
(
chainID
)
totalblockTxCount
:=
20
+
rng
.
Intn
(
100
)
cases
:=
[]
txTypeTest
{
{
"unprotected legacy tx"
,
testutils
.
RandomLegacyTx
,
types
.
HomesteadSigner
{}},
{
"legacy tx"
,
testutils
.
RandomLegacyTx
,
londonSigner
},
{
"access list tx"
,
testutils
.
RandomAccessListTx
,
londonSigner
},
{
"dynamic fee tx"
,
testutils
.
RandomDynamicFeeTx
,
londonSigner
},
}
for
_
,
testCase
:=
range
cases
{
t
.
Run
(
testCase
.
name
,
func
(
t
*
testing
.
T
)
{
var
spanBatchTxs
spanBatchTxs
var
txTypes
[]
int
var
txSigs
[]
spanBatchSignature
...
...
@@ -312,13 +327,7 @@ func TestSpanBatchTxsRecoverV(t *testing.T) {
protectedBits
:=
new
(
big
.
Int
)
totalLegacyTxCount
:=
0
for
idx
:=
0
;
idx
<
totalblockTxCount
;
idx
++
{
var
tx
*
types
.
Transaction
// ensure unprotected txs are included
if
idx
<
4
||
testutils
.
RandomBool
(
rng
)
{
tx
=
testutils
.
RandomLegacyTxNotProtected
(
rng
)
}
else
{
tx
=
testutils
.
RandomTx
(
rng
,
new
(
big
.
Int
)
.
SetUint64
(
rng
.
Uint64
()),
londonSigner
)
}
tx
:=
testCase
.
mkTx
(
rng
,
testCase
.
signer
)
txType
:=
tx
.
Type
()
txTypes
=
append
(
txTypes
,
int
(
txType
))
var
txSig
spanBatchSignature
...
...
@@ -353,8 +362,9 @@ func TestSpanBatchTxsRecoverV(t *testing.T) {
for
_
,
txSig
:=
range
spanBatchTxs
.
txSigs
{
recoveredVs
=
append
(
recoveredVs
,
txSig
.
v
)
}
require
.
Equal
(
t
,
originalVs
,
recoveredVs
,
"recovered v mismatch"
)
})
}
}
func
TestSpanBatchTxsRoundTrip
(
t
*
testing
.
T
)
{
...
...
@@ -388,13 +398,22 @@ func TestSpanBatchTxsRoundTrip(t *testing.T) {
func
TestSpanBatchTxsRoundTripFullTxs
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
0x13377331
))
chainID
:=
big
.
NewInt
(
rng
.
Int63n
(
1000
))
s
igner
:=
types
.
NewLondonSigner
(
chainID
)
londonS
igner
:=
types
.
NewLondonSigner
(
chainID
)
cases
:=
[]
txTypeTest
{
{
"unprotected legacy tx"
,
testutils
.
RandomLegacyTx
,
types
.
HomesteadSigner
{}},
{
"legacy tx"
,
testutils
.
RandomLegacyTx
,
londonSigner
},
{
"access list tx"
,
testutils
.
RandomAccessListTx
,
londonSigner
},
{
"dynamic fee tx"
,
testutils
.
RandomDynamicFeeTx
,
londonSigner
},
}
for
_
,
testCase
:=
range
cases
{
t
.
Run
(
testCase
.
name
,
func
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
4
;
i
++
{
totalblockTxCounts
:=
uint64
(
1
+
rng
.
Int
()
&
0xFF
)
var
txs
[][]
byte
for
i
:=
0
;
i
<
int
(
totalblockTxCounts
);
i
++
{
tx
:=
testutils
.
RandomTx
(
rng
,
new
(
big
.
Int
)
.
SetUint64
(
rng
.
Uint64
()),
signer
)
tx
:=
testCase
.
mkTx
(
rng
,
testCase
.
signer
)
rawTx
,
err
:=
tx
.
MarshalBinary
()
require
.
NoError
(
t
,
err
)
txs
=
append
(
txs
,
rawTx
)
...
...
@@ -407,6 +426,8 @@ func TestSpanBatchTxsRoundTripFullTxs(t *testing.T) {
require
.
Equal
(
t
,
txs
,
txs2
)
}
})
}
}
func
TestSpanBatchTxsRecoverVInvalidTxType
(
t
*
testing
.
T
)
{
...
...
@@ -427,12 +448,21 @@ func TestSpanBatchTxsRecoverVInvalidTxType(t *testing.T) {
func
TestSpanBatchTxsFullTxNotEnoughTxTos
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
0x13572468
))
chainID
:=
big
.
NewInt
(
rng
.
Int63n
(
1000
))
s
igner
:=
types
.
NewLondonSigner
(
chainID
)
londonS
igner
:=
types
.
NewLondonSigner
(
chainID
)
cases
:=
[]
txTypeTest
{
{
"unprotected legacy tx"
,
testutils
.
RandomLegacyTx
,
types
.
HomesteadSigner
{}},
{
"legacy tx"
,
testutils
.
RandomLegacyTx
,
londonSigner
},
{
"access list tx"
,
testutils
.
RandomAccessListTx
,
londonSigner
},
{
"dynamic fee tx"
,
testutils
.
RandomDynamicFeeTx
,
londonSigner
},
}
for
_
,
testCase
:=
range
cases
{
t
.
Run
(
testCase
.
name
,
func
(
t
*
testing
.
T
)
{
totalblockTxCounts
:=
uint64
(
1
+
rng
.
Int
()
&
0xFF
)
var
txs
[][]
byte
for
i
:=
0
;
i
<
int
(
totalblockTxCounts
);
i
++
{
tx
:=
testutils
.
RandomTx
(
rng
,
new
(
big
.
Int
)
.
SetUint64
(
rng
.
Uint64
()),
signer
)
tx
:=
testCase
.
mkTx
(
rng
,
testCase
.
signer
)
rawTx
,
err
:=
tx
.
MarshalBinary
()
require
.
NoError
(
t
,
err
)
txs
=
append
(
txs
,
rawTx
)
...
...
@@ -445,6 +475,8 @@ func TestSpanBatchTxsFullTxNotEnoughTxTos(t *testing.T) {
_
,
err
=
sbt
.
fullTxs
(
chainID
)
require
.
EqualError
(
t
,
err
,
"tx to not enough"
)
})
}
}
func
TestSpanBatchTxsMaxContractCreationBitsLength
(
t
*
testing
.
T
)
{
...
...
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