11"""JSON-RPC methods and helper functions for EEST consume based hive simulators."""
22
3+ import logging
34import time
45from itertools import count
6+ from pathlib import Path
57from pprint import pprint
68from typing import Any , ClassVar , Dict , List , Literal , Union
79
1113
1214from ethereum_test_base_types import Address , Bytes , Hash , to_json
1315from ethereum_test_types import Transaction
16+ from pytest_plugins .logging import get_logger
1417
1518from .types import (
1619 ForkchoiceState ,
2427)
2528
2629BlockNumberType = Union [int , Literal ["latest" , "earliest" , "pending" ]]
30+ logger = get_logger (__name__ )
2731
2832
2933class SendTransactionExceptionError (Exception ):
@@ -43,7 +47,28 @@ def __str__(self):
4347 if self .tx is not None :
4448 f"{ super ().__str__ ()} Transaction={ self .tx .model_dump_json ()} "
4549 elif self .tx_rlp is not None :
46- return f"{ super ().__str__ ()} Transaction RLP={ self .tx_rlp .hex ()} "
50+ tx_rlp_hex_full = self .tx_rlp .hex ()
51+ # always log shortened errors to console (even when debugging read full from log file)
52+ tx_rlp_hex = tx_rlp_hex_full [:50 ]
53+
54+ # create ./logs/rlp folder if it does not exist already
55+ rlp_logs_folder = Path ("." ) / "logs" / "rlp"
56+ rlp_logs_folder .mkdir (parents = True , exist_ok = True )
57+
58+ # create and config a temporary logger that logs to file
59+ timestamp = time .time_ns ()
60+ file_name = rlp_logs_folder / f"{ timestamp } _rlp_data.log"
61+ temp_logger = logging .getLogger (f"rlp_{ timestamp } " )
62+ temp_logger .propagate = False
63+ file_handler = logging .FileHandler (file_name )
64+ temp_logger .addHandler (file_handler )
65+ # log rlp to file
66+ temp_logger .error (tx_rlp_hex_full )
67+ # cleanup
68+ temp_logger .removeHandler (file_handler )
69+ file_handler .close ()
70+
71+ return f"{ super ().__str__ ()} Transaction RLP={ tx_rlp_hex } "
4772 return super ().__str__ ()
4873
4974
0 commit comments