Skip to content

Suggestions for: feat(consume): add ExceptionMapper support to the consume-engine simulator #1464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
43 changes: 34 additions & 9 deletions src/pytest_plugins/consume/hive_simulators/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def pytest_addoption(parser):
dest="disable_strict_exception_matching",
default="",
help=(
"Comma-separated list of the names of clients which should NOT use strict "
"Comma-separated list of client names and/or forks which should NOT use strict "
"exception matching."
),
)
Expand Down Expand Up @@ -208,20 +208,31 @@ def buffered_genesis(client_genesis: dict) -> io.BufferedReader:
return io.BufferedReader(cast(io.RawIOBase, io.BytesIO(genesis_bytes)))


@pytest.fixture(scope="session")
def client_exception_mapper_cache():
"""Cache for exception mappers by client type."""
return {}


@pytest.fixture(scope="function")
def client_exception_mapper(
client_type: ClientType,
client_type: ClientType, client_exception_mapper_cache
) -> ExceptionMapper | None:
"""Return the exception mapper for the client type."""
for client in EXCEPTION_MAPPERS:
if client in client_type.name:
return EXCEPTION_MAPPERS[client]
return None
"""Return the exception mapper for the client type, with caching."""
if client_type.name not in client_exception_mapper_cache:
for client in EXCEPTION_MAPPERS:
if client in client_type.name:
client_exception_mapper_cache[client_type.name] = EXCEPTION_MAPPERS[client]
break
else:
client_exception_mapper_cache[client_type.name] = None

return client_exception_mapper_cache[client_type.name]


@pytest.fixture(scope="session")
def disable_strict_exception_matching(request: pytest.FixtureRequest) -> List[str]:
"""Return the list of clients that should NOT use strict exception matching."""
"""Return the list of clients or forks that should NOT use strict exception matching."""
config_string = request.config.getoption("disable_strict_exception_matching")
return config_string.split(",") if config_string else []

Expand All @@ -232,7 +243,21 @@ def client_strict_exception_matching(
disable_strict_exception_matching: List[str],
) -> bool:
"""Return True if the client type should use strict exception matching."""
return not any(client in client_type.name for client in disable_strict_exception_matching)
return not any(
client.lower() in client_type.name.lower() for client in disable_strict_exception_matching
)


@pytest.fixture(scope="function")
def fork_strict_exception_matching(
fixture: BlockchainFixtureCommon,
disable_strict_exception_matching: List[str],
) -> bool:
"""Return True if the fork should use strict exception matching."""
# NOTE: `in` makes it easier for transition forks ("Prague" in "CancunToPragueAtTime15k")
return not any(
fork.lower() in fixture.fork.lower() for fork in disable_strict_exception_matching
)


@pytest.fixture(scope="function")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def test_blockchain_via_engine(
engine_rpc: EngineRPC,
fixture: BlockchainEngineFixture,
client_strict_exception_matching: bool,
fork_strict_exception_matching: bool,
):
"""
1. Check the client genesis block hash matches `fixture.genesis.block_hash`.
Expand Down Expand Up @@ -115,11 +116,15 @@ def test_blockchain_via_engine(
f'got: "{payload_response.validation_error}" '
f'expected: "{payload.validation_error}"'
)
if client_strict_exception_matching:
if (
not client_strict_exception_matching
or not fork_strict_exception_matching
):
logger.warning(message)
else:
logger.fail(message)
raise Exception(message)
else:
logger.warning(message)

except JSONRPCError as e:
logger.info(f"JSONRPC error encountered: {e.code} - {e.message}")
if payload.error_code is None:
Expand Down
Loading