Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# change max line length from 80 to 100
a3b64605a548a7a707d7b05bded506d7bef384e6
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"internal-terms": false // Disable the `internal-terms` dictionary
},
"[python]": {
"editor.rulers": [80],
"editor.rulers": [100],
"editor.formatOnSave": true,
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.codeActionsOnSave": {
Expand All @@ -33,5 +33,9 @@
// "pytest-framework.ini",
"pytest.ini"
// "-vv"
],
"black-formatter.args": [
"--line-length",
"99"
]
}
19 changes: 19 additions & 0 deletions docs/dev/coding_style.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Coding Style

## Formatting and Line Length

The Python code in execution-spec-tests is black formatted with a maximum line length of 100. Using VS Code with `editor.formatOnSave` is a big help to ensure files conform to the repo's coding style, see [VS Code Setup](../getting_started/setup_vs_code.md) to configure this and other useful settings.

### Ignoring Bulk Change Commits

The max line length was changed from 80 to 100 in Q2 2023. To ignore this bulk change commit in git blame output, use the `.git-blame-ignore-revs` file, for example:

```console
git blame --ignore-revs-file .git-blame-ignore-revs docs/gen_filler_pages.py
```

To use the revs file persistently with `git blame`, run

```console
git config blame.ignoreRevsFile .git-blame-ignore-revs
```
3 changes: 2 additions & 1 deletion docs/dev/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

This documentation is aimed at maintainers of `execution-spec-tests` but may be helpful during test case/filler development:

- [generating documentation](./docs.md).
- [generating documentation](./docs.md).
- [coding style](./coding_style.md).
24 changes: 6 additions & 18 deletions docs/gen_filler_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def get_script_relative_path(): # noqa: D103
"disable filler doc generation"
)
else:
logger.warning(
f"{script_name}: skipping automatic generation of " "filler doc"
)
logger.warning(f"{script_name}: skipping automatic generation of " "filler doc")
logger.info(
f"{script_name}: set env var {enabled_env_var_name} "
"to 'true' and re-run `mkdocs serve` or `mkdocs build` to "
Expand Down Expand Up @@ -92,9 +90,7 @@ def apply_name_filters(input_string: str):
]

for pattern, replacement in regexes:
input_string = re.sub(
pattern, replacement, input_string, flags=re.IGNORECASE
)
input_string = re.sub(pattern, replacement, input_string, flags=re.IGNORECASE)

return input_string

Expand All @@ -117,9 +113,7 @@ def copy_file(source_file, destination_file):
if "__pycache__" in root:
continue

markdown_files = [
filename for filename in files if filename.endswith(".md")
]
markdown_files = [filename for filename in files if filename.endswith(".md")]
python_files = [filename for filename in files if filename.endswith(".py")]

root_filtered = apply_name_filters(root)
Expand All @@ -134,15 +128,11 @@ def copy_file(source_file, destination_file):
# from the __init__.py. mkdocs seems to struggle when both
# an index.md and a readme.md are present.
output_file_path = output_directory / "test_cases.md"
nav_path = (
"Test Case Reference" / relative_filler_path / "Test Cases"
)
nav_path = "Test Case Reference" / relative_filler_path / "Test Cases"
else:
output_file_path = output_directory / file
file_no_ext = os.path.splitext(file)[0]
nav_path = (
"Test Case Reference" / relative_filler_path / file_no_ext
)
nav_path = "Test Case Reference" / relative_filler_path / file_no_ext
copy_file(source_file, output_file_path)
nav_tuple = tuple(apply_name_filters(part) for part in nav_path.parts)
nav[nav_tuple] = output_file_path
Expand All @@ -159,9 +149,7 @@ def copy_file(source_file, destination_file):
else:
file_no_ext = os.path.splitext(file)[0]
output_file_path = output_directory / f"{file_no_ext}.md"
nav_path = (
"Test Case Reference" / relative_filler_path / file_no_ext
)
nav_path = "Test Case Reference" / relative_filler_path / file_no_ext
package_name = os.path.join(root, file_no_ext).replace(os.sep, ".")
pytest_test_path = os.path.join(root, file)

Expand Down
1 change: 1 addition & 0 deletions docs/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [Getting Help](getting_help/index.md)
* [Developer Doc](dev/index.md)
* [Documentation](dev/docs.md)
* [Coding Style](dev/coding_style.md)
* [Library Reference](library/index.md)
* [EVM Transition Tool Package](library/evm_transition_tool.md)
* [EVM Block Builder Package](library/evm_block_builder.md)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[tool.isort]
profile = "black"
multi_line_output = 3
line_length = 79
line_length = 99

[tool.black]
line-length = 79
line-length = 99
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extend-ignore = E203, D107, D200, D203, D205,
# Ignore D415: First line should end with a period, question mark, or exclamation point
# Ignore D416: Section name should end with a colon
# Ignore N806: Variable names with all caps (ALL_CAPS)
max-line-length = 99
per-file-ignore =
tests/evm_transition_tool/test_evaluate.py:E501

Expand Down
20 changes: 5 additions & 15 deletions src/ethereum_test_forks/base_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,39 @@ class BaseFork(ABC, metaclass=BaseForkMeta):

@classmethod
@abstractmethod
def header_base_fee_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_base_fee_required(cls, block_number: int, timestamp: int) -> bool:
"""
Returns true if the header must contain base fee
"""
pass

@classmethod
@abstractmethod
def header_prev_randao_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_prev_randao_required(cls, block_number: int, timestamp: int) -> bool:
"""
Returns true if the header must contain Prev Randao value
"""
pass

@classmethod
@abstractmethod
def header_zero_difficulty_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_zero_difficulty_required(cls, block_number: int, timestamp: int) -> bool:
"""
Returns true if the header must have difficulty zero
"""
pass

@classmethod
@abstractmethod
def header_withdrawals_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_withdrawals_required(cls, block_number: int, timestamp: int) -> bool:
"""
Returns true if the header must contain withdrawals
"""
pass

@classmethod
@abstractmethod
def header_excess_data_gas_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_excess_data_gas_required(cls, block_number: int, timestamp: int) -> bool:
"""
Returns true if the header must contain excess data gas
"""
Expand Down
40 changes: 10 additions & 30 deletions src/ethereum_test_forks/forks/forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,35 @@ class Frontier(BaseFork):
"""

@classmethod
def header_base_fee_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_base_fee_required(cls, block_number: int, timestamp: int) -> bool:
"""
At genesis, header must not contain base fee
"""
return False

@classmethod
def header_prev_randao_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_prev_randao_required(cls, block_number: int, timestamp: int) -> bool:
"""
At genesis, header must not contain Prev Randao value
"""
return False

@classmethod
def header_zero_difficulty_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_zero_difficulty_required(cls, block_number: int, timestamp: int) -> bool:
"""
At genesis, header must not have difficulty zero
"""
return False

@classmethod
def header_withdrawals_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_withdrawals_required(cls, block_number: int, timestamp: int) -> bool:
"""
At genesis, header must not contain withdrawals
"""
return False

@classmethod
def header_excess_data_gas_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_excess_data_gas_required(cls, block_number: int, timestamp: int) -> bool:
"""
At genesis, header must not contain excess data gas
"""
Expand Down Expand Up @@ -139,9 +129,7 @@ class London(Berlin):
"""

@classmethod
def header_base_fee_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_base_fee_required(cls, block_number: int, timestamp: int) -> bool:
"""
Base Fee is required starting from London.
"""
Expand Down Expand Up @@ -171,18 +159,14 @@ class Merge(London):
"""

@classmethod
def header_prev_randao_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_prev_randao_required(cls, block_number: int, timestamp: int) -> bool:
"""
Prev Randao is required starting from Merge.
"""
return True

@classmethod
def header_zero_difficulty_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_zero_difficulty_required(cls, block_number: int, timestamp: int) -> bool:
"""
Zero difficulty is required starting from Merge.
"""
Expand All @@ -202,9 +186,7 @@ class Shanghai(Merge):
"""

@classmethod
def header_withdrawals_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_withdrawals_required(cls, block_number: int, timestamp: int) -> bool:
"""
Withdrawals are required starting from Shanghai.
"""
Expand All @@ -225,9 +207,7 @@ def is_deployed(cls):
return False

@classmethod
def header_excess_data_gas_required(
cls, block_number: int, timestamp: int
) -> bool:
def header_excess_data_gas_required(cls, block_number: int, timestamp: int) -> bool:
"""
Excess data gas is required starting from Cancun.
"""
Expand Down
4 changes: 1 addition & 3 deletions src/ethereum_test_forks/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def get_transition_forks() -> List[Fork]:
fork = transition.__dict__[fork_name]
if not isinstance(fork, type):
continue
if issubclass(fork, TransitionBaseClass) and issubclass(
fork, BaseFork
):
if issubclass(fork, TransitionBaseClass) and issubclass(fork, BaseFork):
transition_forks.append(fork)

return transition_forks
Expand Down
23 changes: 4 additions & 19 deletions src/ethereum_test_forks/tests/test_forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ def test_transition_forks():
def test_forks_from(): # noqa: D103
assert forks_from(Merge) == [Merge, LAST_DEPLOYED]
assert forks_from(Merge, deployed_only=True) == [Merge, LAST_DEPLOYED]
assert (
forks_from(Merge, deployed_only=False)
== [Merge, LAST_DEPLOYED] + DEVELOPMENT_FORKS
)
assert forks_from(Merge, deployed_only=False) == [Merge, LAST_DEPLOYED] + DEVELOPMENT_FORKS


def test_forks():
Expand All @@ -70,22 +67,10 @@ def test_forks():
assert Merge.header_base_fee_required(0, 0) is True

# Transition forks too
assert (
cast(Fork, BerlinToLondonAt5).header_base_fee_required(4, 0) is False
)
assert cast(Fork, BerlinToLondonAt5).header_base_fee_required(4, 0) is False
assert cast(Fork, BerlinToLondonAt5).header_base_fee_required(5, 0) is True
assert (
cast(Fork, MergeToShanghaiAtTime15k).header_withdrawals_required(
0, 14_999
)
is False
)
assert (
cast(Fork, MergeToShanghaiAtTime15k).header_withdrawals_required(
0, 15_000
)
is True
)
assert cast(Fork, MergeToShanghaiAtTime15k).header_withdrawals_required(0, 14_999) is False
assert cast(Fork, MergeToShanghaiAtTime15k).header_withdrawals_required(0, 15_000) is True

assert is_fork(Berlin, Berlin) is True
assert is_fork(London, Berlin) is True
Expand Down
4 changes: 1 addition & 3 deletions src/ethereum_test_forks/transition_base_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def name(cls) -> str:
return transition_name

NewTransitionClass.transitions_to = lambda: to_fork # type: ignore
NewTransitionClass.transitions_from = ( # type: ignore
lambda: cls.__bases__[0]
)
NewTransitionClass.transitions_from = lambda: cls.__bases__[0] # type: ignore

return NewTransitionClass

Expand Down
8 changes: 1 addition & 7 deletions src/ethereum_test_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@
)
from .filling.fill import fill_test
from .reference_spec import ReferenceSpec, ReferenceSpecTypes
from .spec import (
BaseTest,
BlockchainTest,
BlockchainTestFiller,
StateTest,
StateTestFiller,
)
from .spec import BaseTest, BlockchainTest, BlockchainTestFiller, StateTest, StateTestFiller
from .vm import Opcode, Opcodes

__all__ = (
Expand Down
8 changes: 2 additions & 6 deletions src/ethereum_test_tools/code/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,11 @@ def __init__(
if len(pre_padding_bytes) > initcode_length:
raise Exception("Invalid specified length for initcode")

padding_bytes = bytes(
[padding_byte] * (initcode_length - len(pre_padding_bytes))
)
padding_bytes = bytes([padding_byte] * (initcode_length - len(pre_padding_bytes)))
else:
padding_bytes = bytes()

self.deployment_gas = GAS_PER_DEPLOYED_CODE_BYTE * len(
deploy_code_bytes
)
self.deployment_gas = GAS_PER_DEPLOYED_CODE_BYTE * len(deploy_code_bytes)

super().__init__(bytecode=pre_padding_bytes + padding_bytes, name=name)

Expand Down
Loading