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: 0 additions & 2 deletions packages/testing/src/execution_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
BenchmarkCodeGenerator,
ExtCallGenerator,
JumpLoopGenerator,
StubConfig,
)
from .checklists import EIPChecklist
from .exceptions import (
Expand Down Expand Up @@ -189,7 +188,6 @@
"StateTest",
"StateTestFiller",
"Storage",
"StubConfig",
"Switch",
"TestAddress",
"TestAddress2",
Expand Down
2 changes: 0 additions & 2 deletions packages/testing/src/execution_testing/benchmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
ExtCallGenerator,
JumpLoopGenerator,
)
from .stub_config import StubConfig

__all__ = (
"BenchmarkCodeGenerator",
"ExtCallGenerator",
"JumpLoopGenerator",
"StubConfig",
)
52 changes: 0 additions & 52 deletions packages/testing/src/execution_testing/benchmark/stub_config.py

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from execution_testing.tools import Initcode
from execution_testing.vm import Op

from ...shared.address_stubs import StubAddress
from ..pre_alloc import AddressStubs
from ..rpc.chain_builder_eth_rpc import ChainBuilderEthRPC, TestingRPC

Expand Down Expand Up @@ -771,7 +772,7 @@ def test_fail_fund_account_in_alloc(
case "stubbed_contract":
stub_name = "stubbed_contract"
stub_address = contract_deployer.deploy(code)
stubs = AddressStubs({stub_name: stub_address})
stubs = AddressStubs({stub_name: StubAddress(addr=stub_address)})
account_in_alloc = (
f'pre.deploy_contract({code}, stub="{stub_name}")'
)
Expand Down Expand Up @@ -842,7 +843,7 @@ def test_stubs(state_test, pre) -> None:
stub_address=f"{stub_address}",
)

stubs = AddressStubs({stub_name: stub_address})
stubs = AddressStubs({stub_name: StubAddress(addr=stub_address)})
execute_runner.run_assert(test_method=test_method, stubs=stubs)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@

import pytest

from execution_testing.base_types import Address
from execution_testing.base_types import Address, Hash

from ...shared.address_stubs import StubAddress, StubEOA
from ..pre_alloc import AddressStubs

ADDR_1 = Address("0x0000000000000000000000000000000000000001")
DEPOSIT_ADDR = Address("0x00000000219ab540356cbb839cbe05303d7705fa")
TEST_PKEY = Hash(
0x45A915E4D060149EB4365960E6A7A45F334393093061116B197E3240065FF2D8
)
TEST_ADDR = Address("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")


@pytest.mark.parametrize(
"input_value,expected",
Expand All @@ -18,14 +26,8 @@
id="empty_address_stubs_string",
),
pytest.param(
'{"some_address": "0x0000000000000000000000000000000000000001"}',
AddressStubs(
{
"some_address": Address(
"0x0000000000000000000000000000000000000001"
)
}
),
'{"some_address": {"addr": "0x0000000000000000000000000000000000000001"}}', # noqa: E501
AddressStubs({"some_address": StubAddress(addr=ADDR_1)}),
id="address_stubs_string_with_some_address",
),
],
Expand All @@ -46,11 +48,11 @@ def test_address_stubs(input_value: Any, expected: AddressStubs) -> None:
),
pytest.param(
"one_address.json",
'{"DEPOSIT_CONTRACT_ADDRESS": "0x00000000219ab540356cbb839cbe05303d7705fa"}', # noqa: E501
'{"DEPOSIT_CONTRACT_ADDRESS": {"addr": "0x00000000219ab540356cbb839cbe05303d7705fa"}}', # noqa: E501
AddressStubs(
{
"DEPOSIT_CONTRACT_ADDRESS": Address(
"0x00000000219ab540356cbb839cbe05303d7705fa"
"DEPOSIT_CONTRACT_ADDRESS": StubAddress(
addr=DEPOSIT_ADDR,
),
}
),
Expand All @@ -76,3 +78,44 @@ def test_address_stubs_file_not_found(pytester: pytest.Pytester) -> None:
missing_test = pytester.path.joinpath("nonexistent.json")
with pytest.raises(FileNotFoundError):
AddressStubs.model_validate_json_or_file(str(missing_test))


def test_address_stubs_getitem_returns_address() -> None:
"""Verify __getitem__ returns the Address, not the stub entry."""
stubs = AddressStubs({"label": StubAddress(addr=ADDR_1)})
assert stubs["label"] == ADDR_1
assert isinstance(stubs["label"], Address)


def test_address_stubs_contains() -> None:
"""Verify __contains__ checks for label presence."""
stubs = AddressStubs({"label": StubAddress(addr=ADDR_1)})
assert "label" in stubs
assert "other" not in stubs


def test_address_stubs_with_pkey() -> None:
"""Parse a JSON string with a private key entry."""
json_str = (
'{"eoa": {"addr": "' + str(TEST_ADDR) + '", '
'"pkey": "' + str(TEST_PKEY) + '"}}'
)
stubs = AddressStubs.model_validate_json_or_file(json_str)
assert stubs["eoa"] == TEST_ADDR
assert stubs.is_eoa("eoa")
entry = stubs.get_entry("eoa")
assert isinstance(entry, StubEOA)
assert entry.pkey == TEST_PKEY


def test_address_stubs_is_eoa() -> None:
"""Verify is_eoa distinguishes entries."""
stubs = AddressStubs(
{
"contract": StubAddress(addr=ADDR_1),
"eoa": StubEOA(addr=TEST_ADDR, pkey=TEST_PKEY),
}
)
assert not stubs.is_eoa("contract")
assert stubs.is_eoa("eoa")
assert not stubs.is_eoa("nonexistent")
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
)
from execution_testing.tools import Initcode

from ..shared.execute_fill import stub_accounts_key
from ..shared.execute_fill import stub_accounts_key, stub_eoas_key
from ..shared.pre_alloc import Alloc as SharedAlloc
from ..shared.pre_alloc import AllocFlags

Expand Down Expand Up @@ -69,19 +69,32 @@ class Alloc(SharedAlloc):
_eoa_fund_amount_default: int = PrivateAttr(10**21)
_account_salt: Dict[Hash, int] = PrivateAttr(default_factory=dict)
_stub_accounts: Dict[str, Account] = PrivateAttr(default_factory=dict)
_stub_eoas: Dict[str, EOA] = PrivateAttr(default_factory=dict)

def __init__(
self,
*args: Any,
fork: Fork,
flags: AllocFlags,
stub_accounts: Dict[str, Account] | None = None,
stub_eoas: Dict[str, EOA] | None = None,
**kwargs: Any,
) -> None:
"""Initialize the pre-alloc."""
super().__init__(*args, fork=fork, flags=flags, **kwargs)
if stub_accounts is not None:
self._stub_accounts = stub_accounts
if stub_eoas is not None:
self._stub_eoas = stub_eoas

def stub_eoa(self, label: str) -> EOA:
"""Return the EOA for a key-bearing stub."""
if label not in self._stub_eoas:
raise ValueError(
f"Stub EOA '{label}' not found. "
"Provide --address-stubs with a pkey entry."
)
return self._stub_eoas[label]

def get_next_account_salt(self, account_hash: Hash) -> int:
"""Retrieve the next salt for this account."""
Expand Down Expand Up @@ -477,12 +490,21 @@ def stub_accounts(
return request.config.stash.get(stub_accounts_key, {})


@pytest.fixture(scope="session")
def stub_eoas(
request: pytest.FixtureRequest,
) -> Dict[str, EOA]:
"""Return stub EOAs pre-populated during configuration."""
return request.config.stash.get(stub_eoas_key, {})


@pytest.fixture(scope="function")
def pre(
alloc_flags: AllocFlags,
fork: Fork | None,
request: pytest.FixtureRequest,
stub_accounts: Dict[str, Account],
stub_eoas: Dict[str, EOA],
) -> Alloc:
"""Return default pre allocation for all tests (Empty alloc)."""
# FIXME: Static tests don't have a fork so we need to get it from the node.
Expand All @@ -495,4 +517,5 @@ def pre(
flags=alloc_flags,
fork=actual_fork,
stub_accounts=stub_accounts,
stub_eoas=stub_eoas,
)
Loading
Loading