-
Notifications
You must be signed in to change notification settings - Fork 169
feat(tests): enhance eip7883 test coverage #1929
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
Merged
spencer-tb
merged 19 commits into
ethereum:main
from
LouisTsai-Csie:enhance-eip7823-coverage
Aug 22, 2025
+854
−103
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7ea5812
refactor(eip7883): update vector input structure
LouisTsai-Csie f528669
feat: add eip7702, gas usage and extra edge cases
LouisTsai-Csie 6d238bc
feat: add fork transition test
LouisTsai-Csie 78ec622
test: add extra invalid cases
LouisTsai-Csie 8a7d8a2
refactor(tests): Improve fixture and test descriptions for clarity
LouisTsai-Csie e746662
refactor(tests): add helper for invalid case
LouisTsai-Csie 9a0c4a6
feat: add invalud boundary test cases
LouisTsai-Csie 26a5ae5
chore: update boundary input case
LouisTsai-Csie e9e92ad
refactor(tests): simplify boundary modexp test cases
LouisTsai-Csie 834345d
fix(tests): update fork transition test
LouisTsai-Csie 8763580
feat(test): add gas formula egde cases
LouisTsai-Csie 81667a7
test: add extra casefor modexp invalid input
LouisTsai-Csie 12b6277
tests: port legacy modexp test
LouisTsai-Csie 7170c62
refactor: update vector and data types
LouisTsai-Csie ee91ce9
refactor: remove valid case from invalid scenario
LouisTsai-Csie 4ac264d
refactor: update result comparison method and test case
LouisTsai-Csie df29c1d
refactor: update comment
LouisTsai-Csie 7bd5794
refactor: update naming and new cases
LouisTsai-Csie 0a74dac
refactor: update valid fork configuration
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,58 @@ | ||
"""Helper functions for the EIP-7883 ModExp gas cost increase tests.""" | ||
|
||
import json | ||
import os | ||
from typing import Annotated, List | ||
|
||
from pydantic import BaseModel, Field, PlainValidator | ||
import pytest | ||
from pydantic import BaseModel, ConfigDict, Field, PlainValidator, RootModel, TypeAdapter | ||
from pydantic.alias_generators import to_pascal | ||
|
||
from ethereum_test_tools import Bytes | ||
|
||
from ...byzantium.eip198_modexp_precompile.helpers import ModExpInput | ||
|
||
|
||
def current_python_script_directory(*args: str) -> str: | ||
"""Get the current Python script directory.""" | ||
return os.path.join(os.path.dirname(os.path.realpath(__file__)), *args) | ||
|
||
|
||
class Vector(BaseModel): | ||
"""A vector for the ModExp gas cost increase tests.""" | ||
|
||
input: Annotated[ModExpInput, PlainValidator(ModExpInput.from_bytes)] = Field( | ||
modexp_input: Annotated[ModExpInput, PlainValidator(ModExpInput.from_bytes)] = Field( | ||
..., alias="Input" | ||
) | ||
expected: Bytes = Field(..., alias="Expected") | ||
modexp_expected: Bytes = Field(..., alias="Expected") | ||
name: str = Field(..., alias="Name") | ||
gas_old: int | None = Field(..., alias="GasOld") | ||
gas_new: int | None = Field(..., alias="GasNew") | ||
gas_old: int | None = Field(default=None, alias="GasOld") | ||
gas_new: int | None = Field(default=None, alias="GasNew") | ||
|
||
@staticmethod | ||
def from_json(vector_json: dict) -> "Vector": | ||
"""Create a Vector from a JSON dictionary.""" | ||
return Vector.model_validate(vector_json) | ||
model_config = ConfigDict(alias_generator=to_pascal) | ||
|
||
@staticmethod | ||
def from_file(filename: str) -> List["Vector"]: | ||
"""Create a list of Vectors from a file.""" | ||
with open(current_python_script_directory(filename), "r") as f: | ||
vectors_json = json.load(f) | ||
return [Vector.from_json(vector_json) for vector_json in vectors_json] | ||
def to_pytest_param(self): | ||
"""Convert the test vector to a tuple that can be used as a parameter in a pytest test.""" | ||
return pytest.param( | ||
self.modexp_input, self.modexp_expected, self.gas_old, self.gas_new, id=self.name | ||
) | ||
|
||
|
||
def current_python_script_directory(*args: str) -> str: | ||
"""Get the current Python script directory.""" | ||
return os.path.join(os.path.dirname(os.path.realpath(__file__)), *args) | ||
class VectorList(RootModel): | ||
"""A list of test vectors for the ModExp gas cost increase tests.""" | ||
|
||
root: List[Vector] | ||
|
||
|
||
VectorListAdapter = TypeAdapter(VectorList) | ||
|
||
|
||
def vectors_from_file(filename: str) -> List: | ||
"""Load test vectors from a file.""" | ||
with open( | ||
current_python_script_directory( | ||
"vector", | ||
filename, | ||
), | ||
"rb", | ||
) as f: | ||
return [v.to_pytest_param() for v in VectorListAdapter.validate_json(f.read()).root] |
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
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.
Uh oh!
There was an error while loading. Please reload this page.