Skip to content

Commit ff6aca4

Browse files
refactor(benchmark): update starting fork from prague (#2139)
* fix: update starting fork for benchmark test * doc: update benchmark fork description * refactor: update benchmark test generation to use a default benchmark fork
1 parent e9045fc commit ff6aca4

File tree

7 files changed

+22
-47
lines changed

7 files changed

+22
-47
lines changed

docs/writing_tests/benchmarks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Benchmark tests aim to maximize the usage of a specific opcode, precompile, or o
44

55
To fill a benchmark test, in addition to the usual test flags, you must include the `-m benchmark` flag. This is necessary because benchmark tests are ignored by default; they must be manually selected via the `benchmark` pytest marker (="tag"). This marker is applied to all tests under `./tests/benchmark/` automatically by the framework.
66

7+
**Note:** Benchmark tests are now only available starting from the `Prague` fork. Tests targeting earlier forks (`Cancun` or prior) are not supported in benchmark mode.
8+
79
## Setting the Gas Limit for Benchmarking
810

911
To consume the full benchmark gas limit, use the `gas_benchmark_value` fixture as the gas limit:

tests/benchmark/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@
44

55
import pytest
66

7+
DEFAULT_BENCHMARK_FORK = "Prague"
8+
9+
10+
def pytest_generate_tests(metafunc):
11+
"""Modify test generation to enforce default benchmark fork for benchmark tests."""
12+
benchmark_dir = Path(__file__).parent
13+
test_file_path = Path(metafunc.definition.fspath)
14+
15+
# Check if this test is in the benchmark directory
16+
is_in_benchmark_dir = benchmark_dir in test_file_path.parents
17+
18+
if is_in_benchmark_dir:
19+
# Add benchmark marker if no valid_from marker exists
20+
existing_markers = list(metafunc.definition.iter_markers())
21+
has_valid_from = any(marker.name == "valid_from" for marker in existing_markers)
22+
23+
if not has_valid_from:
24+
benchmark_marker = pytest.mark.valid_from(DEFAULT_BENCHMARK_FORK)
25+
metafunc.definition.add_marker(benchmark_marker)
26+
727

828
def pytest_collection_modifyitems(config, items):
929
"""Add the `benchmark` marker to all tests under `./tests/benchmark`."""

tests/benchmark/test_worst_blocks.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def ether_transfer_case(
105105
return senders, receivers
106106

107107

108-
@pytest.mark.valid_from("Cancun")
109108
@pytest.mark.parametrize(
110109
"case_id",
111110
["a_to_a", "a_to_b", "diff_acc_to_b", "a_to_diff_acc", "diff_acc_to_diff_acc"],
@@ -174,7 +173,6 @@ def total_cost_standard_per_token():
174173
return 4
175174

176175

177-
@pytest.mark.valid_from("Prague")
178176
@pytest.mark.parametrize("zero_byte", [True, False])
179177
def test_block_full_data(
180178
state_test: StateTestFiller,
@@ -231,7 +229,6 @@ def test_block_full_data(
231229
)
232230

233231

234-
@pytest.mark.valid_from("Prague")
235232
def test_block_full_access_list_and_data(
236233
state_test: StateTestFiller,
237234
pre: Alloc,

tests/benchmark/test_worst_bytecode.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
Op.EXTCODECOPY,
4848
],
4949
)
50-
@pytest.mark.valid_from("Cancun")
5150
def test_worst_bytecode_single_opcode(
5251
blockchain_test: BlockchainTestFiller,
5352
pre: Alloc,
@@ -233,7 +232,6 @@ def test_worst_bytecode_single_opcode(
233232
)
234233

235234

236-
@pytest.mark.valid_from("Cancun")
237235
@pytest.mark.parametrize(
238236
"pattern",
239237
[
@@ -324,7 +322,6 @@ def test_worst_initcode_jumpdest_analysis(
324322
)
325323

326324

327-
@pytest.mark.valid_from("Cancun")
328325
@pytest.mark.parametrize(
329326
"opcode",
330327
[
@@ -432,7 +429,6 @@ def test_worst_create(
432429
)
433430

434431

435-
@pytest.mark.valid_from("Cancun")
436432
@pytest.mark.parametrize(
437433
"opcode",
438434
[

tests/benchmark/test_worst_compute.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def make_dup(index: int) -> Opcode:
6262
return Opcode(0x80 + index, pushed_stack_items=1, min_stack_height=index + 1)
6363

6464

65-
@pytest.mark.valid_from("Cancun")
6665
@pytest.mark.parametrize(
6766
"opcode",
6867
[
@@ -112,7 +111,6 @@ def test_worst_zero_param(
112111
)
113112

114113

115-
@pytest.mark.valid_from("Cancun")
116114
@pytest.mark.parametrize("calldata_length", [0, 1_000, 10_000])
117115
def test_worst_calldatasize(
118116
state_test: StateTestFiller,
@@ -145,7 +143,6 @@ def test_worst_calldatasize(
145143
)
146144

147145

148-
@pytest.mark.valid_from("Cancun")
149146
@pytest.mark.parametrize("non_zero_value", [True, False])
150147
@pytest.mark.parametrize("from_origin", [True, False])
151148
def test_worst_callvalue(
@@ -205,7 +202,6 @@ class ReturnDataStyle(Enum):
205202
IDENTITY = auto()
206203

207204

208-
@pytest.mark.valid_from("Cancun")
209205
@pytest.mark.parametrize(
210206
"return_data_style",
211207
[
@@ -267,7 +263,6 @@ def test_worst_returndatasize_nonzero(
267263
)
268264

269265

270-
@pytest.mark.valid_from("Cancun")
271266
def test_worst_returndatasize_zero(
272267
state_test: StateTestFiller,
273268
pre: Alloc,
@@ -299,7 +294,6 @@ def test_worst_returndatasize_zero(
299294
)
300295

301296

302-
@pytest.mark.valid_from("Cancun")
303297
@pytest.mark.parametrize("mem_size", [0, 1, 1_000, 100_000, 1_000_000])
304298
def test_worst_msize(
305299
state_test: StateTestFiller,
@@ -339,7 +333,6 @@ def test_worst_msize(
339333
)
340334

341335

342-
@pytest.mark.valid_from("Cancun")
343336
def test_worst_keccak(
344337
state_test: StateTestFiller,
345338
pre: Alloc,
@@ -414,7 +407,6 @@ def test_worst_keccak(
414407
)
415408

416409

417-
@pytest.mark.valid_from("Cancun")
418410
@pytest.mark.parametrize(
419411
"address,static_cost,per_word_dynamic_cost,bytes_per_unit_of_work",
420412
[
@@ -492,7 +484,6 @@ def test_worst_precompile_only_data_input(
492484
)
493485

494486

495-
@pytest.mark.valid_from("Cancun")
496487
@pytest.mark.parametrize(
497488
["mod_exp_input"],
498489
[
@@ -1299,7 +1290,6 @@ def test_worst_modexp(
12991290
)
13001291

13011292

1302-
@pytest.mark.valid_from("Cancun")
13031293
@pytest.mark.parametrize(
13041294
"precompile_address,parameters",
13051295
[
@@ -1748,8 +1738,6 @@ def test_worst_precompile_fixed_cost(
17481738
)
17491739

17501740

1751-
@pytest.mark.valid_from("Cancun")
1752-
@pytest.mark.slow
17531741
def test_worst_jumps(
17541742
state_test: StateTestFiller,
17551743
pre: Alloc,
@@ -1772,7 +1760,6 @@ def test_worst_jumps(
17721760
)
17731761

17741762

1775-
@pytest.mark.valid_from("Cancun")
17761763
def test_worst_jumpi_fallthrough(
17771764
state_test: StateTestFiller,
17781765
pre: Alloc,
@@ -1809,7 +1796,6 @@ def jumpi_seq():
18091796
)
18101797

18111798

1812-
@pytest.mark.valid_from("Cancun")
18131799
def test_worst_jumpis(
18141800
state_test: StateTestFiller,
18151801
pre: Alloc,
@@ -1832,7 +1818,6 @@ def test_worst_jumpis(
18321818
)
18331819

18341820

1835-
@pytest.mark.valid_from("Cancun")
18361821
@pytest.mark.slow
18371822
def test_worst_jumpdests(
18381823
state_test: StateTestFiller,
@@ -1868,7 +1853,6 @@ def test_worst_jumpdests(
18681853
)
18691854

18701855

1871-
@pytest.mark.valid_from("Cancun")
18721856
@pytest.mark.parametrize(
18731857
"opcode,opcode_args",
18741858
[
@@ -2043,7 +2027,6 @@ def test_worst_binop_simple(
20432027
)
20442028

20452029

2046-
@pytest.mark.valid_from("Cancun")
20472030
@pytest.mark.parametrize("opcode", [Op.ISZERO, Op.NOT])
20482031
def test_worst_unop(
20492032
state_test: StateTestFiller,
@@ -2078,7 +2061,6 @@ def test_worst_unop(
20782061
)
20792062

20802063

2081-
@pytest.mark.valid_from("Cancun")
20822064
# `key_mut` indicates the key isn't fixed.
20832065
@pytest.mark.parametrize("key_mut", [True, False])
20842066
# `val_mut` indicates that at the end of each big-loop, the value of the target key changes.
@@ -2134,7 +2116,6 @@ def test_worst_tload(
21342116
)
21352117

21362118

2137-
@pytest.mark.valid_from("Cancun")
21382119
@pytest.mark.parametrize("key_mut", [True, False])
21392120
@pytest.mark.parametrize("dense_val_mut", [True, False])
21402121
def test_worst_tstore(
@@ -2177,7 +2158,6 @@ def test_worst_tstore(
21772158
)
21782159

21792160

2180-
@pytest.mark.valid_from("Cancun")
21812161
@pytest.mark.parametrize("shift_right", [Op.SHR, Op.SAR])
21822162
def test_worst_shifts(
21832163
state_test: StateTestFiller,
@@ -2261,7 +2241,6 @@ def select_shift_amount(shift_fn, v):
22612241
)
22622242

22632243

2264-
@pytest.mark.valid_from("Cancun")
22652244
@pytest.mark.parametrize(
22662245
"blob_index, blobs_present",
22672246
[
@@ -2325,7 +2304,6 @@ def test_worst_blobhash(
23252304
)
23262305

23272306

2328-
@pytest.mark.valid_from("Cancun")
23292307
@pytest.mark.parametrize("mod_bits", [255, 191, 127, 63])
23302308
@pytest.mark.parametrize("op", [Op.MOD, Op.SMOD])
23312309
def test_worst_mod(
@@ -2448,7 +2426,6 @@ def test_worst_mod(
24482426
)
24492427

24502428

2451-
@pytest.mark.valid_from("Cancun")
24522429
@pytest.mark.parametrize("opcode", [Op.MLOAD, Op.MSTORE, Op.MSTORE8])
24532430
@pytest.mark.parametrize("offset", [0, 1, 31])
24542431
@pytest.mark.parametrize("offset_initialized", [True, False])
@@ -2492,7 +2469,6 @@ def test_worst_memory_access(
24922469
)
24932470

24942471

2495-
@pytest.mark.valid_from("Cancun")
24962472
@pytest.mark.parametrize("mod_bits", [255, 191, 127, 63])
24972473
@pytest.mark.parametrize("op", [Op.ADDMOD, Op.MULMOD])
24982474
def test_worst_modarith(
@@ -2596,7 +2572,6 @@ def test_worst_modarith(
25962572
)
25972573

25982574

2599-
@pytest.mark.valid_from("Cancun")
26002575
def test_empty_block(
26012576
blockchain_test: BlockchainTestFiller,
26022577
pre: Alloc,
@@ -2610,7 +2585,6 @@ def test_empty_block(
26102585
)
26112586

26122587

2613-
@pytest.mark.valid_from("Cancun")
26142588
def test_amortized_bn128_pairings(
26152589
state_test: StateTestFiller,
26162590
pre: Alloc,

tests/benchmark/test_worst_memory.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class CallDataOrigin:
3030
CALL = 2
3131

3232

33-
@pytest.mark.valid_from("Cancun")
3433
@pytest.mark.parametrize(
3534
"origin",
3635
[
@@ -127,7 +126,6 @@ def test_worst_calldatacopy(
127126
)
128127

129128

130-
@pytest.mark.valid_from("Cancun")
131129
@pytest.mark.parametrize(
132130
"max_code_size_ratio",
133131
[
@@ -184,7 +182,6 @@ def test_worst_codecopy(
184182
)
185183

186184

187-
@pytest.mark.valid_from("Cancun")
188185
@pytest.mark.parametrize(
189186
"size",
190187
[
@@ -268,7 +265,6 @@ def test_worst_returndatacopy(
268265
)
269266

270267

271-
@pytest.mark.valid_from("Cancun")
272268
@pytest.mark.parametrize(
273269
"size",
274270
[

0 commit comments

Comments
 (0)