Skip to content

Commit 0288797

Browse files
committed
refactor(all): update lang from 'shared pre-alloc' to 'pre-allocation groups' 1/2
Terminology: - 'shared pre-allocation' → 'pre-allocation groups' - 'shared pre-state' → 'pre-allocation groups' Flags: - `--generate-shared-pre` -> `--generate-grouped-pre-allocs` - `--use-shared-pre` -> `--use-grouped-pre-allocs` Method names updated: - `update_shared_pre_state` → `update_pre_alloc_groups` - `compute_shared_pre_alloc_hash` → `compute_pre_alloc_group_hash` - `shared_pre_alloc_folder_path` → `grouped_pre_allocs_folder_path`
1 parent 3537b50 commit 0288797

File tree

8 files changed

+140
-134
lines changed

8 files changed

+140
-134
lines changed

docs/running_tests/test_formats/blockchain_test_engine_x.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ Each file in the `pre_alloc` folder corresponds to a pre-allocation hash to shar
5050

5151
For each [`BlockchainTestEngineXFixture`](#BlockchainTestEngineXFixture) test object in the JSON fixture file, perform the following steps:
5252

53-
1. **Load Shared Pre-Allocation**:
53+
1. **Load Pre-Allocation Group**:
5454
- Read the appropriate file from the `pre_alloc` folder in the same directory
55-
- Locate the shared state group using [`preHash`](#-prehash-string)
56-
- Extract the `pre` allocation and `environment` from the shared group
55+
- Locate the pre-allocation group using [`preHash`](#-prehash-string)
56+
- Extract the `pre` allocation and `environment` from the group
5757

5858
2. **Initialize Client**:
5959
- Use [`network`](#-network-fork) to configure the execution fork schedule
60-
- Use the shared `pre` allocation as the starting state
61-
- Use the shared `environment` as the execution context
60+
- Use the pre-allocation group's `pre` allocation as the starting state
61+
- Use the pre-allocation group's `environment` as the execution context
6262
- Use [`genesisBlockHeader`](#-genesisblockheader-fixtureheader) as the genesis block header
6363

6464
3. **Execute Engine API Sequence**:

src/cli/pytest_commands/fill.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ def __init__(self):
2323

2424
def create_executions(self, pytest_args: List[str]) -> List[PytestExecution]:
2525
"""
26-
Create execution plan that supports two-phase shared pre-state generation.
26+
Create execution plan that supports two-phase pre-allocation group generation.
2727
2828
Returns single execution for normal filling, or two-phase execution
29-
when --gen-shared-pre is specified.
29+
when --generate-grouped-pre-allocs is specified.
3030
"""
3131
processed_args = self.process_arguments(pytest_args)
3232

3333
# Check if we need two-phase execution
34-
if "--generate-shared-pre" in processed_args:
34+
if "--generate-grouped-pre-allocs" in processed_args:
3535
return self._create_two_phase_executions(processed_args)
36-
elif "--use-shared-pre" in processed_args:
37-
# Only phase 2: using existing shared pre-allocation state
38-
return self._create_single_phase_with_shared_alloc(processed_args)
36+
elif "--use-grouped-pre-allocs" in processed_args:
37+
# Only phase 2: using existing pre-allocation groups
38+
return self._create_single_phase_with_grouped_pre_allocs(processed_args)
3939
else:
4040
# Normal single-phase execution
4141
return [
@@ -46,8 +46,8 @@ def create_executions(self, pytest_args: List[str]) -> List[PytestExecution]:
4646
]
4747

4848
def _create_two_phase_executions(self, args: List[str]) -> List[PytestExecution]:
49-
"""Create two-phase execution: shared allocation generation + fixture filling."""
50-
# Phase 1: Shared allocation generation (clean and minimal output)
49+
"""Create two-phase execution: pre-allocation group generation + fixture filling."""
50+
# Phase 1: Pre-allocation group generation (clean and minimal output)
5151
phase1_args = self._create_phase1_args(args)
5252

5353
# Phase 2: Main fixture generation (full user options)
@@ -57,7 +57,7 @@ def _create_two_phase_executions(self, args: List[str]) -> List[PytestExecution]
5757
PytestExecution(
5858
config_file=self.config_file,
5959
args=phase1_args,
60-
description="generating shared pre-allocation state",
60+
description="generating pre-allocation groups",
6161
),
6262
PytestExecution(
6363
config_file=self.config_file,
@@ -66,8 +66,10 @@ def _create_two_phase_executions(self, args: List[str]) -> List[PytestExecution]
6666
),
6767
]
6868

69-
def _create_single_phase_with_shared_alloc(self, args: List[str]) -> List[PytestExecution]:
70-
"""Create single execution using existing shared pre-allocation state."""
69+
def _create_single_phase_with_grouped_pre_allocs(
70+
self, args: List[str]
71+
) -> List[PytestExecution]:
72+
"""Create single execution using existing pre-allocation groups."""
7173
return [
7274
PytestExecution(
7375
config_file=self.config_file,
@@ -76,24 +78,24 @@ def _create_single_phase_with_shared_alloc(self, args: List[str]) -> List[Pytest
7678
]
7779

7880
def _create_phase1_args(self, args: List[str]) -> List[str]:
79-
"""Create arguments for phase 1 (shared allocation generation)."""
81+
"""Create arguments for phase 1 (pre-allocation group generation)."""
8082
# Start with all args, then remove what we don't want for phase 1
8183
filtered_args = self._remove_unwanted_phase1_args(args)
8284

8385
# Add required phase 1 flags (with quiet output by default)
8486
phase1_args = [
85-
"--generate-shared-pre",
87+
"--generate-grouped-pre-allocs",
8688
"-qq", # Quiet pytest output by default (user -v/-vv/-vvv can override)
8789
] + filtered_args
8890

8991
return phase1_args
9092

9193
def _create_phase2_args(self, args: List[str]) -> List[str]:
9294
"""Create arguments for phase 2 (fixture filling)."""
93-
# Remove --generate-shared-pre and --clean, then add --use-shared-pre
94-
phase2_args = self._remove_generate_shared_pre_flag(args)
95+
# Remove --generate-grouped-pre-allocs and --clean, then add --use-grouped-pre-allocs
96+
phase2_args = self._remove_generate_grouped_pre_allocs_flag(args)
9597
phase2_args = self._remove_clean_flag(phase2_args)
96-
phase2_args = self._add_use_shared_pre_flag(phase2_args)
98+
phase2_args = self._add_use_grouped_pre_allocs_flag(phase2_args)
9799
return phase2_args
98100

99101
def _remove_unwanted_phase1_args(self, args: List[str]) -> List[str]:
@@ -106,9 +108,9 @@ def _remove_unwanted_phase1_args(self, args: List[str]) -> List[str]:
106108
"--quiet",
107109
"-qq",
108110
"--tb",
109-
# Shared allocation flags (we'll add our own)
110-
"--generate-shared-pre",
111-
"--use-shared-pre",
111+
# Pre-allocation group flags (we'll add our own)
112+
"--generate-grouped-pre-allocs",
113+
"--use-grouped-pre-allocs",
112114
}
113115

114116
filtered_args = []
@@ -132,17 +134,17 @@ def _remove_unwanted_phase1_args(self, args: List[str]) -> List[str]:
132134

133135
return filtered_args
134136

135-
def _remove_generate_shared_pre_flag(self, args: List[str]) -> List[str]:
136-
"""Remove --generate-shared-pre flag from argument list."""
137-
return [arg for arg in args if arg != "--generate-shared-pre"]
137+
def _remove_generate_grouped_pre_allocs_flag(self, args: List[str]) -> List[str]:
138+
"""Remove --generate-grouped-pre-allocs flag from argument list."""
139+
return [arg for arg in args if arg != "--generate-grouped-pre-allocs"]
138140

139141
def _remove_clean_flag(self, args: List[str]) -> List[str]:
140142
"""Remove --clean flag from argument list."""
141143
return [arg for arg in args if arg != "--clean"]
142144

143-
def _add_use_shared_pre_flag(self, args: List[str]) -> List[str]:
144-
"""Add --use-shared-pre flag to argument list."""
145-
return args + ["--use-shared-pre"]
145+
def _add_use_grouped_pre_allocs_flag(self, args: List[str]) -> List[str]:
146+
"""Add --use-grouped-pre-allocs flag to argument list."""
147+
return args + ["--use-grouped-pre-allocs"]
146148

147149

148150
class PhilCommand(FillCommand):

src/cli/show_pre_alloc_group_stats.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Script to display statistics about shared pre-allocation groups."""
1+
"""Script to display statistics about pre-allocation groups."""
22

33
from collections import defaultdict
44
from pathlib import Path
@@ -393,7 +393,7 @@ def display_stats(stats: Dict, console: Console, verbose: int = 0):
393393
console.print("\n[bold yellow]Test Functions Split Across Multiple Groups[/bold yellow]")
394394
console.print(
395395
"[dim]These test functions create multiple size-1 groups (due to different "
396-
"forks/parameters), preventing shared pre-allocation optimization:[/dim]",
396+
"forks/parameters), preventing pre-allocation group optimization:[/dim]",
397397
highlight=False,
398398
)
399399

@@ -462,19 +462,19 @@ def display_stats(stats: Dict, console: Console, verbose: int = 0):
462462
)
463463
def main(pre_alloc_folder: Path, verbose: int):
464464
"""
465-
Display statistics about shared pre-allocation groups.
465+
Display statistics about pre-allocation groups.
466466
467467
This script analyzes a pre_alloc folder generated by the test framework's
468-
shared pre-allocation optimization feature and displays:
468+
pre-allocation group optimization feature and displays:
469469
470470
- Total number of groups, tests, and accounts
471471
- Number of tests and accounts per group (tabulated)
472472
- Number of groups and tests per fork (tabulated)
473473
- Number of groups and tests per test module (tabulated)
474474
475475
The pre_alloc file is generated when running tests with the
476-
--generate-shared-pre and --use-shared-pre flags to optimize
477-
test execution by sharing pre-allocation state across tests.
476+
--generate-grouped-pre-allocs and --use-grouped-pre-allocs flags to optimize
477+
test execution by grouping tests with identical pre-allocation state.
478478
479479
"""
480480
console = Console()

src/ethereum_test_fixtures/shared_alloc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Shared pre-allocation models for test fixture generation."""
1+
"""Pre-allocation group models for test fixture generation."""
22

33
from pathlib import Path
44
from typing import Any, Dict, List
@@ -15,10 +15,10 @@
1515

1616
class SharedPreStateGroup(CamelModel):
1717
"""
18-
Shared pre-state group for tests with identical Environment and fork values.
18+
Pre-allocation group for tests with identical Environment and fork values.
1919
2020
Groups tests by a hash of their fixture Environment and fork to enable
21-
shared pre-allocation optimization.
21+
pre-allocation group optimization.
2222
"""
2323

2424
model_config = {"populate_by_name": True} # Allow both field names and aliases

src/ethereum_test_specs/base.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,20 @@ def get_genesis_environment(self, fork: Fork) -> Environment:
218218
"pre-allocation"
219219
)
220220

221-
def update_shared_pre_state(
222-
self, shared_pre_state: SharedPreState, fork: Fork, test_id: str
221+
def update_pre_alloc_groups(
222+
self, pre_alloc_groups: SharedPreState, fork: Fork, test_id: str
223223
) -> SharedPreState:
224-
"""Create or update the shared pre-state group with the pre from the current spec."""
224+
"""Create or update the pre-allocation group with the pre from the current spec."""
225225
if not hasattr(self, "pre"):
226226
raise AttributeError(
227-
f"{self.__class__.__name__} does not have a 'pre' field. Shared pre-allocation "
228-
"is only supported for test types that define pre-allocation."
227+
f"{self.__class__.__name__} does not have a 'pre' field. Pre-allocation groups "
228+
"are only supported for test types that define pre-allocation."
229229
)
230-
pre_alloc_hash = self.compute_shared_pre_alloc_hash(fork=fork)
230+
pre_alloc_hash = self.compute_pre_alloc_group_hash(fork=fork)
231231

232-
if pre_alloc_hash in shared_pre_state:
232+
if pre_alloc_hash in pre_alloc_groups:
233233
# Update existing group - just merge pre-allocations
234-
group = shared_pre_state[pre_alloc_hash]
234+
group = pre_alloc_groups[pre_alloc_hash]
235235
group.pre = Alloc.merge(
236236
group.pre,
237237
self.pre,
@@ -241,7 +241,7 @@ def update_shared_pre_state(
241241
group.test_ids.append(str(test_id))
242242
group.test_count = len(group.test_ids)
243243
group.pre_account_count = len(group.pre.root)
244-
shared_pre_state[pre_alloc_hash] = group
244+
pre_alloc_groups[pre_alloc_hash] = group
245245
else:
246246
# Create new group - use Environment instead of expensive genesis generation
247247
group = SharedPreStateGroup(
@@ -252,11 +252,11 @@ def update_shared_pre_state(
252252
environment=self.get_genesis_environment(fork),
253253
pre=self.pre,
254254
)
255-
shared_pre_state[pre_alloc_hash] = group
256-
return shared_pre_state
255+
pre_alloc_groups[pre_alloc_hash] = group
256+
return pre_alloc_groups
257257

258-
def compute_shared_pre_alloc_hash(self, fork: Fork) -> str:
259-
"""Hash (fork, env) in order to group tests by shared genesis config."""
258+
def compute_pre_alloc_group_hash(self, fork: Fork) -> str:
259+
"""Hash (fork, env) in order to group tests by genesis config."""
260260
if not hasattr(self, "pre"):
261261
raise AttributeError(
262262
f"{self.__class__.__name__} does not have a 'pre' field. Shared pre-allocation "

0 commit comments

Comments
 (0)