Skip to content

Commit b001dfa

Browse files
committed
improved rlp error logging: less verbose in console + persist full logs when error occurs
1 parent 64f949d commit b001dfa

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

pytest-execute-hive.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ addopts =
1414
-p pytest_plugins.solc.solc
1515
-p pytest_plugins.execute.rpc.hive
1616
-p pytest_plugins.execute.execute
17+
-p pytest_plugins.logging.logging
1718
-p pytest_plugins.shared.execute_fill
1819
-p pytest_plugins.forks.forks
1920
-p pytest_plugins.pytest_hive.pytest_hive

pytest-execute.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ addopts =
1414
-p pytest_plugins.execute.pre_alloc
1515
-p pytest_plugins.solc.solc
1616
-p pytest_plugins.execute.execute
17+
-p pytest_plugins.logging.logging
1718
-p pytest_plugins.shared.execute_fill
1819
-p pytest_plugins.execute.rpc.remote_seed_sender
1920
-p pytest_plugins.execute.rpc.remote

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ addopts =
1515
-p pytest_plugins.filler.filler
1616
-p pytest_plugins.filler.static_filler
1717
-p pytest_plugins.filler.ported_tests
18+
-p pytest_plugins.logging.logging
1819
-p pytest_plugins.shared.execute_fill
1920
-p pytest_plugins.forks.forks
2021
-p pytest_plugins.eels_resolver

src/ethereum_test_rpc/rpc.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""JSON-RPC methods and helper functions for EEST consume based hive simulators."""
22

3+
import logging
34
import time
45
from itertools import count
6+
from pathlib import Path
57
from pprint import pprint
68
from typing import Any, ClassVar, Dict, List, Literal, Union
79

@@ -11,6 +13,7 @@
1113

1214
from ethereum_test_base_types import Address, Bytes, Hash, to_json
1315
from ethereum_test_types import Transaction
16+
from pytest_plugins.logging import get_logger
1417

1518
from .types import (
1619
ForkchoiceState,
@@ -24,6 +27,7 @@
2427
)
2528

2629
BlockNumberType = Union[int, Literal["latest", "earliest", "pending"]]
30+
logger = get_logger(__name__)
2731

2832

2933
class 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

Comments
 (0)