Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/core/providers/test_wait_for_tx_receipt_hexstr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from hexbytes import HexBytes
import pytest
from web3 import Web3
from web3.exceptions import TimeExhausted

def _send_dummy_tx(w3: Web3):
a0, a1 = w3.eth.accounts[:2]
tx_hash = w3.eth.send_transaction({"from": a0, "to": a1, "value": 1})
return tx_hash

def test_wait_for_tx_receipt_accepts_hex_string_success():
w3 = Web3(Web3.EthereumTesterProvider())
tx_hash = _send_dummy_tx(w3)
tx_hash_hexstr = tx_hash.hex()

receipt = w3.eth.wait_for_transaction_receipt(tx_hash_hexstr, timeout=60)
assert receipt is not None
assert receipt["transactionHash"] in (tx_hash, HexBytes(tx_hash_hexstr))

def test_wait_for_tx_receipt_accepts_hex_string_timeout():
w3 = Web3(Web3.EthereumTesterProvider())

# Use a bogus tx hash (never mined) to force timeout
bogus_hex = "0x" + "00" * 32

# Very short timeout so it raises quickly
with pytest.raises(TimeExhausted):
w3.eth.wait_for_transaction_receipt(
bogus_hex,
timeout=0.1,
poll_latency=0.05,
)

26 changes: 26 additions & 0 deletions tests/providers/test_wait_for_tx_receipt_hexstr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from hexbytes import HexBytes
import pytest
from web3 import Web3
from web3.exceptions import TimeExhausted

def _send_dummy_tx(w3: Web3):
a0, a1 = w3.eth.accounts[:2]
tx_hash = w3.eth.send_transaction({"from": a0, "to": a1, "value": 1})
return tx_hash

def test_wait_for_tx_receipt_accepts_hex_string_success():
w3 = Web3(Web3.EthereumTesterProvider())
tx_hash = _send_dummy_tx(w3)
tx_hash_hexstr = tx_hash.hex()

receipt = w3.eth.wait_for_transaction_receipt(tx_hash_hexstr, timeout=60)
assert receipt is not None
assert receipt["transactionHash"] in (tx_hash, HexBytes(tx_hash_hexstr))

def test_wait_for_tx_receipt_accepts_hex_string_timeout():
w3 = Web3(Web3.EthereumTesterProvider())
tx_hash = _send_dummy_tx(w3)
tx_hash_hexstr = tx_hash.hex()

with pytest.raises(TimeExhausted):
w3.eth.wait_for_transaction_receipt(tx_hash_hexstr, timeout=0)