Skip to content

Commit

Permalink
new(tests): EIP-7685: General purpose execution layer requests
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed May 24, 2024
1 parent 6719976 commit 0470295
Show file tree
Hide file tree
Showing 6 changed files with 489 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Test fixtures for use by clients are available for each release on the [Github r
-[EIP-663](https://eips.ethereum.org/EIPS/eip-663): Add `test_dupn.py` and `test_swapn.py` ([#502](https://github.com/ethereum/execution-spec-tests/pull/502)).
- ✨ Add tests for [EIP-6110: Supply validator deposits on chain](https://eips.ethereum.org/EIPS/eip-6110) ([#530](https://github.com/ethereum/execution-spec-tests/pull/530)).
- ✨ Add tests for [EIP-7002: Execution layer triggerable withdrawals](https://eips.ethereum.org/EIPS/eip-7002) ([#530](https://github.com/ethereum/execution-spec-tests/pull/530)).
- ✨ Add tests for [EIP-7685: General purpose execution layer requests](https://eips.ethereum.org/EIPS/eip-7685) ([#530](https://github.com/ethereum/execution-spec-tests/pull/530)).

### 🛠️ Framework

Expand Down
3 changes: 3 additions & 0 deletions tests/prague/eip7685_general_purpose_el_requests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Cross-client EIP-7685 Tests
"""
87 changes: 87 additions & 0 deletions tests/prague/eip7685_general_purpose_el_requests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""
Fixtures for the EIP-7685 deposit tests.
"""

from typing import Dict, List

import pytest

from ethereum_test_tools import Account, Address, Block, BlockException, Header, Transaction

from ..eip6110_deposits.helpers import DepositInteractionBase, DepositRequest
from ..eip7002_el_triggerable_withdrawals.helpers import (
WithdrawalRequest,
WithdrawalRequestInteractionBase,
)


@pytest.fixture
def pre(
requests: List[DepositInteractionBase | WithdrawalRequestInteractionBase],
) -> Dict[Address, Account]:
"""
Initial state of the accounts. Every deposit transaction defines their own pre-state
requirements, and this fixture aggregates them all.
"""
pre: Dict[Address, Account] = {}
for d in requests:
d.update_pre(pre)
return pre


@pytest.fixture
def txs(
requests: List[DepositInteractionBase | WithdrawalRequestInteractionBase],
) -> List[Transaction]:
"""List of transactions to include in the block."""
address_nonce: Dict[Address, int] = {}
txs = []
for r in requests:
nonce = 0
if r.sender_account.address in address_nonce:
nonce = address_nonce[r.sender_account.address]
txs.append(r.transaction(nonce))
address_nonce[r.sender_account.address] = nonce + 1
return txs


@pytest.fixture
def block_body_override_requests() -> List[DepositRequest] | None:
"""List of requests that overwrite the requests in the header. None by default."""
return None


@pytest.fixture
def exception() -> BlockException | None:
"""Block exception expected by the tests. None by default."""
return None


@pytest.fixture
def blocks(
requests: List[DepositInteractionBase | WithdrawalRequestInteractionBase],
block_body_override_requests: List[DepositRequest | WithdrawalRequest] | None,
txs: List[Transaction],
exception: BlockException | None,
) -> List[Block]:
"""List of blocks that comprise the test."""
included_deposit_requests = []
included_withdrawal_requests = []
# Single block therefore base fee
withdrawal_request_fee = 1
for r in requests:
if isinstance(r, DepositInteractionBase):
included_deposit_requests += r.valid_requests(10**18)
elif isinstance(r, WithdrawalRequestInteractionBase):
included_withdrawal_requests += r.valid_requests(withdrawal_request_fee)

return [
Block(
txs=txs,
header_verify=Header(
requests_root=included_deposit_requests + included_withdrawal_requests,
),
requests=block_body_override_requests,
exception=exception,
)
]
19 changes: 19 additions & 0 deletions tests/prague/eip7685_general_purpose_el_requests/spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Common procedures to test
[EIP-7685: General purpose execution layer requests](https://eips.ethereum.org/EIPS/eip-7685)
""" # noqa: E501

from dataclasses import dataclass


@dataclass(frozen=True)
class ReferenceSpec:
"""
Defines the reference spec version and git path.
"""

git_path: str
version: str


ref_spec_7685 = ReferenceSpec("EIPS/eip-7685.md", "52a260582376476e658b1dda60864bcac3cf5e1a")
Loading

0 comments on commit 0470295

Please sign in to comment.