Skip to content

Commit

Permalink
fix(tests): Requests tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Oct 4, 2024
1 parent bf902b8 commit 77b36d1
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 17 deletions.
16 changes: 13 additions & 3 deletions tests/prague/eip6110_deposits/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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],
Expand All @@ -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,
)
]
19 changes: 16 additions & 3 deletions tests/prague/eip7002_el_triggerable_withdrawals/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]],
Expand All @@ -80,13 +82,24 @@ 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,
included_requests,
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
19 changes: 16 additions & 3 deletions tests/prague/eip7251_consolidations/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]],
Expand All @@ -81,13 +83,24 @@ 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,
included_requests,
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
10 changes: 8 additions & 2 deletions tests/prague/eip7685_general_purpose_el_requests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
]
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import pytest

from ethereum_test_forks import Fork
from ethereum_test_tools import (
Account,
Address,
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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),
)
),
)
],
Expand Down
7 changes: 6 additions & 1 deletion tests/prague/eip7702_set_code_tx/test_set_code_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
):
Expand Down Expand Up @@ -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={
Expand Down

0 comments on commit 77b36d1

Please sign in to comment.