Skip to content

Commit

Permalink
new(tests): EIP-7251 condolidation tests
Browse files Browse the repository at this point in the history
fix(tests): EIP-7251

new(tests): Add deposit+withdrawal+consolidation tests

new(tests): Add different requests in same tx

new(tests): Add invalid-order requests tests with consolidations

Update tests/prague/eip7251_consolidations/helpers.py

Co-authored-by: spencer <[email protected]>

Update tests/prague/eip7251_consolidations/spec.py

Co-authored-by: spencer <[email protected]>

Update tests/prague/eip7251_consolidations/spec.py

Co-authored-by: spencer <[email protected]>

tests: add consolidation test with same pubkey

fix(tests): EIP-7002,EIP-7251: keep producing empty blocks to exhaust queues

fix(tests): tox

fix(tests): tox fix
  • Loading branch information
marioevz committed Jul 23, 2024
1 parent 8d8ce95 commit 05d4bbf
Show file tree
Hide file tree
Showing 12 changed files with 1,664 additions and 415 deletions.
6 changes: 6 additions & 0 deletions tests/prague/eip6110_deposits/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ def calldata(self) -> bytes:
+ self.signature
)

def with_source_address(self, source_address: Address) -> "DepositRequest":
"""
Return a copy.
"""
return self.copy()


@dataclass(kw_only=True)
class DepositInteractionBase:
Expand Down
22 changes: 18 additions & 4 deletions tests/prague/eip7002_el_triggerable_withdrawals/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Fixtures for the EIP-7002 deposit tests.
"""
from itertools import zip_longest
from typing import List

import pytest
Expand Down Expand Up @@ -57,6 +58,13 @@ def included_requests(
excess_withdrawal_requests,
len(current_block_requests),
)
while carry_over_requests:
# Keep adding blocks until all withdrawal requests are included
per_block_included_requests.append(
carry_over_requests[: Spec.MAX_WITHDRAWAL_REQUESTS_PER_BLOCK]
)
carry_over_requests = carry_over_requests[Spec.MAX_WITHDRAWAL_REQUESTS_PER_BLOCK :]

return per_block_included_requests


Expand All @@ -69,10 +77,16 @@ def blocks(
"""
Return the list of blocks that should be included in the test.
"""
return [
return [ # type: ignore
Block(
txs=sum((r.transactions() for r in block_requests), []),
header_verify=Header(requests_root=included_requests[i]),
header_verify=Header(requests_root=block_included_requests),
)
for block_requests, block_included_requests in zip_longest(
blocks_withdrawal_requests,
included_requests,
fillvalue=[],
)
for i, block_requests in enumerate(blocks_withdrawal_requests)
]
] + [
Block(header_verify=Header(requests_root=[]))
] # Add an empty block at the end to verify that no more withdrawal requests are included
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
validator_pubkey=0x01,
amount=0,
fee=0,
valid=False,
)
],
),
Expand Down Expand Up @@ -262,7 +263,6 @@
),
pytest.param(
[
# Block 1
[
WithdrawalRequestTransaction(
requests=[
Expand All @@ -275,10 +275,6 @@
]
)
],
# Block 2, no new withdrawal requests, but queued requests from previous block
[],
# Block 3, no new nor queued withdrawal requests
[],
],
id="multiple_block_above_max_withdrawal_requests_from_eoa",
),
Expand Down
3 changes: 3 additions & 0 deletions tests/prague/eip7251_consolidations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Cross-client EIP-7251 Tests
"""
93 changes: 93 additions & 0 deletions tests/prague/eip7251_consolidations/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"""
Fixtures for the EIP-7251 consolidations tests.
"""
from itertools import zip_longest
from typing import List

import pytest

from ethereum_test_tools import Alloc, Block, Header

from .helpers import ConsolidationRequest, ConsolidationRequestInteractionBase
from .spec import Spec


@pytest.fixture
def update_pre(
pre: Alloc,
blocks_consolidation_requests: List[List[ConsolidationRequestInteractionBase]],
):
"""
Initial state of the accounts. Every deposit transaction defines their own pre-state
requirements, and this fixture aggregates them all.
"""
for requests in blocks_consolidation_requests:
for r in requests:
r.update_pre(pre)


@pytest.fixture
def included_requests(
update_pre: None, # Fixture is used for its side effects
blocks_consolidation_requests: List[List[ConsolidationRequestInteractionBase]],
) -> List[List[ConsolidationRequest]]:
"""
Return the list of consolidation requests that should be included in each block.
"""
excess_consolidation_requests = 0
carry_over_requests: List[ConsolidationRequest] = []
per_block_included_requests: List[List[ConsolidationRequest]] = []
for block_consolidation_requests in blocks_consolidation_requests:
# Get fee for the current block
current_minimum_fee = Spec.get_fee(excess_consolidation_requests)

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

# Get the consolidation 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_CONSOLIDATION_REQUESTS_PER_BLOCK]
)
carry_over_requests = pending_requests[Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK :]

# Update the excess consolidation requests
excess_consolidation_requests = Spec.get_excess_consolidation_requests(
excess_consolidation_requests,
len(current_block_requests),
)

while carry_over_requests:
# Keep adding blocks until all consolidation requests are included
per_block_included_requests.append(
carry_over_requests[: Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK]
)
carry_over_requests = carry_over_requests[Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK :]

return per_block_included_requests


@pytest.fixture
def blocks(
update_pre: None, # Fixture is used for its side effects
blocks_consolidation_requests: List[List[ConsolidationRequestInteractionBase]],
included_requests: List[List[ConsolidationRequest]],
) -> List[Block]:
"""
Return the list of blocks that should be included in the test.
"""
return [ # type: ignore
Block(
txs=sum((r.transactions() for r in block_requests), []),
header_verify=Header(requests_root=block_included_requests),
)
for block_requests, block_included_requests in zip_longest(
blocks_consolidation_requests,
included_requests,
fillvalue=[],
)
] + [
Block(header_verify=Header(requests_root=[]))
] # Add an empty block at the end to verify that no more consolidation requests are included
Loading

0 comments on commit 05d4bbf

Please sign in to comment.