Skip to content
Draft
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
16 changes: 16 additions & 0 deletions tests/benchmark/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest
from execution_testing import Fork, StubConfig
from execution_testing.rpc import EthRPC

DEFAULT_BENCHMARK_FORK = "Prague"

Expand Down Expand Up @@ -74,3 +75,18 @@ def pytest_ignore_collect(collection_path: Path, config: Any) -> bool | None:
def tx_gas_limit(fork: Fork, gas_benchmark_value: int) -> int:
"""Return the transaction gas limit cap."""
return fork.transaction_gas_limit_cap() or gas_benchmark_value


@pytest.fixture
def live_eth_rpc(request: pytest.FixtureRequest) -> EthRPC | None:
"""
Resolve `eth_rpc` from the current session.

In execute mode the fixture is provided by the execute plugin and
points to a live network; in fill mode no such fixture exists and
this returns ``None``.
"""
try:
return request.getfixturevalue("eth_rpc")
except pytest.FixtureLookupError:
return None
12 changes: 6 additions & 6 deletions tests/benchmark/stateful/bloatnet/test_single_opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ def run_bloated_eoa_benchmark(
token_name: str,
existing_slots: bool,
runtime_code: Bytecode,
eth_rpc: EthRPC | None = None,
live_eth_rpc: EthRPC | None = None,
) -> None:
"""
Run a bloated-EOA benchmark with the given runtime delegation code.

Handles authority setup, slot 0 initialization, delegation to
runtime code, benchmark tx generation, and test invocation.
"""
authority = get_storage_bloated_eoa(token_name, eth_rpc=eth_rpc)
authority = get_storage_bloated_eoa(token_name, eth_rpc=live_eth_rpc)
slot_0_value = Hash(1) if existing_slots else Hash(START_SLOT)

setter_address = pre.deploy_contract(code=Op.SSTORE(0, Op.CALLDATALOAD(0)))
Expand Down Expand Up @@ -161,7 +161,7 @@ def test_sload_bloated(
tx_gas_limit: int,
token_name: str,
existing_slots: bool,
eth_rpc: EthRPC | None = None,
live_eth_rpc: EthRPC | None,
) -> None:
"""
Benchmark SLOAD opcodes targeting an EOA with storage bloated.
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_sload_bloated(
token_name=token_name,
existing_slots=existing_slots,
runtime_code=runtime_code,
eth_rpc=eth_rpc,
live_eth_rpc=live_eth_rpc,
)


Expand All @@ -207,7 +207,7 @@ def test_sstore_bloated(
token_name: str,
write_new_value: bool,
existing_slots: bool,
eth_rpc: EthRPC | None = None,
live_eth_rpc: EthRPC | None,
) -> None:
"""
Benchmark SSTORE opcodes targeting an EOA with storage bloated.
Expand Down Expand Up @@ -255,7 +255,7 @@ def test_sstore_bloated(
token_name=token_name,
existing_slots=existing_slots,
runtime_code=runtime_code,
eth_rpc=eth_rpc,
live_eth_rpc=live_eth_rpc,
)


Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/stateful/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def get_storage_bloated_eoa(
if eth_rpc is not None:
nonce = eth_rpc.get_transaction_count(Address(eoa))
eoa.nonce = Number(nonce)
print(f"Nonce for storage-bloated EOA '{name}' is {nonce}")
return eoa


Expand Down