Skip to content

Commit

Permalink
new(tests): EIP-7002: Execution layer triggerable withdrawals
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed May 24, 2024
1 parent 7d15a3e commit 6719976
Show file tree
Hide file tree
Showing 7 changed files with 1,217 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 @@ -14,6 +14,7 @@ Test fixtures for use by clients are available for each release on the [Github r
- ✨ Add tests for [EIP-2537: Precompile for BLS12-381 curve operations](https://eips.ethereum.org/EIPS/eip-2537) ([#499](https://github.com/ethereum/execution-spec-tests/pull/499)).
-[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)).

### 🛠️ Framework

Expand Down
3 changes: 3 additions & 0 deletions tests/prague/eip7002_el_triggerable_withdrawals/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Cross-client EIP-7002 Tests
"""
89 changes: 89 additions & 0 deletions tests/prague/eip7002_el_triggerable_withdrawals/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""
Fixtures for the EIP-7002 deposit tests.
"""
from typing import Dict, List

import pytest

from ethereum_test_tools import Account, Address, Block, Header

from .helpers import WithdrawalRequest, WithdrawalRequestInteractionBase
from .spec import Spec


@pytest.fixture
def included_requests(
blocks_withdrawal_requests: List[List[WithdrawalRequestInteractionBase]],
) -> List[List[WithdrawalRequest]]:
"""
Return the list of withdrawal requests that should be included in each block.
"""
excess_withdrawal_requests = 0
carry_over_requests: List[WithdrawalRequest] = []
per_block_included_requests: List[List[WithdrawalRequest]] = []
for block_withdrawal_requests in blocks_withdrawal_requests:
# Get fee for the current block
current_minimum_fee = Spec.get_fee(excess_withdrawal_requests)

# With the fee, get the valid withdrawal requests for the current block
current_block_requests = []
for w in block_withdrawal_requests:
current_block_requests += w.valid_requests(current_minimum_fee)

# Get the withdrawal requests that should be included in the block
pending_requests = carry_over_requests + current_block_requests
per_block_included_requests.append(
pending_requests[: Spec.MAX_WITHDRAWAL_REQUESTS_PER_BLOCK]
)
carry_over_requests = pending_requests[Spec.MAX_WITHDRAWAL_REQUESTS_PER_BLOCK :]

# Update the excess withdrawal requests
excess_withdrawal_requests = Spec.get_excess_withdrawal_requests(
excess_withdrawal_requests,
len(current_block_requests),
)
return per_block_included_requests


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


@pytest.fixture
def blocks(
blocks_withdrawal_requests: List[List[WithdrawalRequestInteractionBase]],
included_requests: List[List[WithdrawalRequest]],
) -> List[Block]:
"""
Return the list of blocks that should be included in the test.
"""
blocks: List[Block] = []
address_nonce: Dict[Address, int] = {}
for i in range(len(blocks_withdrawal_requests)):
txs = []
for r in blocks_withdrawal_requests[i]:
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
blocks.append(
Block(
txs=txs,
header_verify=Header(
requests_root=included_requests[i],
),
)
)
return blocks
Loading

0 comments on commit 6719976

Please sign in to comment.