-
Notifications
You must be signed in to change notification settings - Fork 182
feat(fill, execute): track execution & setup testing phase #2157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LouisTsai-Csie
wants to merge
5
commits into
ethereum:main
Choose a base branch
from
LouisTsai-Csie:feat/add-phase-manager
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+456
−8
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
42a1e8c
feat(tests): add phase manager to track testing phase
LouisTsai-Csie 2e8ee6a
refactor: update test phase manager instance model
LouisTsai-Csie 2dab80d
fix: resolve linting issue
LouisTsai-Csie 9f85ffc
test: add case for TestPhaseManager functionality
LouisTsai-Csie b7faeef
tests: isolated phase manager behaviour
LouisTsai-Csie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
"""Test phase management for Ethereum tests.""" | ||
|
||
from contextlib import contextmanager | ||
from enum import Enum | ||
from typing import Any, Iterator, List, Optional | ||
|
||
from pydantic import GetCoreSchemaHandler | ||
from pydantic_core.core_schema import ( | ||
PlainValidatorFunctionSchema, | ||
no_info_plain_validator_function, | ||
) | ||
|
||
|
||
class TestPhase(Enum): | ||
"""Test phase for state and blockchain tests.""" | ||
|
||
SETUP = "setup" | ||
EXECUTION = "execution" | ||
|
||
|
||
class TestPhaseManager: | ||
""" | ||
Manages test phases and collects transactions and blocks by phase. | ||
This class provides a mechanism for "setup" and "execution" phases, | ||
Only supports "setup" and "execution" phases now. | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
"""Initialize TestPhaseManager with empty transactions and blocks.""" | ||
self.setup_transactions: List = [] | ||
self.setup_blocks: List = [] | ||
self.execution_transactions: List = [] | ||
self.execution_blocks: List = [] | ||
self._current_phase: Optional[TestPhase] = TestPhase.EXECUTION | ||
|
||
@contextmanager | ||
def setup(self) -> Iterator["TestPhaseManager"]: | ||
"""Context manager for the setup phase of a benchmark test.""" | ||
old_phase = self._current_phase | ||
self._current_phase = TestPhase.SETUP | ||
try: | ||
yield self | ||
finally: | ||
self._current_phase = old_phase | ||
|
||
@contextmanager | ||
def execution(self) -> Iterator["TestPhaseManager"]: | ||
"""Context manager for the execution phase of a test.""" | ||
old_phase = self._current_phase | ||
self._current_phase = TestPhase.EXECUTION | ||
try: | ||
yield self | ||
finally: | ||
self._current_phase = old_phase | ||
|
||
def add_transaction(self, tx) -> None: | ||
"""Add a transaction to the current phase.""" | ||
current_phase = self._current_phase | ||
tx.test_phase = current_phase | ||
|
||
if current_phase == TestPhase.EXECUTION: | ||
self.execution_transactions.append(tx) | ||
else: | ||
self.setup_transactions.append(tx) | ||
|
||
def add_block(self, block) -> None: | ||
"""Add a block to the current phase.""" | ||
current_phase = self._current_phase | ||
for tx in block.txs: | ||
tx.test_phase = current_phase | ||
|
||
if current_phase == TestPhase.EXECUTION: | ||
self.execution_blocks.append(block) | ||
else: | ||
self.setup_blocks.append(block) | ||
|
||
def get_current_phase(self) -> Optional[TestPhase]: | ||
"""Get the current test phase.""" | ||
return self._current_phase | ||
|
||
@staticmethod | ||
def __get_pydantic_core_schema__( | ||
source_type: Any, handler: GetCoreSchemaHandler | ||
) -> PlainValidatorFunctionSchema: | ||
"""Pydantic schema for TestPhaseManager.""" | ||
|
||
def validate_test_phase_manager(value): | ||
"""Return the TestPhaseManager instance as-is.""" | ||
if isinstance(value, source_type): | ||
return value | ||
return source_type() | ||
|
||
return no_info_plain_validator_function( | ||
validate_test_phase_manager, | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Iiuc, we are now sourcing blocks from two places which can be really confusing.
Besides, if we are targeting to only tag transactions so
execute
can decide whether to send them or not depending on the current phase, then theBlock
class does not need to be modified, and the only thing we need to add is thetest_phase
field inTransaction
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see yeah, this is the kind of scope I was looking for. That makes sense.