Skip to content

chore(deps): remove dependency on ethereum-execution #1787

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

Merged
merged 5 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ classifiers = [
]
dependencies = [
"click>=8.1.0,<9",
"ethereum-execution==1.17.0rc6.dev1",
"hive.py @ git+https://github.com/marioevz/hive.py",
"ethereum-spec-evm-resolver",
"gitpython>=3.1.31,<4",
Expand Down
70 changes: 65 additions & 5 deletions src/ethereum_test_types/account_types.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""Account-related types for Ethereum tests."""

from dataclasses import dataclass
from typing import List, Literal
from dataclasses import dataclass, field
from typing import Dict, List, Literal, Optional, Tuple

from coincurve.keys import PrivateKey
from ethereum.frontier.fork_types import Account as FrontierAccount
from ethereum.frontier.fork_types import Address as FrontierAddress
from ethereum.frontier.state import State, set_account, set_storage, state_root
from ethereum_types.bytes import Bytes20
from ethereum_types.numeric import U256, Bytes32, Uint
from pydantic import PrivateAttr

Expand All @@ -26,8 +24,70 @@
)
from ethereum_test_vm import EVMCodeType

from .trie import EMPTY_TRIE_ROOT, FrontierAccount, Trie, root, trie_get, trie_set
from .utils import keccak256

FrontierAddress = Bytes20


@dataclass
class State:
"""Contains all information that is preserved between transactions."""

_main_trie: Trie[Bytes20, Optional[FrontierAccount]] = field(
default_factory=lambda: Trie(secured=True, default=None)
)
_storage_tries: Dict[Bytes20, Trie[Bytes32, U256]] = field(default_factory=dict)
_snapshots: List[
Tuple[
Trie[Bytes20, Optional[FrontierAccount]],
Dict[Bytes20, Trie[Bytes32, U256]],
]
] = field(default_factory=list)


def set_account(state: State, address: Bytes20, account: Optional[FrontierAccount]) -> None:
"""
Set the `Account` object at an address. Setting to `None` deletes
the account (but not its storage, see `destroy_account()`).
"""
trie_set(state._main_trie, address, account)


def set_storage(state: State, address: Bytes20, key: Bytes32, value: U256) -> None:
"""
Set a value at a storage key on an account. Setting to `U256(0)` deletes
the key.
"""
assert trie_get(state._main_trie, address) is not None

trie = state._storage_tries.get(address)
if trie is None:
trie = Trie(secured=True, default=U256(0))
state._storage_tries[address] = trie
trie_set(trie, key, value)
if trie._data == {}:
del state._storage_tries[address]


def storage_root(state: State, address: Bytes20) -> Bytes32:
"""Calculate the storage root of an account."""
assert not state._snapshots
if address in state._storage_tries:
return root(state._storage_tries[address])
else:
return EMPTY_TRIE_ROOT


def state_root(state: State) -> Bytes32:
"""Calculate the state root."""
assert not state._snapshots

def get_storage_root(address: Bytes20) -> Bytes32:
return storage_root(state, address)

return root(state._main_trie, get_storage_root=get_storage_root)


class EOA(Address):
"""
Expand Down
Loading
Loading