diff --git a/pytest-execute-hive.ini b/pytest-execute-hive.ini index cbb20237947..271cf346974 100644 --- a/pytest-execute-hive.ini +++ b/pytest-execute-hive.ini @@ -14,6 +14,7 @@ addopts = -p pytest_plugins.solc.solc -p pytest_plugins.execute.rpc.hive -p pytest_plugins.execute.execute + -p pytest_plugins.logging.logging -p pytest_plugins.shared.execute_fill -p pytest_plugins.forks.forks -p pytest_plugins.pytest_hive.pytest_hive diff --git a/pytest-execute.ini b/pytest-execute.ini index 527959bd872..803de23fe39 100644 --- a/pytest-execute.ini +++ b/pytest-execute.ini @@ -14,6 +14,7 @@ addopts = -p pytest_plugins.execute.pre_alloc -p pytest_plugins.solc.solc -p pytest_plugins.execute.execute + -p pytest_plugins.logging.logging -p pytest_plugins.shared.execute_fill -p pytest_plugins.execute.rpc.remote_seed_sender -p pytest_plugins.execute.rpc.remote diff --git a/pytest.ini b/pytest.ini index 95aab37d542..8255fb4f988 100644 --- a/pytest.ini +++ b/pytest.ini @@ -15,6 +15,7 @@ addopts = -p pytest_plugins.filler.filler -p pytest_plugins.filler.static_filler -p pytest_plugins.filler.ported_tests + -p pytest_plugins.logging.logging -p pytest_plugins.shared.execute_fill -p pytest_plugins.forks.forks -p pytest_plugins.eels_resolver diff --git a/src/ethereum_test_rpc/rpc.py b/src/ethereum_test_rpc/rpc.py index 9ebdf5ea972..2576abdd282 100644 --- a/src/ethereum_test_rpc/rpc.py +++ b/src/ethereum_test_rpc/rpc.py @@ -1,7 +1,9 @@ """JSON-RPC methods and helper functions for EEST consume based hive simulators.""" +import logging import time from itertools import count +from pathlib import Path from pprint import pprint from typing import Any, ClassVar, Dict, List, Literal, Union @@ -11,6 +13,7 @@ from ethereum_test_base_types import Address, Bytes, Hash, to_json from ethereum_test_types import Transaction +from pytest_plugins.logging import get_logger from .types import ( ForkchoiceState, @@ -24,6 +27,7 @@ ) BlockNumberType = Union[int, Literal["latest", "earliest", "pending"]] +logger = get_logger(__name__) class SendTransactionExceptionError(Exception): @@ -43,7 +47,28 @@ def __str__(self): if self.tx is not None: f"{super().__str__()} Transaction={self.tx.model_dump_json()}" elif self.tx_rlp is not None: - return f"{super().__str__()} Transaction RLP={self.tx_rlp.hex()}" + tx_rlp_hex_full = self.tx_rlp.hex() + # always log shortened errors to console (even when debugging read full from log file) + tx_rlp_hex = tx_rlp_hex_full[:50] + + # create ./logs/rlp folder if it does not exist already + rlp_logs_folder = Path(".") / "logs" / "rlp" + rlp_logs_folder.mkdir(parents=True, exist_ok=True) + + # create and config a temporary logger that logs to file + timestamp = time.time_ns() + file_name = rlp_logs_folder / f"{timestamp}_rlp_data.log" + temp_logger = logging.getLogger(f"rlp_{timestamp}") + temp_logger.propagate = False + file_handler = logging.FileHandler(file_name) + temp_logger.addHandler(file_handler) + # log rlp to file + temp_logger.error(tx_rlp_hex_full) + # cleanup + temp_logger.removeHandler(file_handler) + file_handler.close() + + return f"{super().__str__()} Transaction RLP={tx_rlp_hex}" return super().__str__()