33 Tests uncoupled blob txs for [EIP-7742: Uncouple blob count between CL and EL](https://eips.ethereum.org/EIPS/eip-7742)
44""" # noqa: E501
55
6+ import itertools
7+ from typing import List , Tuple
8+
69import pytest
710
8- from ethereum_test_tools import Alloc , Environment , StateTestFiller , Transaction
11+ from ethereum_test_tools import (
12+ Alloc ,
13+ Block ,
14+ BlockchainTestFiller ,
15+ Environment ,
16+ StateTestFiller ,
17+ Transaction ,
18+ )
919
1020from .spec import Spec , ref_spec_7742
1121
1525
1626@pytest .mark .parametrize (
1727 "blobs_per_tx" ,
18- [(0 ,)],
28+ [
29+ (Spec .CANCUN_MAX_BLOBS_PER_BLOCK + 1 ,),
30+ (Spec .CANCUN_MAX_BLOBS_PER_BLOCK + 2 ,),
31+ (Spec .CANCUN_MAX_BLOBS_PER_BLOCK + 3 ,),
32+ ],
1933)
2034@pytest .mark .valid_from ("Prague" )
21- def test_zero_blobs_in_blob_tx (
35+ def test_blobs_above_cancun_max (
2236 state_test : StateTestFiller ,
2337 pre : Alloc ,
2438 state_env : Environment ,
2539 txs : list [Transaction ],
2640):
2741 """
28- Test that a blob transaction with zero blobs is accepted in Prague (EIP-7742) .
42+ Test that transactions with blob counts above the Cancun maximum are accepted in Prague.
2943 """
3044 state_test (
3145 pre = pre ,
@@ -37,21 +51,17 @@ def test_zero_blobs_in_blob_tx(
3751
3852@pytest .mark .parametrize (
3953 "blobs_per_tx" ,
40- [
41- (Spec .CANCUN_MAX_BLOBS_PER_BLOCK + 1 ,),
42- (Spec .CANCUN_MAX_BLOBS_PER_BLOCK + 2 ,),
43- (Spec .CANCUN_MAX_BLOBS_PER_BLOCK + 3 ,),
44- ],
54+ [(i ,) for i in range (64 , 1024 , 64 )],
4555)
4656@pytest .mark .valid_from ("Prague" )
47- def test_blobs_above_cancun_max (
57+ def test_large_number_of_blobs_in_tx (
4858 state_test : StateTestFiller ,
4959 pre : Alloc ,
5060 state_env : Environment ,
5161 txs : list [Transaction ],
5262):
5363 """
54- Test that transactions with blob counts above the Cancun maximum are accepted in Prague .
64+ Test transactions with a large number of blobs (64 to 1024 blobs) .
5565 """
5666 state_test (
5767 pre = pre ,
@@ -61,23 +71,52 @@ def test_blobs_above_cancun_max(
6171 )
6272
6373
74+ def invalid_cancun_blob_combinations () -> List [Tuple [int , ...]]:
75+ """
76+ Returns all possible invalid Cancun blob tx combinations for a given block that use up to
77+ `CANCUN_MAX_BLOBS_PER_BLOCK+1` blobs. These combinations are valid from Prague.
78+ """
79+ all = [
80+ seq
81+ for i in range (
82+ Spec .CANCUN_MAX_BLOBS_PER_BLOCK + 1 , 0 , - 1
83+ ) # We can have from 1 to at most MAX_BLOBS_PER_BLOCK blobs per block
84+ for seq in itertools .combinations_with_replacement (
85+ range (1 , Spec .CANCUN_MAX_BLOBS_PER_BLOCK + 2 ), i
86+ ) # We iterate through all possible combinations
87+ if sum (seq ) == Spec .CANCUN_MAX_BLOBS_PER_BLOCK + 1
88+ ]
89+ # We also add the reversed version of each combination, only if it's not
90+ # already in the list. E.g. (4, 1) is added from (1, 4) but not
91+ # (1, 1, 1, 1, 1) because its reversed version is identical.
92+ all += [tuple (reversed (x )) for x in all if tuple (reversed (x )) not in all ]
93+ return all
94+
95+
6496@pytest .mark .parametrize (
6597 "blobs_per_tx" ,
66- [( i ,) for i in range ( 64 , 1024 , 64 )] ,
98+ invalid_cancun_blob_combinations () ,
6799)
68100@pytest .mark .valid_from ("Prague" )
69- def test_large_number_of_blobs_in_tx (
70- state_test : StateTestFiller ,
101+ def test_invalid_cancun_block_blob_count (
102+ blockchain_test : BlockchainTestFiller ,
71103 pre : Alloc ,
72- state_env : Environment ,
73- txs : list [ Transaction ] ,
104+ env : Environment ,
105+ block : Block ,
74106):
75107 """
76- Test transactions with a large number of blobs (64 to 1024 blobs).
108+ Tests all invalid blob combinations for the Cancun fork in a single block,
109+ where the sum of all blobs in a block is `CANCUN_MAX_BLOBS_PER_BLOCK + 1`.
110+
111+ This is a copy of the invalid test from:
112+ `tests/cancun/eip4844_blobs/test_blob_txs.py:test_invalid_block_blob_count`.
113+
114+ In Cancun, these blocks are invalid but in Prague they are valid.
77115 """
78- state_test (
116+ blockchain_test (
79117 pre = pre ,
80118 post = {},
81- tx = txs [0 ],
82- env = state_env ,
119+ blocks = [block ],
120+ genesis_environment = env ,
121+ header_verify = block .header_verify ,
83122 )
0 commit comments