Skip to content

Commit 00e8ce8

Browse files
fix(tests): EIP-7685: Return Engine API error code for invalid params (#1097)
* fix(tests): EIP-7685: Return Engine API error code for invalid params * chore(tests): improve fixture docstring * Update tests/prague/eip7685_general_purpose_el_requests/conftest.py Co-authored-by: danceratopz <[email protected]> --------- Co-authored-by: danceratopz <[email protected]>
1 parent 5e6a38e commit 00e8ce8

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

tests/prague/eip7685_general_purpose_el_requests/conftest.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
import pytest
66

77
from ethereum_test_forks import Fork
8-
from ethereum_test_tools import Alloc, Block, BlockException, Bytes, Header, Requests
8+
from ethereum_test_tools import (
9+
Alloc,
10+
Block,
11+
BlockException,
12+
Bytes,
13+
EngineAPIError,
14+
Header,
15+
Requests,
16+
)
917

1018
from ..eip6110_deposits.helpers import DepositInteractionBase, DepositRequest
1119
from ..eip7002_el_triggerable_withdrawals.helpers import (
@@ -50,6 +58,26 @@ def exception() -> BlockException | None:
5058
return None
5159

5260

61+
@pytest.fixture
62+
def engine_api_error_code(
63+
block_body_override_requests: List[Bytes | SupportsBytes] | None,
64+
) -> EngineAPIError | None:
65+
"""Engine API error code if any."""
66+
if block_body_override_requests is None:
67+
return None
68+
block_body_override_requests_bytes = [bytes(r) for r in block_body_override_requests]
69+
if any(len(r) <= 1 for r in block_body_override_requests_bytes):
70+
return EngineAPIError.InvalidParams
71+
72+
def is_monotonically_increasing(requests: List[bytes]) -> bool:
73+
return all(x[0] < y[0] for x, y in zip(requests, requests[1:], strict=False))
74+
75+
if not is_monotonically_increasing(block_body_override_requests_bytes):
76+
return EngineAPIError.InvalidParams
77+
78+
return None
79+
80+
5381
@pytest.fixture
5482
def blocks(
5583
fork: Fork,
@@ -59,10 +87,11 @@ def blocks(
5987
| WithdrawalRequestInteractionBase
6088
| ConsolidationRequestInteractionBase
6189
],
62-
block_body_override_requests: (List[Bytes | SupportsBytes] | None),
90+
block_body_override_requests: List[Bytes | SupportsBytes] | None,
6391
block_body_extra_requests: List[SupportsBytes],
6492
correct_requests_hash_in_header: bool,
6593
exception: BlockException | None,
94+
engine_api_error_code: EngineAPIError | None,
6695
) -> List[Block]:
6796
"""List of blocks that comprise the test."""
6897
valid_requests_list: List[DepositRequest | WithdrawalRequest | ConsolidationRequest] = []
@@ -95,5 +124,6 @@ def blocks(
95124
requests=block_body_override_requests,
96125
exception=exception,
97126
rlp_modifier=rlp_modifier,
127+
engine_api_error_code=engine_api_error_code,
98128
)
99129
]

tests/prague/eip7685_general_purpose_el_requests/test_deposits_withdrawals_consolidations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ def invalid_requests_block_combinations(fork: Fork) -> List[Any]:
331331
332332
In the event of a new request type, the `all_request_types` dictionary should be updated
333333
with the new request type and its corresponding request-generating transaction.
334+
335+
Returned parameters are: requests, block_body_override_requests, exception
334336
"""
335337
assert fork.max_request_type() == 2, "Test update is needed for new request types"
336338

tests/prague/eip7685_general_purpose_el_requests/test_request_types.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929

3030
@pytest.fixture
3131
def block_body_extra_requests(fork: Fork, invalid_request_data: bytes) -> List[bytes]:
32-
"""List of requests that overwrite the requests in the header. None by default."""
32+
"""
33+
Create a request with an invalid type for the fork.
34+
35+
This overrides the default fixture and its behavior defined in conftest.py.
36+
"""
3337
invalid_request_type = fork.max_request_type() + 1
3438
return [bytes([invalid_request_type]) + invalid_request_data]
3539

0 commit comments

Comments
 (0)