Skip to content

Commit 297322f

Browse files
new(tests): EIP-7251: add modified consolidation contract test cases (#1465)
* adds modified consolidation contract like previously done with withdrawal * removed geas created bytecode tests * fixed function name * docs: changelog --------- Co-authored-by: Mario Vega <[email protected]>
1 parent 8666e45 commit 297322f

File tree

3 files changed

+133
-74
lines changed

3 files changed

+133
-74
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Test fixtures for use by clients are available for each release on the [Github r
2626
-[EIP-7702](https://eips.ethereum.org/EIPS/eip-7702): Add invalid nonce authorizations tests for the case of multiple signers when the sender's nonce gets increased ([#1441](https://github.com/ethereum/execution-spec-tests/pull/1441)).
2727
-[EIP-7702](https://eips.ethereum.org/EIPS/eip-7702): Add a test that verifies that set code transactions are correctly rejected before Prague activation ([#1463](https://github.com/ethereum/execution-spec-tests/pull/1463)).
2828
-[EIP-7623](https://eips.ethereum.org/EIPS/eip-7623): Additionally parametrize transaction validity tests with the `to` set to an EOA account (previously only contracts) ([#1422](https://github.com/ethereum/execution-spec-tests/pull/1422)).
29+
-[EIP-7251](https://eips.ethereum.org/EIPS/eip-7251): Add EIP-7251 test cases for modified consolidations contract that allows more consolidations ([#1465](https://github.com/ethereum/execution-spec-tests/pull/1465)).
2930
-[EIP-6110](https://eips.ethereum.org/EIPS/eip-6110): Add extra deposit request edge cases, sending eth to the deposit contract while sending a deposit request ([#1467](https://github.com/ethereum/execution-spec-tests/pull/1467)).
3031
-[EIP-7251](https://eips.ethereum.org/EIPS/eip-7251): Remove pytest skips for consolidation request cases ([#1449](https://github.com/ethereum/execution-spec-tests/pull/1449)).
3132

tests/prague/eip7002_el_triggerable_withdrawals/test_modified_withdrawal_contract.py

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
from .helpers import (
2424
WithdrawalRequest,
25-
# WithdrawalRequestBase,
26-
# WithdrawalRequestContract,
2725
WithdrawalRequestTransaction,
2826
)
2927
from .spec import Spec as Spec_EIP7002
@@ -89,78 +87,6 @@ def test_extra_withdrawals(
8987
blockchain_test: BlockchainTestFiller,
9088
pre: Alloc,
9189
requests_list: List[WithdrawalRequest],
92-
):
93-
"""Test how clients were to behave when more than 16 withdrawals (here: 18 withdrawals) would be allowed per block.""" # noqa: E501
94-
# Source of code (change value of this line to 18 and re-compile with fjl/geas): https://github.com/lightclient/sys-asm/blob/f1c13e285b6aeef2b19793995e00861bf0f32c9a/src/withdrawals/main.eas#L37 # noqa: E501, W291
95-
modified_code: bytes = b"3373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060121160df575060125b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd" # noqa: E501
96-
pre[Spec_EIP7002.WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS] = Account(
97-
code=modified_code,
98-
nonce=1,
99-
balance=0,
100-
)
101-
102-
# given a list of withdrawal requests construct a withdrawal request transaction
103-
withdrawal_request_transaction = WithdrawalRequestTransaction(requests=requests_list)
104-
# prepare withdrawal senders
105-
withdrawal_request_transaction.update_pre(pre=pre)
106-
# get transaction list
107-
txs: List[Transaction] = withdrawal_request_transaction.transactions()
108-
109-
blockchain_test(
110-
pre=pre,
111-
blocks=[
112-
Block(
113-
txs=txs,
114-
requests_hash=Requests(*requests_list),
115-
),
116-
],
117-
post={},
118-
)
119-
120-
121-
@pytest.mark.parametrize(
122-
"requests_list",
123-
[
124-
pytest.param(
125-
[],
126-
id="empty_request_list",
127-
),
128-
pytest.param(
129-
[
130-
*withdrawal_list_with_custom_fee(1),
131-
],
132-
id="1_withdrawal_request",
133-
),
134-
pytest.param(
135-
[
136-
*withdrawal_list_with_custom_fee(15),
137-
],
138-
id="15_withdrawal_requests",
139-
),
140-
pytest.param(
141-
[
142-
*withdrawal_list_with_custom_fee(16),
143-
],
144-
id="16_withdrawal_requests",
145-
),
146-
pytest.param(
147-
[
148-
*withdrawal_list_with_custom_fee(17),
149-
],
150-
id="17_withdrawal_requests",
151-
),
152-
pytest.param(
153-
[
154-
*withdrawal_list_with_custom_fee(18),
155-
],
156-
id="18_withdrawal_requests",
157-
),
158-
],
159-
)
160-
def test_extra_withdrawals_pseudo_contract(
161-
blockchain_test: BlockchainTestFiller,
162-
pre: Alloc,
163-
requests_list: List[WithdrawalRequest],
16490
):
16591
"""Test how clients were to behave when more than 16 withdrawals would be allowed per block."""
16692
modified_code: Bytecode = Bytecode()
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
"""
2+
abstract: Tests [EIP-7251: Execution layer triggerable consolidation](https://eips.ethereum.org/EIPS/eip-7251)
3+
Test execution layer triggered exits [EIP-7251: Execution layer triggerable consolidation](https://eips.ethereum.org/EIPS/eip-7251).
4+
5+
""" # noqa: E501
6+
7+
from typing import List
8+
9+
import pytest
10+
11+
from ethereum_test_tools import (
12+
Account,
13+
Alloc,
14+
Block,
15+
BlockchainTestFiller,
16+
Bytecode,
17+
Transaction,
18+
)
19+
from ethereum_test_tools import Macros as Om
20+
from ethereum_test_tools import Opcodes as Op
21+
from ethereum_test_types import Requests
22+
23+
from .helpers import (
24+
ConsolidationRequest,
25+
ConsolidationRequestTransaction,
26+
)
27+
from .spec import Spec as Spec_EIP7251
28+
from .spec import ref_spec_7251
29+
30+
REFERENCE_SPEC_GIT_PATH: str = ref_spec_7251.git_path
31+
REFERENCE_SPEC_VERSION: str = ref_spec_7251.version
32+
33+
pytestmark: pytest.MarkDecorator = pytest.mark.valid_from("Prague")
34+
35+
36+
def consolidation_list_with_custom_fee(n: int) -> List[ConsolidationRequest]: # noqa: D103
37+
return [
38+
ConsolidationRequest(
39+
source_pubkey=0x01,
40+
target_pubkey=0x02,
41+
fee=Spec_EIP7251.get_fee(10),
42+
)
43+
for i in range(n)
44+
]
45+
46+
47+
@pytest.mark.parametrize(
48+
"requests_list",
49+
[
50+
pytest.param(
51+
[],
52+
id="empty_request_list",
53+
),
54+
pytest.param(
55+
[
56+
*consolidation_list_with_custom_fee(1),
57+
],
58+
id="1_consolidation_request",
59+
),
60+
pytest.param(
61+
[
62+
*consolidation_list_with_custom_fee(2),
63+
],
64+
id="2_consolidation_requests",
65+
),
66+
pytest.param(
67+
[
68+
*consolidation_list_with_custom_fee(3),
69+
],
70+
id="3_consolidation_requests",
71+
),
72+
pytest.param(
73+
[
74+
*consolidation_list_with_custom_fee(4),
75+
],
76+
id="4_consolidation_requests",
77+
),
78+
pytest.param(
79+
[
80+
*consolidation_list_with_custom_fee(5),
81+
],
82+
id="5_consolidation_requests",
83+
),
84+
],
85+
)
86+
def test_extra_consolidations(
87+
blockchain_test: BlockchainTestFiller,
88+
pre: Alloc,
89+
requests_list: List[ConsolidationRequest],
90+
):
91+
"""Test how clients were to behave with more than 2 consolidations per block."""
92+
modified_code: Bytecode = Bytecode()
93+
memory_offset: int = 0
94+
amount_of_requests: int = 0
95+
96+
for consolidation_request in requests_list:
97+
# update memory_offset with the correct value
98+
consolidation_request_bytes_amount: int = len(bytes(consolidation_request))
99+
assert consolidation_request_bytes_amount == 116, (
100+
"Expected consolidation request to be of size 116 but got size "
101+
f"{consolidation_request_bytes_amount}"
102+
)
103+
memory_offset += consolidation_request_bytes_amount
104+
105+
modified_code += Om.MSTORE(bytes(consolidation_request), memory_offset)
106+
amount_of_requests += 1
107+
108+
modified_code += Op.RETURN(0, Op.MSIZE())
109+
110+
pre[Spec_EIP7251.CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS] = Account(
111+
code=modified_code,
112+
nonce=1,
113+
balance=0,
114+
)
115+
116+
# given a list of consolidation requests construct a consolidation request transaction
117+
consolidation_request_transaction = ConsolidationRequestTransaction(requests=requests_list)
118+
# prepare consolidation senders
119+
consolidation_request_transaction.update_pre(pre=pre)
120+
# get transaction list
121+
txs: List[Transaction] = consolidation_request_transaction.transactions()
122+
123+
blockchain_test(
124+
pre=pre,
125+
blocks=[
126+
Block(
127+
txs=txs,
128+
requests_hash=Requests(*requests_list),
129+
),
130+
],
131+
post={},
132+
)

0 commit comments

Comments
 (0)