-
Notifications
You must be signed in to change notification settings - Fork 72
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
feat(plugins): Features plug-in, EIP-7702 mode #781
Open
marioevz
wants to merge
5
commits into
main
Choose a base branch
from
features-plugin
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.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ac99d30
feat(plugins): features plug-in, EIP-7702 mode
marioevz 61fffe7
fix(plugins): tests
marioevz 834db33
fix(docs): Add documentation changes
marioevz 254ae7d
Apply suggestions from code review
marioevz 8b5558c
fix(plugins): Merge issue
marioevz 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 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 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,3 @@ | ||
# Features Plugin | ||
|
||
::: pytest_plugins.features |
This file contains 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 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 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 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 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,7 @@ | ||
""" | ||
Pytest plugin to enable feature-based modification during test filling/execution. | ||
""" | ||
|
||
from .features import Features | ||
|
||
__all__ = ["Features"] |
This file contains 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,84 @@ | ||
""" | ||
Enable feature-specific functionality on all tests during filling/execution. | ||
""" | ||
|
||
from enum import Flag, auto | ||
|
||
import pytest | ||
|
||
from ethereum_test_vm import EVMCodeType | ||
|
||
|
||
class Features(Flag): | ||
""" | ||
Enumerates the available features. | ||
|
||
Each feature can be passed to the parameter flag `--feature` as a (case-insensitive) string, | ||
and multiple features can be enabled by repeating the flag. | ||
""" | ||
|
||
NONE = 0 | ||
EIP_7702 = auto() | ||
""" | ||
Enables tests to be filled and executed in EIP-7702 mode, i.e. addresses returned by | ||
`pre.deploy_contract` is not the contract itself but an EOA account that delegates | ||
to the contract. | ||
""" | ||
EOF_V1 = auto() | ||
""" | ||
Enables tests to be filled and executed in EOF V1 mode, i.e. all test contracts deployed during | ||
tests are automatically wrapped in an EOF V1 container. | ||
""" | ||
|
||
def __str__(self): | ||
""" | ||
Returns the string representation of the feature. | ||
""" | ||
return self.name | ||
|
||
|
||
def pytest_addoption(parser: pytest.Parser): | ||
""" | ||
Adds command-line options to pytest. | ||
""" | ||
features_group = parser.getgroup( | ||
"features", "Arguments related to enabling specific testing of features" | ||
) | ||
|
||
features_group.addoption( | ||
"--feature", | ||
action="append", | ||
default=[], | ||
help="Enable a feature (may be specified multiple times, once per feature). " | ||
"Supported features: " + ", ".join(str(feature).lower() for feature in Features), | ||
) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def features(request): | ||
""" | ||
Returns the enabled features. | ||
""" | ||
features_str_list = request.config.getoption("feature") | ||
features = Features.NONE | ||
for feature_str in features_str_list: | ||
features |= Features[feature_str.upper()] | ||
return features | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def eip_7702_feature(features: Features) -> bool: | ||
""" | ||
Returns whether the EIP-7702 mode is enabled. | ||
""" | ||
return Features.EIP_7702 in features | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="session") | ||
def evm_code_type(features: Features) -> EVMCodeType | None: | ||
""" | ||
Returns the default EVM code type for all tests. | ||
""" | ||
if Features.EOF_V1 in features: | ||
return EVMCodeType.EOF_V1 | ||
return None |
This file contains 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 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 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
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.
Nice! Didn't know
Flag
. Love the example from the docs: https://docs.python.org/3/library/enum.html#enum.Flag