Skip to content

Commit 6cf066e

Browse files
authored
fix(test): fix eip-7918 reserve activation addition to eip-4844 test_excess_blob_gas_fork_transition.py (#2059)
* fix(test): Change excess_blob_gas to header_verify to catch the issue * fix(tests): Fix tests/cancun/eip4844_blobs/test_excess_blob_gas_fork_transition.py to guarantee base fee in blocks
1 parent 510e3b8 commit 6cf066e

File tree

1 file changed

+68
-17
lines changed

1 file changed

+68
-17
lines changed

tests/cancun/eip4844_blobs/test_excess_blob_gas_fork_transition.py

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
Transaction,
2525
add_kzg_version,
2626
)
27+
from ethereum_test_tools import Opcodes as Op
2728

2829
from .spec import Spec, SpecHelpers, ref_spec_4844
2930

@@ -32,11 +33,25 @@
3233

3334
# Timestamp of the fork
3435
FORK_TIMESTAMP = 15_000
36+
BASE_FEE_MAX_CHANGE_DENOMINATOR = 8
3537

3638

3739
@pytest.fixture
38-
def env() -> Environment: # noqa: D103
39-
return Environment()
40+
def block_gas_limit(fork: Fork) -> int: # noqa: D103
41+
gas_limit = int(Environment().gas_limit)
42+
tx_gas_limit_cap = fork.transaction_gas_limit_cap()
43+
if tx_gas_limit_cap is not None:
44+
# Below transaction gas limit cap to reach gas limit easily
45+
gas_limit = min(gas_limit, tx_gas_limit_cap * 2)
46+
return gas_limit
47+
48+
49+
@pytest.fixture
50+
def genesis_environment(block_gas_limit: int, block_base_fee_per_gas: int) -> Environment: # noqa: D103
51+
return Environment(
52+
base_fee_per_gas=(block_base_fee_per_gas * BASE_FEE_MAX_CHANGE_DENOMINATOR) // 7,
53+
gas_limit=block_gas_limit,
54+
)
4055

4156

4257
@pytest.fixture
@@ -57,16 +72,33 @@ def post_fork_blobs_per_block(fork: Fork) -> int:
5772
def pre_fork_blocks(
5873
pre_fork_blobs_per_block: int,
5974
destination_account: Address,
75+
gas_spender_account: Address,
6076
sender: EOA,
6177
fork: Fork,
78+
block_base_fee_per_gas: int,
79+
block_gas_limit: int,
6280
) -> List[Block]:
6381
"""Generate blocks to reach the fork."""
6482
blocks = []
65-
nonce = 0
6683

6784
for t in range(999, FORK_TIMESTAMP, 1_000):
85+
remaining_gas = block_gas_limit // 2
6886
if pre_fork_blobs_per_block == 0:
69-
blocks.append(Block(txs=[], timestamp=t))
87+
blocks.append(
88+
Block(
89+
txs=[
90+
Transaction(
91+
to=gas_spender_account,
92+
value=0,
93+
gas_limit=remaining_gas,
94+
max_fee_per_gas=1_000_000,
95+
max_priority_fee_per_gas=10,
96+
sender=sender,
97+
)
98+
],
99+
timestamp=t,
100+
)
101+
)
70102
continue
71103

72104
# Split into multi txs for forks where max per tx < max per block
@@ -77,12 +109,13 @@ def pre_fork_blocks(
77109

78110
while remaining_blobs > 0:
79111
tx_blobs = min(remaining_blobs, max_blobs_per_tx)
112+
blob_tx_gas_limit = 21_000
80113
txs.append(
81114
Transaction(
82115
ty=Spec.BLOB_TX_TYPE,
83116
to=destination_account,
84117
value=1,
85-
gas_limit=3_000_000,
118+
gas_limit=blob_tx_gas_limit,
86119
max_fee_per_gas=1_000_000,
87120
max_priority_fee_per_gas=10,
88121
max_fee_per_blob_gas=100,
@@ -92,14 +125,25 @@ def pre_fork_blocks(
92125
Spec.BLOB_COMMITMENT_VERSION_KZG,
93126
),
94127
sender=sender,
95-
nonce=nonce,
96128
)
97129
)
98-
nonce += 1
130+
remaining_gas -= blob_tx_gas_limit
99131
blob_index += tx_blobs
100132
remaining_blobs -= tx_blobs
101-
102-
blocks.append(Block(txs=txs, timestamp=t))
133+
txs.append(
134+
Transaction(
135+
to=gas_spender_account,
136+
value=0,
137+
gas_limit=remaining_gas,
138+
max_fee_per_gas=1_000_000,
139+
max_priority_fee_per_gas=10,
140+
sender=sender,
141+
)
142+
)
143+
block = Block(
144+
txs=txs, timestamp=t, header_verify=Header(base_fee_per_gas=block_base_fee_per_gas)
145+
)
146+
blocks.append(block)
103147
return blocks
104148

105149

@@ -137,6 +181,12 @@ def destination_account(pre: Alloc) -> Address: # noqa: D103
137181
return pre.fund_eoa(amount=0)
138182

139183

184+
@pytest.fixture
185+
def gas_spender_account(pre: Alloc) -> Address: # noqa: D103
186+
# Account that when called consumes the entirety of the transaction's gas
187+
return pre.deploy_contract(code=Op.INVALID)
188+
189+
140190
@pytest.fixture
141191
def fork_block_excess_blob_gas(
142192
fork: Fork,
@@ -167,15 +217,16 @@ def post_fork_blocks(
167217
):
168218
"""Generate blocks after the fork."""
169219
blocks = []
170-
nonce = sum(len(block.txs) for block in pre_fork_blocks)
171220

172221
for i in range(post_fork_block_count):
173222
if post_fork_blobs_per_block == 0:
174223
if i == 0:
175224
blocks.append(
176225
Block(
177226
txs=[],
178-
excess_blob_gas=fork_block_excess_blob_gas,
227+
header_verify=Header(
228+
excess_blob_gas=fork_block_excess_blob_gas,
229+
),
179230
)
180231
)
181232
else:
@@ -194,7 +245,7 @@ def post_fork_blocks(
194245
ty=Spec.BLOB_TX_TYPE,
195246
to=destination_account,
196247
value=1,
197-
gas_limit=3_000_000,
248+
gas_limit=100_000,
198249
max_fee_per_gas=1_000_000,
199250
max_priority_fee_per_gas=10,
200251
max_fee_per_blob_gas=100,
@@ -203,18 +254,18 @@ def post_fork_blocks(
203254
Spec.BLOB_COMMITMENT_VERSION_KZG,
204255
),
205256
sender=sender,
206-
nonce=nonce,
207257
)
208258
)
209-
nonce += 1
210259
blob_index += tx_blobs
211260
remaining_blobs -= tx_blobs
212261

213262
if i == 0:
214263
blocks.append(
215264
Block(
216265
txs=txs,
217-
excess_blob_gas=fork_block_excess_blob_gas,
266+
header_verify=Header(
267+
excess_blob_gas=fork_block_excess_blob_gas,
268+
),
218269
)
219270
)
220271
else:
@@ -438,7 +489,7 @@ def test_fork_transition_excess_blob_gas_at_blob_genesis(
438489
@pytest.mark.parametrize("block_base_fee_per_gas", [7, 16, 23])
439490
def test_fork_transition_excess_blob_gas_post_blob_genesis(
440491
blockchain_test: BlockchainTestFiller,
441-
env: Environment,
492+
genesis_environment: Environment,
442493
pre: Alloc,
443494
pre_fork_blocks: List[Block],
444495
post_fork_blocks: List[Block],
@@ -449,5 +500,5 @@ def test_fork_transition_excess_blob_gas_post_blob_genesis(
449500
pre=pre,
450501
post=post,
451502
blocks=pre_fork_blocks + post_fork_blocks,
452-
genesis_environment=env,
503+
genesis_environment=genesis_environment,
453504
)

0 commit comments

Comments
 (0)