Commit 1e751d4e authored by pcw109550's avatar pcw109550

op-node: Ensure unit tests to handle Span batches with unprotected txs

parent 9a798189
...@@ -30,15 +30,24 @@ func RandomRawSpanBatch(rng *rand.Rand, chainId *big.Int) *RawSpanBatch { ...@@ -30,15 +30,24 @@ func RandomRawSpanBatch(rng *rand.Rand, chainId *big.Int) *RawSpanBatch {
} }
var blockTxCounts []uint64 var blockTxCounts []uint64
totalblockTxCounts := uint64(0) totalblockTxCounts := uint64(0)
for i := 0; i < int(blockCount); i++ {
blockTxCounts = append(blockTxCounts, 4)
totalblockTxCounts += 4
for i := 1; i < int(blockCount); i++ {
blockTxCount := uint64(rng.Intn(16)) blockTxCount := uint64(rng.Intn(16))
blockTxCounts = append(blockTxCounts, blockTxCount) blockTxCounts = append(blockTxCounts, blockTxCount)
totalblockTxCounts += blockTxCount totalblockTxCounts += blockTxCount
} }
signer := types.NewLondonSigner(chainId) londonSigner := types.NewLondonSigner(chainId)
var txs [][]byte var txs [][]byte
for i := 0; i < int(totalblockTxCounts); i++ { for i := 0; i < int(totalblockTxCounts); i++ {
tx := testutils.RandomTx(rng, new(big.Int).SetUint64(rng.Uint64()), signer) 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)
}
rawTx, err := tx.MarshalBinary() rawTx, err := tx.MarshalBinary()
if err != nil { if err != nil {
panic("MarshalBinary:" + err.Error()) panic("MarshalBinary:" + err.Error())
......
...@@ -301,19 +301,36 @@ func TestSpanBatchTxsRecoverV(t *testing.T) { ...@@ -301,19 +301,36 @@ func TestSpanBatchTxsRecoverV(t *testing.T) {
rng := rand.New(rand.NewSource(0x123)) rng := rand.New(rand.NewSource(0x123))
chainID := big.NewInt(rng.Int63n(1000)) chainID := big.NewInt(rng.Int63n(1000))
signer := types.NewLondonSigner(chainID) londonSigner := types.NewLondonSigner(chainID)
totalblockTxCount := rng.Intn(100) totalblockTxCount := 20 + rng.Intn(100)
var spanBatchTxs spanBatchTxs var spanBatchTxs spanBatchTxs
var txTypes []int var txTypes []int
var txSigs []spanBatchSignature var txSigs []spanBatchSignature
var originalVs []uint64 var originalVs []uint64
yParityBits := new(big.Int) yParityBits := new(big.Int)
protectedBits := new(big.Int)
totalLegacyTxCount := 0
for idx := 0; idx < totalblockTxCount; idx++ { for idx := 0; idx < totalblockTxCount; idx++ {
tx := testutils.RandomTx(rng, new(big.Int).SetUint64(rng.Uint64()), signer) var tx *types.Transaction
txTypes = append(txTypes, int(tx.Type())) // 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)
}
txType := tx.Type()
txTypes = append(txTypes, int(txType))
var txSig spanBatchSignature var txSig spanBatchSignature
v, r, s := tx.RawSignatureValues() v, r, s := tx.RawSignatureValues()
if txType == types.LegacyTxType {
protectedBit := uint(0)
if tx.Protected() {
protectedBit = uint(1)
}
protectedBits.SetBit(protectedBits, int(totalLegacyTxCount), protectedBit)
totalLegacyTxCount++
}
// Do not fill in txSig.V // Do not fill in txSig.V
txSig.r, _ = uint256.FromBig(r) txSig.r, _ = uint256.FromBig(r)
txSig.s, _ = uint256.FromBig(s) txSig.s, _ = uint256.FromBig(s)
......
...@@ -157,6 +157,10 @@ func RandomTx(rng *rand.Rand, baseFee *big.Int, signer types.Signer) *types.Tran ...@@ -157,6 +157,10 @@ func RandomTx(rng *rand.Rand, baseFee *big.Int, signer types.Signer) *types.Tran
return tx return tx
} }
func RandomLegacyTxNotProtected(rng *rand.Rand) *types.Transaction {
return RandomLegacyTx(rng, types.HomesteadSigner{})
}
func RandomLegacyTx(rng *rand.Rand, signer types.Signer) *types.Transaction { func RandomLegacyTx(rng *rand.Rand, signer types.Signer) *types.Transaction {
key := InsecureRandomKey(rng) key := InsecureRandomKey(rng)
txData := &types.LegacyTx{ txData := &types.LegacyTx{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment