-
Notifications
You must be signed in to change notification settings - Fork 167
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
Open
LouisTsai-Csie
wants to merge
17
commits into
ethereum:main
Choose a base branch
from
LouisTsai-Csie:enhance-eip7823-coverage
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
17 commits
Select commit
Hold shift + click to select a range
7a7ffae
refactor(eip7883): update vector input structure
LouisTsai-Csie 8ee0e3d
feat: add eip7702, gas usage and extra edge cases
LouisTsai-Csie f6508ff
feat: add fork transition test
LouisTsai-Csie 933b0d1
test: add extra invalid cases
LouisTsai-Csie a475888
refactor(tests): Improve fixture and test descriptions for clarity
LouisTsai-Csie 70b1dc9
refactor(tests): add helper for invalid case
LouisTsai-Csie c455262
feat: add invalud boundary test cases
LouisTsai-Csie 81b6bfa
chore: update boundary input case
LouisTsai-Csie 6cda28a
refactor(tests): simplify boundary modexp test cases
LouisTsai-Csie 5691c15
fix(tests): update fork transition test
LouisTsai-Csie f72066e
feat(test): add gas formula egde cases
LouisTsai-Csie 0518821
test: add extra casefor modexp invalid input
LouisTsai-Csie 95c01a9
tests: port legacy modexp test
LouisTsai-Csie b93500c
refactor: update vector and data types
LouisTsai-Csie 757501f
refactor: remove valid case from invalid scenario
LouisTsai-Csie ec39341
refactor: update result comparison method and test case
LouisTsai-Csie c6b83d4
refactor: update comment
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.