diff --git a/packages/testing/src/execution_testing/test_types/transaction_types.py b/packages/testing/src/execution_testing/test_types/transaction_types.py index 77a0ba03bd..af387fa601 100644 --- a/packages/testing/src/execution_testing/test_types/transaction_types.py +++ b/packages/testing/src/execution_testing/test_types/transaction_types.py @@ -32,10 +32,10 @@ TestAddress, TestPrivateKey, ) +from execution_testing.exceptions import TransactionException from execution_testing.logging import ( get_logger, ) -from execution_testing.exceptions import TransactionException from .account_types import EOA from .blob_types import Blob @@ -725,6 +725,42 @@ def metadata_string(self) -> str | None: return None return self.metadata.to_json() + def _format_field_value(self, field_name: str, value: Any) -> str: + """ + Format a field value for string representation. + + Special handling for to, data, and sender fields to show hex encoding. + """ + if field_name in ("to", "data", "sender"): + if value is None: + return "None" + elif hasattr(value, "hex"): + return value.hex() + else: + return repr(value) + else: + return repr(value) + + def __repr__(self) -> str: + """ + Return string representation with hex-encoded values for to, data, and + sender fields. + """ + field_strs = [] + for field_name in self.model_fields: + value = getattr(self, field_name) + formatted_value = self._format_field_value(field_name, value) + field_strs.append(f"{field_name}={formatted_value}") + + return " ".join(field_strs) + + def __str__(self) -> str: + """ + Return string representation with hex-encoded values for to, data, and + sender fields. + """ + return self.__repr__() + @cached_property def hash(self) -> Hash: """Returns hash of the transaction."""