From 5fd988094fc1d6b27f8ac0c276e1d09f0c8830db Mon Sep 17 00:00:00 2001 From: Mario Vega Date: Fri, 4 Oct 2024 23:55:08 +0000 Subject: [PATCH] fix(tests): Requests tests --- tests/prague/eip6110_deposits/conftest.py | 16 +++++++++++++--- .../conftest.py | 19 ++++++++++++++++--- .../prague/eip7251_consolidations/conftest.py | 19 ++++++++++++++++--- .../conftest.py | 10 ++++++++-- ...est_deposits_withdrawals_consolidations.py | 15 ++++++++++----- .../eip7702_set_code_tx/test_set_code_txs.py | 7 ++++++- 6 files changed, 69 insertions(+), 17 deletions(-) diff --git a/tests/prague/eip6110_deposits/conftest.py b/tests/prague/eip6110_deposits/conftest.py index 4f1f986f4b..681c3ac26d 100644 --- a/tests/prague/eip6110_deposits/conftest.py +++ b/tests/prague/eip6110_deposits/conftest.py @@ -5,7 +5,8 @@ import pytest -from ethereum_test_tools import Alloc, Block, BlockException, Header, Transaction +from ethereum_test_forks import Fork +from ethereum_test_tools import Alloc, Block, BlockException, Header, Requests, Transaction from .helpers import DepositInteractionBase, DepositRequest @@ -61,6 +62,7 @@ def included_requests( @pytest.fixture def blocks( + fork: Fork, included_requests: List[DepositRequest], block_body_override_requests: List[DepositRequest] | None, txs: List[Transaction], @@ -71,9 +73,17 @@ def blocks( Block( txs=txs, header_verify=Header( - requests_hash=included_requests, + requests_hash=Requests( + *included_requests, + max_request_type=fork.max_request_type(block_number=1, timestamp=1), + ), ), - requests=block_body_override_requests, + requests=Requests( + *block_body_override_requests, + max_request_type=fork.max_request_type(block_number=1, timestamp=1), + ).requests_list + if block_body_override_requests + else None, exception=exception, ) ] diff --git a/tests/prague/eip7002_el_triggerable_withdrawals/conftest.py b/tests/prague/eip7002_el_triggerable_withdrawals/conftest.py index 18b3adceb7..5fb7e6fa35 100644 --- a/tests/prague/eip7002_el_triggerable_withdrawals/conftest.py +++ b/tests/prague/eip7002_el_triggerable_withdrawals/conftest.py @@ -6,7 +6,8 @@ import pytest -from ethereum_test_tools import Alloc, Block, Header +from ethereum_test_forks import Fork +from ethereum_test_tools import Alloc, Block, Header, Requests from .helpers import WithdrawalRequest, WithdrawalRequestInteractionBase from .spec import Spec @@ -70,6 +71,7 @@ def included_requests( @pytest.fixture def blocks( + fork: Fork, update_pre: None, # Fixture is used for its side effects blocks_withdrawal_requests: List[List[WithdrawalRequestInteractionBase]], included_requests: List[List[WithdrawalRequest]], @@ -80,7 +82,12 @@ def blocks( return [ # type: ignore Block( txs=sum((r.transactions() for r in block_requests), []), - header_verify=Header(requests_hash=block_included_requests), + header_verify=Header( + requests_hash=Requests( + *block_included_requests, + max_request_type=fork.max_request_type(block_number=1, timestamp=1), + ) + ), ) for block_requests, block_included_requests in zip_longest( blocks_withdrawal_requests, @@ -88,5 +95,11 @@ def blocks( fillvalue=[], ) ] + [ - Block(header_verify=Header(requests_hash=[])) + Block( + header_verify=Header( + requests_hash=Requests( + max_request_type=fork.max_request_type(block_number=1, timestamp=1) + ) + ) + ) ] # Add an empty block at the end to verify that no more withdrawal requests are included diff --git a/tests/prague/eip7251_consolidations/conftest.py b/tests/prague/eip7251_consolidations/conftest.py index a822ee9463..c893129144 100644 --- a/tests/prague/eip7251_consolidations/conftest.py +++ b/tests/prague/eip7251_consolidations/conftest.py @@ -6,7 +6,8 @@ import pytest -from ethereum_test_tools import Alloc, Block, Header +from ethereum_test_forks import Fork +from ethereum_test_tools import Alloc, Block, Header, Requests from .helpers import ConsolidationRequest, ConsolidationRequestInteractionBase from .spec import Spec @@ -71,6 +72,7 @@ def included_requests( @pytest.fixture def blocks( + fork: Fork, update_pre: None, # Fixture is used for its side effects blocks_consolidation_requests: List[List[ConsolidationRequestInteractionBase]], included_requests: List[List[ConsolidationRequest]], @@ -81,7 +83,12 @@ def blocks( return [ # type: ignore Block( txs=sum((r.transactions() for r in block_requests), []), - header_verify=Header(requests_hash=block_included_requests), + header_verify=Header( + requests_hash=Requests( + *block_included_requests, + max_request_type=fork.max_request_type(block_number=1, timestamp=1), + ) + ), ) for block_requests, block_included_requests in zip_longest( blocks_consolidation_requests, @@ -89,5 +96,11 @@ def blocks( fillvalue=[], ) ] + [ - Block(header_verify=Header(requests_hash=[])) + Block( + header_verify=Header( + requests_hash=Requests( + max_request_type=fork.max_request_type(block_number=1, timestamp=1) + ) + ) + ) ] # Add an empty block at the end to verify that no more consolidation requests are included diff --git a/tests/prague/eip7685_general_purpose_el_requests/conftest.py b/tests/prague/eip7685_general_purpose_el_requests/conftest.py index 11a971324b..0c145b2d6c 100644 --- a/tests/prague/eip7685_general_purpose_el_requests/conftest.py +++ b/tests/prague/eip7685_general_purpose_el_requests/conftest.py @@ -6,7 +6,8 @@ import pytest -from ethereum_test_tools import Alloc, Block, BlockException, Header +from ethereum_test_forks import Fork +from ethereum_test_tools import Alloc, Block, BlockException, Header, Requests from ..eip6110_deposits.helpers import DepositInteractionBase, DepositRequest from ..eip7002_el_triggerable_withdrawals.helpers import ( @@ -41,12 +42,14 @@ def exception() -> BlockException | None: @pytest.fixture def blocks( + fork: Fork, pre: Alloc, requests: List[ DepositInteractionBase | WithdrawalRequestInteractionBase | ConsolidationRequestInteractionBase ], + # TODO: Not as easy as the other EIPs to refactor block_body_override_requests: List[ DepositRequest | WithdrawalRequest | ConsolidationRequest | SupportsBytes ] @@ -78,7 +81,10 @@ def blocks( Block( txs=sum((r.transactions() for r in requests), []), header_verify=Header( - requests_hash=valid_requests, + requests_hash=Requests( + *valid_requests, + max_request_type=fork.max_request_type(block_number=1, timestamp=1), + ), ), requests=block_body_override_requests, exception=exception, diff --git a/tests/prague/eip7685_general_purpose_el_requests/test_deposits_withdrawals_consolidations.py b/tests/prague/eip7685_general_purpose_el_requests/test_deposits_withdrawals_consolidations.py index 623199b911..0e9f50dca7 100644 --- a/tests/prague/eip7685_general_purpose_el_requests/test_deposits_withdrawals_consolidations.py +++ b/tests/prague/eip7685_general_purpose_el_requests/test_deposits_withdrawals_consolidations.py @@ -9,6 +9,7 @@ import pytest +from ethereum_test_forks import Fork from ethereum_test_tools import ( Account, Address, @@ -21,7 +22,7 @@ Header, ) from ethereum_test_tools import Opcodes as Op -from ethereum_test_tools import Storage, TestAddress, TestAddress2, Transaction +from ethereum_test_tools import Requests, Storage, TestAddress, TestAddress2, Transaction from ..eip6110_deposits.helpers import DepositContract, DepositRequest, DepositTransaction from ..eip6110_deposits.spec import Spec as Spec_EIP6110 @@ -239,6 +240,7 @@ def test_valid_deposit_withdrawal_consolidation_request_from_same_tx( blockchain_test: BlockchainTestFiller, pre: Alloc, requests: List[DepositRequest | WithdrawalRequest | ConsolidationRequest], + fork: Fork, ): """ Test making a deposit to the beacon chain deposit contract and a withdrawal in the same tx. @@ -307,10 +309,13 @@ def test_valid_deposit_withdrawal_consolidation_request_from_same_tx( Block( txs=[tx], header_verify=Header( - requests_hash=[ - request.with_source_address(contract_address) - for request in sorted(requests, key=lambda r: r.type_byte) - ] + requests_hash=Requests( + *[ + request.with_source_address(contract_address) + for request in sorted(requests, key=lambda r: r.type) + ], + max_request_type=fork.max_request_type(block_number=1, timestamp=1), + ) ), ) ], diff --git a/tests/prague/eip7702_set_code_tx/test_set_code_txs.py b/tests/prague/eip7702_set_code_tx/test_set_code_txs.py index 95cc10685f..a2c67e9eee 100644 --- a/tests/prague/eip7702_set_code_tx/test_set_code_txs.py +++ b/tests/prague/eip7702_set_code_tx/test_set_code_txs.py @@ -11,6 +11,7 @@ import pytest from ethereum_test_addresses import SystemContract +from ethereum_test_forks import Fork from ethereum_test_tools import ( AccessList, Account, @@ -31,6 +32,7 @@ from ethereum_test_tools import Macros as Om from ethereum_test_tools import Opcodes as Op from ethereum_test_tools import ( + Requests, StateTestFiller, Storage, Transaction, @@ -2422,6 +2424,7 @@ def deposit_contract_initial_storage() -> Storage: def test_set_code_to_system_contract( blockchain_test: BlockchainTestFiller, pre: Alloc, + fork: Fork, system_contract: int, call_opcode: Op, ): @@ -2527,7 +2530,9 @@ def test_set_code_to_system_contract( blocks=[ Block( txs=txs, - requests_hash=[], # Verify nothing slipped into the requests trie + requests_hash=Requests( + max_request_type=fork.max_request_type(block_number=1) + ), # Verify nothing slipped into the requests trie ) ], post={