Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/testing/src/execution_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
FrameStatus,
GasFee,
NetworkWrappedTransaction,
OmissionClaim,
Removable,
SystemContractInteractionBase,
SystemContractInteractionContract,
Expand Down Expand Up @@ -160,6 +161,7 @@
)

__all__ = (
"OmissionClaim",
"DETERMINISTIC_FACTORY_ADDRESS",
"AccessList",
"Account",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
EngineRPC,
EthRPC,
ForkchoiceUpdateTimeoutError,
SendTransactionExceptionError,
)
from execution_testing.rpc.rpc_types import (
ForkchoiceState,
JSONRPCError,
PayloadStatusEnum,
)
from execution_testing.test_types import TransactionType

from ..helpers.exceptions import (
GenesisBlockMismatchExceptionError,
Expand Down Expand Up @@ -73,6 +75,8 @@ def test_blockchain_via_engine(
done once per client and skipped for later tests in the group.
3. Execute test fixture blocks using engine_newPayloadVX.
4. For valid payloads, send FCU to advance the chain head.
5. If the head carries an inclusion list verdict, check the list the
client builds with `engine_getInclusionListVX`.

A client's bad-block cache persists across the tests of a pre-alloc
group in enginex mode: a block that an earlier test already got
Expand Down Expand Up @@ -148,6 +152,17 @@ def test_blockchain_via_engine(
*payload.params,
version=payload.new_payload_version,
)
if (
payload.new_payload_version >= 6
and payload.inclusion_list_satisfied is not None
):
payload_response = (
engine_rpc.wait_for_inclusion_list(
payload_response,
*payload.params,
version=payload.new_payload_version,
)
)
status = payload_response.status
logger.info(f"Payload response status: {status}")
expected_validity = (
Expand All @@ -160,6 +175,35 @@ def test_blockchain_via_engine(
f"unexpected status: want {expected_validity},"
f" got {payload_response.status}"
)
response_ils = (
payload_response.inclusion_list_satisfied
)
if not payload.valid():
# `PayloadStatusV2` requires a null
# `inclusionListSatisfied` unless the payload
# is deemed VALID, and no earlier payload
# status carries the field at all.
if response_ils is not None:
raise LoggedError(
"expected null "
"`inclusionListSatisfied` on a payload "
f"not deemed VALID, got {response_ils}"
)
elif payload.inclusion_list_satisfied is not None:
if response_ils is None:
raise LoggedError(
"expected `inclusion_list_satisfied` in "
"response."
)
if (
payload.inclusion_list_satisfied
!= response_ils
):
raise LoggedError(
f"unexpected inclusion list satisfied: "
f"want {payload.inclusion_list_satisfied},"
f" got {response_ils}"
)
if payload.error_code is not None:
raise LoggedError(
"Client failed to raise expected Engine API "
Expand Down Expand Up @@ -230,4 +274,80 @@ def test_blockchain_via_engine(
f"unexpected status: want "
f"{PayloadStatusEnum.VALID}, got {status}"
)
if (
payload.inclusion_list_satisfied is not None
and len(payload.params) == 5
):
fcu_status = forkchoice_response.payload_status
fcu_ils = fcu_status.inclusion_list_satisfied
# The client must evaluate the retained
# inclusion lists when the forkchoice head is
# deemed VALID.
if fcu_ils is None:
raise LoggedError(
"expected `inclusionListSatisfied` in "
"forkchoice response."
)
if payload.inclusion_list_satisfied != fcu_ils:
raise LoggedError(
f"unexpected inclusion list satisfied "
f"in forkchoice response: want "
f"{payload.inclusion_list_satisfied}, "
f"got {fcu_ils}"
)
logger.info("All payloads processed successfully.")

head_payload = next(
(p for p in reversed(fixture.payloads) if p.valid()), None
)
if (
head_payload is not None
and head_payload.inclusion_list_satisfied is not None
):
head = head_payload.params[0]
head_fork = fixture.fork.fork_at(
block_number=head.number, timestamp=head.timestamp
)
il_version = head_fork.engine_get_inclusion_list_version()
size_limit = head_fork.inclusion_list_transactions_size_limit()
assert il_version is not None and size_limit is not None
with timing_data.time(f"engine_getInclusionListV{il_version}"):
if head_payload.inclusion_list_satisfied is False:
# The unsatisfied list holds a transaction still appendable
# on the head state, so the client has a candidate to pick.
# The list sits after the requests; omission claims, when
# present, follow it. The length check is for mypy
# narrowing.
if len(head_payload.params) == 6:
inclusion_list_param = list(
dict.fromkeys(
tx for il in head_payload.params[4] for tx in il
)
)
elif len(head_payload.params) == 5:
inclusion_list_param = head_payload.params[4]
else:
inclusion_list_param = []
for raw_tx in inclusion_list_param:
try:
eth_rpc.send_raw_transaction(raw_tx)
except SendTransactionExceptionError:
# Entries may be deliberately invalid.
pass
logger.info(f"Sending engine_getInclusionListV{il_version}...")
inclusion_list = engine_rpc.get_inclusion_list(version=il_version)
# Which transactions to pick is up to the client; only the
# list's form is specified.
transactions_size = sum(len(entry) for entry in inclusion_list)
if transactions_size > size_limit:
raise LoggedError(
f"inclusion list transactions total {transactions_size} "
f"bytes, over the {size_limit}-byte limit"
)
for entry in inclusion_list:
if len(entry) == 0:
raise LoggedError("empty inclusion list entry")
if entry[0] == TransactionType.BLOB_TRANSACTION:
raise LoggedError(
f"blob transaction in inclusion list: {entry.hex()}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,32 @@ def _finalize_payload(
block_number=payload.execution_payload.number,
timestamp=payload.execution_payload.timestamp,
)
# This chain builder supplies an empty selected inclusion list in
# PayloadAttributes. Retain the builder's exact committed claims.
if payload_fork.engine_new_payload_omission_claims():
if payload.omission_claims is None:
raise ValueError("getPayloadV7 must return omission claims")
new_payload_args.extend(
[[[] for _ in range(16)], payload.omission_claims]
)
elif payload_fork.engine_new_payload_inclusion_list_transactions():
new_payload_args.append([])
new_payload_version = payload_fork.engine_new_payload_version()
assert new_payload_version is not None, (
"Fork does not support engine new_payload"
)
new_payload_response = self.engine_rpc.new_payload(
*new_payload_args, version=new_payload_version
)
if payload_fork.engine_new_payload_omission_claims():
new_payload_response = self.engine_rpc.wait_for_inclusion_list(
new_payload_response,
*new_payload_args,
version=new_payload_version,
)
assert new_payload_response.inclusion_list_satisfied is True, (
"Built payload did not satisfy its inclusion list"
)
assert new_payload_response.status == PayloadStatusEnum.VALID, (
"Payload was invalid"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from execution_testing import (
Alloc,
Block,
BlockException,
BlockchainTestFiller,
Fork,
Transaction,
Expand Down Expand Up @@ -84,6 +85,13 @@ def invalid_tx() -> Transaction:
"[Block(txs=[valid_tx()]), "
"Block(txs=[valid_tx(), invalid_tx()], exception=INVALID)]"
)
# No transaction left at the end of the chain to move into the inclusion list.
EMPTY_LAST_BLOCK = "[Block(txs=[valid_tx()]), Block(txs=[])]"
# A last block that stays invalid once its last transaction is moved out.
BLOCK_EXCEPTION_ONLY = (
"[Block(txs=[valid_tx()]), Block(txs=[valid_tx()], "
"exception=BlockException.INCORRECT_BLOCK_FORMAT)]"
)


def write_test_module(
Expand Down Expand Up @@ -159,6 +167,39 @@ def test_misplaced_invalid_tx_is_rejected(
)


@pytest.mark.parametrize(
"blocks,expected_message",
[
pytest.param(
EMPTY_LAST_BLOCK,
"needs a transaction at the end of its last block",
id="empty_last_block",
),
pytest.param(
BLOCK_EXCEPTION_ONLY,
"but it declares only block exceptions",
id="block_exception_only",
),
],
)
def test_last_block_the_variant_cannot_use_is_rejected(
pytester: pytest.Pytester,
blocks: str,
expected_message: str,
) -> None:
"""
Fill an inclusion test whose last block cannot become the valid block the
inclusion-list variant expects, and assert it fails naming the reason.
"""
module_path = write_test_module(pytester, INCLUSION_TEST_MARKERS, blocks)

result = run_fill(pytester, module_path)

result.assert_outcomes(passed=0, failed=1)
output = "\n".join(result.outlines + result.errlines)
assert expected_message in output, output


@pytest.mark.parametrize(
"markers,blocks",
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
from execution_testing.client_clis.clis.execution_specs import (
ExecutionSpecsTransitionTool,
)
from execution_testing.fixtures import (
FixtureFillingPhase,
LabeledFixtureFormat,
)
from execution_testing.fixtures import FixtureFillingPhase
from execution_testing.forks import (
BPO1,
BPO2,
Expand Down Expand Up @@ -67,15 +64,10 @@ def test_all_forks({StateTest.pytest_parameter_name()}):
stdout = "\n".join(result.stdout.lines)
for test_fork in forks_under_test:
for fixture_format in STATE_TEST_FILL_FORMATS:
if isinstance(fixture_format, LabeledFixtureFormat):
# Keep the label: its `supports_fork` may veto forks the
# wrapped format supports, and the filler honors the label.
fixture_format_label = fixture_format.label
else:
fixture_format_label = fixture_format.format_name.lower()
fixture_format_label = fixture_format.format_id()
if (
not fixture_format.supports_fork(test_fork)
or "blockchain_test_engine_x" in fixture_format_label
or FixtureFillingPhase.FILL not in fixture_format.format_phases
):
expected_passed -= 1
assert (
Expand Down Expand Up @@ -124,15 +116,10 @@ def test_all_forks({StateTest.pytest_parameter_name()}):
stdout = "\n".join(result.stdout.lines)
for test_fork in forks_under_test:
for fixture_format in STATE_TEST_FILL_FORMATS:
if isinstance(fixture_format, LabeledFixtureFormat):
# Keep the label: its `supports_fork` may veto forks the
# wrapped format supports, and the filler honors the label.
fixture_format_label = fixture_format.label
else:
fixture_format_label = fixture_format.format_name.lower()
fixture_format_label = fixture_format.format_id()
if (
not fixture_format.supports_fork(test_fork)
or "blockchain_test_engine_x" in fixture_format_label
or FixtureFillingPhase.FILL not in fixture_format.format_phases
):
expected_passed -= 1
assert (
Expand Down Expand Up @@ -191,15 +178,10 @@ def test_all_forks({StateTest.pytest_parameter_name()}):
expected_passed -= len(STATE_TEST_FILL_FORMATS)
for test_fork in forks_under_test:
for fixture_format in STATE_TEST_FILL_FORMATS:
if isinstance(fixture_format, LabeledFixtureFormat):
# Keep the label: its `supports_fork` may veto forks the
# wrapped format supports, and the filler honors the label.
fixture_format_label = fixture_format.label
else:
fixture_format_label = fixture_format.format_name.lower()
fixture_format_label = fixture_format.format_id()
if (
not fixture_format.supports_fork(test_fork)
or "blockchain_test_engine_x" in fixture_format_label
or FixtureFillingPhase.FILL not in fixture_format.format_phases
):
expected_passed -= 1
assert (
Expand Down Expand Up @@ -249,15 +231,10 @@ def test_all_forks({StateTest.pytest_parameter_name()}):

for test_fork in forks_under_test:
for fixture_format in STATE_TEST_FILL_FORMATS:
if isinstance(fixture_format, LabeledFixtureFormat):
# Keep the label: its `supports_fork` may veto forks the
# wrapped format supports, and the filler honors the label.
fixture_format_label = fixture_format.label
else:
fixture_format_label = fixture_format.format_name.lower()
fixture_format_label = fixture_format.format_id()
if (
not fixture_format.supports_fork(test_fork)
or "blockchain_test_engine_x" in fixture_format_label
or FixtureFillingPhase.FILL not in fixture_format.format_phases
):
expected_passed -= 1
assert (
Expand Down
Loading