diff --git a/packages/testing/src/execution_testing/cli/gentest/source_code_generator.py b/packages/testing/src/execution_testing/cli/gentest/source_code_generator.py index 7f316cbd08..ecbed9150e 100644 --- a/packages/testing/src/execution_testing/cli/gentest/source_code_generator.py +++ b/packages/testing/src/execution_testing/cli/gentest/source_code_generator.py @@ -89,7 +89,6 @@ def format_code(code: str) -> str: str(formatter_path), "format", str(input_file_path), - "--quiet", "--no-cache", "--config", str(config_path), @@ -100,7 +99,8 @@ def format_code(code: str) -> str: if result.returncode != 0: raise Exception( f"Error formatting code using formatter '{formatter_path}': " - f"{result.stderr}" + f"returncode={result.returncode}, stdout={result.stdout!r}, " + f"stderr={result.stderr!r}" ) # Return the formatted source code 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 0245581e62..aa4ef542fb 100644 --- a/packages/testing/src/execution_testing/test_types/transaction_types.py +++ b/packages/testing/src/execution_testing/test_types/transaction_types.py @@ -3,6 +3,7 @@ from dataclasses import dataclass from enum import IntEnum from functools import cached_property +import numbers from typing import Any, ClassVar, Dict, Generic, List, Literal, Self, Sequence import ethereum_rlp as eth_rlp @@ -842,6 +843,47 @@ def signer_minimum_balance(self, *, fork: Fork) -> int: else: return gas_price * gas_limit + self.value + def _format_field_value(self, value: Any) -> str: + """ + Format a field value for string representation. + + Uses decimal for numeric values (int, HexNumber, etc.) and + hex encoding for Address, Bytes, Hash, etc. + """ + if value is None: + return "None" + + # fields like 'value' should be shown as decimal number + if isinstance(value, numbers.Number): + # Force decimal representation for int subclasses like HexNumber + if isinstance(value, int): + return str(int(value)) + + return str(value) + + # fields like 'to' should be shown as hex string + if hasattr(value, "hex") and callable(value.hex): + return f'"{value.hex()}"' + + return repr(value) + + def __repr__(self) -> str: + """ + Return string representation with hex-encoded values for + applicable fields. + """ + field_strs = [] + for field_name in self.__class__.model_fields: + value = getattr(self, field_name) + formatted_value = self._format_field_value(value) + field_strs.append(f"{field_name}={formatted_value}") + + return f"{self.__class__.__name__}({', '.join(field_strs)})" + + def __str__(self) -> str: + """Return the repr string representation.""" + return self.__repr__() + class NetworkWrappedTransaction(CamelModel, RLPSerializable): """