Skip to content

Commit

Permalink
Better handling of tx_hash in assert_transaction_success_with_explana…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
miohtama committed Aug 14, 2024
1 parent 26714b2 commit e7077a2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions eth_defi/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def print_symbolic_trace(

def assert_transaction_success_with_explanation(
web3: Web3,
tx_hash: HexBytes,
tx_hash: HexBytes | str,
RaisedException=TransactionAssertionError,
tracing: bool = False,
) -> TxReceipt:
Expand Down Expand Up @@ -300,6 +300,9 @@ def assert_transaction_success_with_explanation(
Output transaction receipt if no error is raised
"""

if type(tx_hash) == str:
tx_hash = HexBytes(tx_hash)

receipt = web3.eth.wait_for_transaction_receipt(tx_hash)
if receipt["status"] == 0:
# Explain why the transaction failed
Expand All @@ -316,7 +319,7 @@ def assert_transaction_success_with_explanation(
solidity_stack_trace=trace_output,
)
else:
raise RaisedException(f"Transaction failed: {tx_details} - tracing disabled")
raise RaisedException(f"Transaction {tx_hash.hex()} failed: {tx_details} - tracing disabled")

return receipt

Expand Down

0 comments on commit e7077a2

Please sign in to comment.