Skip to content

Commit bff747c

Browse files
committed
fix
1 parent 8486fcb commit bff747c

File tree

5 files changed

+52
-15
lines changed

5 files changed

+52
-15
lines changed

src/ethereum_test_benchmark/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""Benchmark code generator classes for creating optimized bytecode patterns."""
1+
"""
2+
Benchmark code generator classes for
3+
creating optimized bytecode patterns.
4+
"""
25

36
from .benchmark_code_generator import (
47
BenchmarkCodeGenerator,

src/ethereum_test_benchmark/benchmark_code_generator.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""Benchmark code generator classes for creating optimized bytecode patterns."""
1+
"""
2+
Benchmark code generator classes for creating
3+
optimized bytecode patterns.
4+
"""
25

36
from ethereum_test_forks import Fork
47
from ethereum_test_specs.benchmark import BenchmarkCodeGenerator
@@ -13,7 +16,8 @@ class JumpLoopGenerator(BenchmarkCodeGenerator):
1316
def deploy_contracts(self, pre: Alloc, fork: Fork) -> None:
1417
"""Deploy the looping contract."""
1518
# Benchmark Test Structure:
16-
# setup + JUMPDEST + attack + attack + ... + attack + JUMP(setup_length)
19+
# setup + JUMPDEST + attack + attack + ... +
20+
# attack + JUMP(setup_length)
1721
code = self.generate_repeated_code(self.attack_block, self.setup, fork)
1822
self._contract_address = pre.deploy_contract(code=code)
1923

@@ -30,13 +34,17 @@ def generate_transaction(self, pre: Alloc, gas_limit: int, fork: Fork) -> Transa
3034

3135

3236
class ExtCallGenerator(BenchmarkCodeGenerator):
33-
"""Generates bytecode that fills the contract to maximum allowed code size."""
37+
"""
38+
Generates bytecode that fills the contract to
39+
maximum allowed code size.
40+
"""
3441

3542
def deploy_contracts(self, pre: Alloc, fork: Fork) -> None:
3643
"""Deploy both target and caller contracts."""
3744
# Benchmark Test Structure:
3845
# There are two contracts:
39-
# 1. The target contract that executes certain operation but not loop (e.g. PUSH)
46+
# 1. The target contract that executes certain operation
47+
# but not loop (e.g. PUSH)
4048
# 2. The loop contract that calls the target contract in a loop
4149

4250
max_iterations = min(
@@ -49,8 +57,12 @@ def deploy_contracts(self, pre: Alloc, fork: Fork) -> None:
4957
)
5058

5159
# Create caller contract that repeatedly calls the target contract
52-
# attack = POP(STATICCALL(GAS, target_contract_address, 0, 0, 0, 0))
53-
# setup + JUMPDEST + attack + attack + ... + attack + JUMP(setup_length)
60+
# attack = POP(
61+
# STATICCALL(GAS, target_contract_address, 0, 0, 0, 0)
62+
# )
63+
#
64+
# setup + JUMPDEST + attack + attack + ... + attack +
65+
# JUMP(setup_length)
5466
code_sequence = Op.POP(Op.STATICCALL(Op.GAS, self._target_contract_address, 0, 0, 0, 0))
5567

5668
caller_code = self.generate_repeated_code(code_sequence, Bytecode(), fork)

src/ethereum_test_specs/benchmark.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ def generate_transaction(self, pre: Alloc, gas_limit: int, fork: Fork) -> Transa
5454
def generate_repeated_code(
5555
self, repeated_code: Bytecode, setup: Bytecode, fork: Fork
5656
) -> Bytecode:
57-
"""Calculate the maximum number of iterations that can fit in the code size limit."""
57+
"""
58+
Calculate the maximum number of iterations that
59+
can fit in the code size limit.
60+
"""
5861
assert len(repeated_code) > 0, "repeated_code cannot be empty"
5962
max_code_size = fork.max_code_size()
6063

@@ -114,7 +117,10 @@ class BenchmarkTest(BaseTest):
114117

115118
@classmethod
116119
def pytest_parameter_name(cls) -> str:
117-
"""Return the parameter name used in pytest to select this spec type."""
120+
"""
121+
Return the parameter name used in pytest
122+
to select this spec type.
123+
"""
118124
return "benchmark_test"
119125

120126
@classmethod
@@ -124,7 +130,10 @@ def discard_fixture_format_by_marks(
124130
fork: Fork,
125131
markers: List[pytest.Mark],
126132
) -> bool:
127-
"""Discard a fixture format from filling if the appropriate marker is used."""
133+
"""
134+
Discard a fixture format from filling if the
135+
appropriate marker is used.
136+
"""
128137
if "blockchain_test_only" in [m.name for m in markers]:
129138
return fixture_format != BlockchainFixture
130139
if "blockchain_test_engine_only" in [m.name for m in markers]:
@@ -136,7 +145,10 @@ def get_genesis_environment(self, fork: Fork) -> Environment:
136145
return self.env
137146

138147
def split_transaction(self, tx: Transaction, gas_limit_cap: int | None) -> List[Transaction]:
139-
"""Split a transaction that exceeds the gas limit cap into multiple transactions."""
148+
"""
149+
Split a transaction that exceeds the gas
150+
limit cap into multiple transactions.
151+
"""
140152
if gas_limit_cap is None:
141153
tx.gas_limit = HexNumber(self.gas_benchmark_value)
142154
return [tx]

src/ethereum_test_specs/tests/test_benchmark.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""Tests for the BenchmarkTest class and its transaction splitting functionality."""
1+
"""
2+
Tests for the BenchmarkTest class and its
3+
transaction splitting functionality.
4+
"""
25

36
import pytest
47

@@ -20,7 +23,10 @@
2023
],
2124
)
2225
def test_split_transaction(gas_benchmark_value_millions: int, expected_splits: int):
23-
"""Test that transaction splitting works correctly for Osaka fork gas cap."""
26+
"""
27+
Test that transaction splitting works
28+
correctly for Osaka fork gas cap.
29+
"""
2430
gas_benchmark_value = gas_benchmark_value_millions * 1_000_000
2531
gas_limit_cap = 16_000_000 # Osaka's transaction gas limit cap
2632

@@ -100,6 +106,7 @@ def test_split_transaction_edge_cases(gas_benchmark_value: int, gas_limit_cap: i
100106
# When no cap, gas_limit should be benchmark value
101107
assert split_txs[0].gas_limit == gas_benchmark_value
102108
else:
103-
# When cap > benchmark, gas_limit should be min of tx.gas_limit and benchmark
109+
# When cap > benchmark, gas_limit should be
110+
# min of tx.gas_limit and benchmark
104111
assert benchmark_test.tx is not None, "Transaction should not be None"
105112
assert split_txs[0].gas_limit == min(benchmark_test.tx.gas_limit, gas_benchmark_value)

src/ethereum_test_vm/bytecode.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,10 @@ def keccak256(self) -> Hash:
245245
def __get_pydantic_core_schema__(
246246
cls, source_type: Any, handler: GetCoreSchemaHandler
247247
) -> PlainValidatorFunctionSchema:
248-
"""Provide Pydantic core schema for Bytecode serialization and validation."""
248+
"""
249+
Provide Pydantic core schema for Bytecode
250+
serialization and validation.
251+
"""
249252
return no_info_plain_validator_function(
250253
cls,
251254
serialization=plain_serializer_function_ser_schema(

0 commit comments

Comments
 (0)