Skip to content

Commit

Permalink
fix(tests): EIP-7002,EIP-7251: keep producing empty blocks to exhaust…
Browse files Browse the repository at this point in the history
… queues
  • Loading branch information
marioevz committed Jun 26, 2024
1 parent 8370070 commit cf2ba90
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 42 deletions.
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
23 changes: 19 additions & 4 deletions tests/prague/eip7251_consolidations/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Fixtures for the EIP-7251 consolidations tests.
"""
from itertools import zip_longest
from typing import List

import pytest
Expand Down Expand Up @@ -57,6 +58,14 @@ def included_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


Expand All @@ -69,10 +78,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_consolidation_requests,
included_requests,
fillvalue=[],
)
for i, block_requests in enumerate(blocks_consolidation_requests)
]
] + [
Block(header_verify=Header(requests_root=[]))
] # Add an empty block at the end to verify that no more consolidation requests are included
55 changes: 33 additions & 22 deletions tests/prague/eip7251_consolidations/test_consolidations.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@
],
id="single_block_single_consolidation_request_from_eoa_equal_pubkeys",
),
pytest.param(
[
[
ConsolidationRequestTransaction(
requests=[
ConsolidationRequest(
source_pubkey=-1,
target_pubkey=-2,
fee=Spec.get_fee(0),
)
],
),
],
],
id="single_block_single_consolidation_request_from_eoa_max_pubkeys",
),
pytest.param(
[
[
Expand All @@ -80,6 +96,7 @@
source_pubkey=0x01,
target_pubkey=0x02,
fee=0,
valid=False,
)
],
),
Expand Down Expand Up @@ -184,6 +201,9 @@
)
],
],
marks=pytest.mark.skip(
reason="duplicate test due to MAX_CONSOLIDATION_REQUESTS_PER_BLOCK==1"
),
id="single_block_max_consolidation_requests_from_eoa",
),
pytest.param(
Expand Down Expand Up @@ -278,7 +298,6 @@
),
pytest.param(
[
# Block 1
[
ConsolidationRequestTransaction(
requests=[
Expand All @@ -287,14 +306,10 @@
target_pubkey=i * 2 + 1,
fee=Spec.get_fee(0),
)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 2)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
]
)
],
# Block 2, no new consolidation requests, but queued requests from previous block
[],
# Block 3, no new nor queued consolidation requests
[],
],
id="multiple_block_above_max_consolidation_requests_from_eoa",
),
Expand Down Expand Up @@ -324,9 +339,7 @@
target_pubkey=i * 2 + 1,
fee=Spec.get_fee(0),
)
for i in range(
Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK
) # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
],
),
],
Expand All @@ -350,9 +363,7 @@
target_pubkey=i * 2 + 1,
fee=Spec.get_fee(0),
)
for i in range(
1, Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK
) # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
for i in range(1, Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
],
),
],
Expand All @@ -369,15 +380,15 @@
target_pubkey=i * 2 + 1,
fee=Spec.get_fee(0),
)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK - 1)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
]
+ [
ConsolidationRequest(
source_pubkey=-1,
target_pubkey=-2,
fee=0,
)
], # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
],
),
],
],
Expand All @@ -404,9 +415,9 @@
fee=Spec.get_fee(0),
valid=True,
)
for i in range(1, Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK)
for i in range(1, Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
],
), # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
),
],
],
id="single_block_multiple_consolidation_requests_from_contract_first_oog",
Expand All @@ -423,7 +434,7 @@
gas_limit=1_000_000,
valid=True,
)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
]
+ [
ConsolidationRequest(
Expand All @@ -434,7 +445,7 @@
valid=False,
)
],
), # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
),
],
],
id="single_block_multiple_consolidation_requests_from_contract_last_oog",
Expand All @@ -450,11 +461,11 @@
fee=Spec.get_fee(0),
valid=False,
)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
],
extra_code=Op.REVERT(0, 0),
),
], # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
],
],
id="single_block_multiple_consolidation_requests_from_contract_caller_reverts",
),
Expand All @@ -469,10 +480,10 @@
fee=Spec.get_fee(0),
valid=False,
)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK)
for i in range(Spec.MAX_CONSOLIDATION_REQUESTS_PER_BLOCK * 5)
],
extra_code=Macros.OOG(),
), # TODO: MAX_CONSOLIDATION_REQUESTS_PER_BLOCK not ideal
),
],
],
id="single_block_multiple_consolidation_requests_from_contract_caller_oog",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,10 @@ def test_valid_deposit_withdrawal_consolidation_request_from_same_tx(
contract_code += Op.SSTORE(
storage.store_next(1),
Op.CALL(
Op.GAS,
call_contract_address,
value,
0,
len(current_calldata),
0,
0,
address=call_contract_address,
value=value,
args_offset=0,
args_size=len(current_calldata),
),
)

Expand Down
1 change: 1 addition & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ extcodehash
extcodesize
F00
filesystem
fillvalue
firstlineno
fn
fname
Expand Down

0 comments on commit cf2ba90

Please sign in to comment.