Skip to content

Commit

Permalink
feat: log print and console.log calls made during transactions (#1930)
Browse files Browse the repository at this point in the history
* feat: log print and console.log calls made during transactions

* refactor: improve contract check before calling log_print()

* fix: import TypeGuard from typing_extensions for 3.8 support

* fix: is_contract only available on Address model

* fix: python 3.8 typing is bleh, fix import of Iterable

* fix: unintended edit

* fix: fail gracefully when provider does not implement get_call_tree

* feat: adds post transaction hook to Web3Provider

* refactor: adds ReceiptAPI.debug_logs prop and ReceiptAPI.print_debug_logs()

* fix: bad string formatting

* refactor: clarity, simplicity, and support recursive call tree walking

* fix: manhandle the type checker

* feat: pre-cache console contract for call trace beautification

* fix: cast CONSOLE_CONTRACT_ID as ChecksumAddress

* style: cleanup debugging noise

* docs: update ape_ethereum._print's docstring header for clarity

* refactor: print_debug_logs -> show_debug_logs

* refactor: use DEBUG-LOG as logging prefix

* refactor: split debug_logs into debug_logs_lines and debug_logs_typed

* fix: unusual generator behavior

* test: add tests for debug logs

* style: lint

* chore(debug): instrumentation to debug CI tests

* feat: log print and console.log calls made during transactions

* refactor: improve contract check before calling log_print()

* fix: import TypeGuard from typing_extensions for 3.8 support

* fix: is_contract only available on Address model

* fix: python 3.8 typing is bleh, fix import of Iterable

* fix: unintended edit

* fix: fail gracefully when provider does not implement get_call_tree

* feat: adds post transaction hook to Web3Provider

* refactor: adds ReceiptAPI.debug_logs prop and ReceiptAPI.print_debug_logs()

* fix: bad string formatting

* refactor: clarity, simplicity, and support recursive call tree walking

* fix: manhandle the type checker

* feat: pre-cache console contract for call trace beautification

* fix: cast CONSOLE_CONTRACT_ID as ChecksumAddress

* style: cleanup debugging noise

* docs: update ape_ethereum._print's docstring header for clarity

* refactor: print_debug_logs -> show_debug_logs

* refactor: use DEBUG-LOG as logging prefix

* refactor: split debug_logs into debug_logs_lines and debug_logs_typed

* fix: unusual generator behavior

* test: add tests for debug logs

* style: lint

* chore(debug): instrumentation to debug CI tests

* Revert "chore(debug): instrumentation to debug CI tests"

This reverts commit 6edd31b.

* fix: do not use assertion errors for logic branching

* style: fstring > +

Co-authored-by: antazoey <yingthi@live.com>

* docs(style): .

Co-authored-by: antazoey <yingthi@live.com>

* style: cleanup of debug statements

---------

Co-authored-by: antazoey <yingthi@live.com>
  • Loading branch information
mikeshultz and antazoey authored Mar 8, 2024
1 parent 39d7a67 commit a8d1487
Show file tree
Hide file tree
Showing 8 changed files with 4,452 additions and 7 deletions.
21 changes: 20 additions & 1 deletion src/ape/api/transactions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import time
from datetime import datetime
from typing import IO, TYPE_CHECKING, Any, Iterator, List, NoReturn, Optional, Union
from typing import IO, TYPE_CHECKING, Any, Iterator, List, NoReturn, Optional, Tuple, Union

from eth_pydantic_types import HexBytes
from eth_utils import is_0x_prefixed, is_hex, to_int
Expand Down Expand Up @@ -294,6 +294,25 @@ def validate_txn_hash(cls, value):
def call_tree(self) -> Optional[Any]:
return None

@cached_property
def debug_logs_typed(self) -> List[Tuple[Any]]:
"""Return any debug log data outputted by the transaction."""
return []

@cached_property
def debug_logs_lines(self) -> List[str]:
"""
Return any debug log data outputted by the transaction as strings suitable for printing
"""
return [" ".join(map(str, ln)) for ln in self.debug_logs_typed]

def show_debug_logs(self):
"""
Output debug logs to logging system
"""
for ln in self.debug_logs_lines:
logger.info(f"[DEBUG-LOG] {ln}")

@property
def failed(self) -> bool:
"""
Expand Down
Loading

0 comments on commit a8d1487

Please sign in to comment.