Skip to content

Commit

Permalink
Merge pull request #1896 from tmckenzie51/tiffany/waitForTransReceipt…
Browse files Browse the repository at this point in the history
…-to-snakecase

deprecate waitForTransactionReceipt in favor of snakecased wait_for_transaction_receipt
  • Loading branch information
tmckenzie51 authored Apr 2, 2021
2 parents 9611996 + 77345d7 commit 506a302
Show file tree
Hide file tree
Showing 32 changed files with 106 additions and 94 deletions.
14 changes: 7 additions & 7 deletions docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ To run this example, you will need to install a few extra features:
>>> tx_hash = Greeter.constructor().transact()
# Wait for the transaction to be mined, and get the transaction receipt
>>> tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
>>> tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
>>> greeter = w3.eth.contract(
... address=tx_receipt.contractAddress,
Expand All @@ -95,7 +95,7 @@ To run this example, you will need to install a few extra features:
'Hello'
>>> tx_hash = greeter.functions.setGreeting('Nihao').transact()
>>> tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
>>> tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
>>> greeter.functions.greet().call()
'Nihao'
Expand Down Expand Up @@ -686,7 +686,7 @@ Taking the following contract code as an example:
>>> ArraysContract = w3.eth.contract(abi=abi, bytecode=bytecode)

>>> tx_hash = ArraysContract.constructor([b'b']).transact()
>>> tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
>>> tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)

>>> array_contract = w3.eth.contract(
... address=tx_receipt.contractAddress,
Expand Down Expand Up @@ -1069,15 +1069,15 @@ Event Log Object
assert bob == '0x2B5AD5c4795c026514f8317c7a215E218DcCD6cF', bob
tx_hash = my_token_contract.constructor(1000000).transact({'from': alice, 'gas': 899000, 'gasPrice': 320000})
assert tx_hash == HexBytes('0x611aa2d5c3e51f08d0665c4529c5520ed32520d8a48ba2cf2aff3f2fce3f26e4'), tx_hash
txn_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
txn_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
assert txn_receipt['contractAddress'] == '0xF2E246BB76DF876Cef8b38ae84130F4F55De395b', txn_receipt['contractAddress']
contract_address = txn_receipt['contractAddress']
contract = w3.eth.contract(contract_address, abi=ABI)
total_supply = contract.functions.totalSupply().call()
decimals = 10 ** 18
assert total_supply == 1000000 * decimals, total_supply
tx_hash = contract.functions.transfer(alice, 10).transact({'gas': 899000, 'gasPrice': 200000})
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)

.. doctest:: createFilter

Expand All @@ -1096,7 +1096,7 @@ Event Log Object
>>> transfer_filter.get_new_entries()
[]
>>> tx_hash = contract.functions.transfer(alice, 10).transact({'gas': 899000, 'gasPrice': 200000})
>>> tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
>>> tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
>>> transfer_filter.get_new_entries()
[AttributeDict({'args': AttributeDict({'from': '0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf',
'to': '0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf',
Expand Down Expand Up @@ -1173,7 +1173,7 @@ For example:
ABI = json.loads('[{"constant":false,"inputs":[],"name":"return13","outputs":[{"name":"result","type":"int256"}],"type":"function"},{"constant":true,"inputs":[],"name":"counter","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"amt","type":"uint256"}],"name":"increment","outputs":[{"name":"result","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"a","type":"int256"},{"name":"b","type":"int256"}],"name":"add","outputs":[{"name":"result","type":"int256"}],"type":"function"},{"constant":false,"inputs":[],"name":"increment","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"a","type":"int256"}],"name":"multiply7","outputs":[{"name":"result","type":"int256"}],"type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"value","type":"uint256"}],"name":"increased","type":"event"}]')
contract = w3.eth.contract(abi=ABI, bytecode=bytecode)
deploy_txn = contract.constructor().transact()
deploy_receipt = w3.eth.waitForTransactionReceipt(deploy_txn)
deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn)
address = deploy_receipt.contractAddress

.. doctest:: contractcaller
Expand Down
4 changes: 2 additions & 2 deletions docs/ethpm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ LinkableContract
>>> # Deploy SafeSendLib
>>> SafeSendFactory = EscrowPackage.get_contract_factory("SafeSendLib")
>>> safe_send_tx_hash = SafeSendFactory.constructor().transact()
>>> safe_send_tx_receipt = w3.eth.waitForTransactionReceipt(safe_send_tx_hash)
>>> safe_send_tx_receipt = w3.eth.wait_for_transaction_receipt(safe_send_tx_hash)

>>> # Link Escrow factory to deployed SafeSendLib instance
>>> LinkedEscrowFactory = EscrowFactory.link_bytecode({"SafeSendLib": safe_send_tx_receipt.contractAddress})
>>> assert LinkedEscrowFactory.needs_bytecode_linking is False
>>> escrow_tx_hash = LinkedEscrowFactory.constructor(w3.eth.accounts[0]).transact()
>>> escrow_tx_receipt = w3.eth.waitForTransactionReceipt(escrow_tx_hash)
>>> escrow_tx_receipt = w3.eth.wait_for_transaction_receipt(escrow_tx_hash)
>>> assert is_address(escrow_tx_receipt.contractAddress)


Expand Down
12 changes: 6 additions & 6 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ The following example demonstrates a few things:
if gas_estimate < 100000:
print("Sending transaction to setVar(255)\n")
tx_hash = store_var_contract.functions.setVar(255).transact()
receipt = w3.eth.waitForTransactionReceipt(tx_hash)
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print("Transaction receipt mined:")
pprint.pprint(dict(receipt))
print("\nWas transaction successful?")
Expand Down Expand Up @@ -466,7 +466,7 @@ contract which conforms to this standard.
assert bob == '0x2B5AD5c4795c026514f8317c7a215E218DcCD6cF', bob
tx_hash = factory.constructor(1000000).transact({'from': alice, 'gas': 899000, 'gasPrice': 320000})
assert tx_hash == HexBytes('0x611aa2d5c3e51f08d0665c4529c5520ed32520d8a48ba2cf2aff3f2fce3f26e4'), tx_hash
txn_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
txn_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
assert txn_receipt['contractAddress'] == '0xF2E246BB76DF876Cef8b38ae84130F4F55De395b', txn_receipt['contractAddress']
contract_address = txn_receipt['contractAddress']
contract = w3.eth.contract(contract_address, abi=ABI)
Expand Down Expand Up @@ -549,7 +549,7 @@ Next we can transfer some tokens from ``alice`` to ``bob`` using the contract's
.. doctest::

>>> tx_hash = contract.functions.transfer(bob, 100).transact({'from': alice})
>>> tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
>>> tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
>>> contract.functions.balanceOf(alice).call()
999999999999999999999900
>>> contract.functions.balanceOf(bob).call()
Expand All @@ -568,7 +568,7 @@ spend using the ``allowance`` function.
>>> contract.functions.allowance(alice, bob).call()
0
>>> tx_hash = contract.functions.approve(bob, 200).transact({'from': alice})
>>> tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
>>> tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
>>> contract.functions.allowance(alice, bob).call()
200

Expand All @@ -586,7 +586,7 @@ When someone has an allowance they can transfer those tokens using the
>>> contract.functions.balanceOf(bob).call()
100
>>> tx_hash = contract.functions.transferFrom(alice, bob, 75).transact({'from': bob})
>>> tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
>>> tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
>>> contract.functions.allowance(alice, bob).call()
125
>>> contract.functions.balanceOf(bob).call()
Expand Down Expand Up @@ -658,7 +658,7 @@ And finally, send the transaction
.. code-block:: python
txn_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
txn_receipt = w3.eth.waitForTransactionReceipt(txn_hash)
txn_receipt = w3.eth.wait_for_transaction_receipt(txn_hash)
Tip : afterwards you can use the value stored in ``txn_hash``, in an explorer like `etherscan`_ to view the transaction's details

Expand Down
4 changes: 2 additions & 2 deletions docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ API
- :meth:`web3.eth.send_raw_transaction() <web3.eth.Eth.send_raw_transaction>`
- :meth:`web3.eth.replace_transaction() <web3.eth.Eth.replace_transaction>`
- :meth:`web3.eth.modify_transaction() <web3.eth.Eth.modify_transaction>`
- :meth:`web3.eth.waitForTransactionReceipt() <web3.eth.Eth.waitForTransactionReceipt>`
- :meth:`web3.eth.wait_for_transaction_receipt() <web3.eth.Eth.wait_for_transaction_receipt>`
- :meth:`web3.eth.get_transaction_receipt() <web3.eth.Eth.get_transaction_receipt>`
- :meth:`web3.eth.sign() <web3.eth.Eth.sign>`
- :meth:`web3.eth.sign_typed_data() <web3.eth.Eth.sign_typed_data>`
Expand Down Expand Up @@ -205,7 +205,7 @@ instance of the contract:
>>> ExampleContract = w3.eth.contract(abi=abi, bytecode=bytecode)
>>> tx_hash = ExampleContract.constructor().transact()
>>> tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
>>> tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
>>> tx_receipt.contractAddress
'0x8a22225eD7eD460D7ee3842bce2402B9deaD23D3'
Expand Down
11 changes: 8 additions & 3 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -613,18 +613,18 @@ The following methods are available on the ``web3.eth`` namespace.
.. warning:: Deprecated: This method is deprecated in favor of
:attr:`~web3.eth.Eth.get_transaction_by_block`

.. py:method:: Eth.waitForTransactionReceipt(transaction_hash, timeout=120, poll_latency=0.1)
.. py:method:: Eth.wait_for_transaction_receipt(transaction_hash, timeout=120, poll_latency=0.1)
Waits for the transaction specified by ``transaction_hash`` to be included in a block, then
returns its transaction receipt.

Optionally, specify a ``timeout`` in seconds. If timeout elapses before the transaction
is added to a block, then :meth:`~Eth.waitForTransactionReceipt` raises a
is added to a block, then :meth:`~Eth.wait_for_transaction_receipt` raises a
:class:`web3.exceptions.TimeExhausted` exception.

.. code-block:: python
>>> web3.eth.waitForTransactionReceipt('0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060')
>>> web3.eth.wait_for_transaction_receipt('0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060')
# If transaction is not yet in a block, time passes, while the thread sleeps...
# ...
# Then when the transaction is added to a block, its receipt is returned:
Expand All @@ -644,6 +644,11 @@ The following methods are available on the ``web3.eth`` namespace.
})
.. py:method:: Eth.waitForTransactionReceipt(transaction_hash, timeout=120, poll_latency=0.1)
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.eth.Eth.wait_for_transaction_receipt()`

.. py:method:: Eth.get_transaction_receipt(transaction_hash)
* Delegates to ``eth_getTransactionReceipt`` RPC Method
Expand Down
1 change: 1 addition & 0 deletions newsfragments/1896.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``w3.eth.wait_for_transaction_receipt`` deprecate ``w3.eth.waitForTransactionReceipt``
4 changes: 2 additions & 2 deletions tests/core/contracts/test_concise_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
def deploy(web3, Contract, args=None):
args = args or []
deploy_txn = Contract.constructor(*args).transact()
deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
deploy_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
contract = Contract(address=deploy_receipt['contractAddress'])
assert len(web3.eth.get_code(contract.address)) > 0
Expand All @@ -35,7 +35,7 @@ def zero_address_contract(web3, WithConstructorAddressArgumentsContract, EMPTY_A
deploy_txn = WithConstructorAddressArgumentsContract.constructor(
EMPTY_ADDR,
).transact()
deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
deploy_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
_address_contract = WithConstructorAddressArgumentsContract(
address=deploy_receipt['contractAddress'],
Expand Down
2 changes: 1 addition & 1 deletion tests/core/contracts/test_contract_ambiguous_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@pytest.fixture()
def string_contract(web3, StringContract, address_conversion_func):
deploy_txn = StringContract.constructor("Caqalai").transact()
deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
deploy_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
contract_address = address_conversion_func(deploy_receipt['contractAddress'])
contract = StringContract(address=contract_address)
Expand Down
6 changes: 3 additions & 3 deletions tests/core/contracts/test_contract_buildTransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@pytest.fixture()
def math_contract(web3, MathContract, address_conversion_func):
deploy_txn = MathContract.constructor().transact()
deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
deploy_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
math_contract_address = address_conversion_func(deploy_receipt['contractAddress'])
_math_contract = MathContract(address=math_contract_address)
Expand All @@ -25,7 +25,7 @@ def math_contract(web3, MathContract, address_conversion_func):
@pytest.fixture()
def fallback_function_contract(web3, FallbackFunctionContract, address_conversion_func):
deploy_txn = FallbackFunctionContract.constructor().transact()
deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
deploy_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
fallback_contract_address = address_conversion_func(deploy_receipt['contractAddress'])
_fallback_contract = FallbackFunctionContract(address=fallback_contract_address)
Expand All @@ -36,7 +36,7 @@ def fallback_function_contract(web3, FallbackFunctionContract, address_conversio
@pytest.fixture()
def payable_tester_contract(web3, PayableTesterContract, address_conversion_func):
deploy_txn = PayableTesterContract.constructor().transact()
deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
deploy_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
payable_tester_address = address_conversion_func(deploy_receipt['contractAddress'])
_payable_tester = PayableTesterContract(address=payable_tester_address)
Expand Down
4 changes: 2 additions & 2 deletions tests/core/contracts/test_contract_call_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
def deploy(web3, Contract, apply_func=identity, args=None):
args = args or []
deploy_txn = Contract.constructor(*args).transact()
deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
deploy_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
address = apply_func(deploy_receipt['contractAddress'])
contract = Contract(address=address)
Expand Down Expand Up @@ -159,7 +159,7 @@ def undeployed_math_contract(web3, MathContract, address_conversion_func):
@pytest.fixture()
def mismatched_math_contract(web3, StringContract, MathContract, address_conversion_func):
deploy_txn = StringContract.constructor("Caqalai").transact()
deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
deploy_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
address = address_conversion_func(deploy_receipt['contractAddress'])
_mismatched_math_contract = MathContract(address=address)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/contracts/test_contract_caller_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def deploy(web3, Contract, apply_func=identity, args=None):
args = args or []
deploy_txn = Contract.constructor(*args).transact()
deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
deploy_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert deploy_receipt is not None
address = apply_func(deploy_receipt['contractAddress'])
contract = Contract(address=address)
Expand Down
18 changes: 9 additions & 9 deletions tests/core/contracts/test_contract_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_contract_constructor_gas_estimate_no_constructor(web3, MathContract):
gas_estimate = MathContract.constructor().estimateGas()

deploy_txn = MathContract.constructor().transact()
txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
txn_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
gas_used = txn_receipt.get('gasUsed')

assert abs(gas_estimate - gas_used) < 21000
Expand All @@ -29,7 +29,7 @@ def test_contract_constructor_gas_estimate_with_block_id(web3, MathContract):
block_identifier = None
gas_estimate = MathContract.constructor().estimateGas(block_identifier=block_identifier)
deploy_txn = MathContract.constructor().transact()
txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
txn_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
gas_used = txn_receipt.get('gasUsed')

assert abs(gas_estimate - gas_used) < 21000
Expand All @@ -41,7 +41,7 @@ def test_contract_constructor_gas_estimate_with_constructor_without_arguments(
gas_estimate = SimpleConstructorContract.constructor().estimateGas()

deploy_txn = SimpleConstructorContract.constructor().transact()
txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
txn_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
gas_used = txn_receipt.get('gasUsed')

assert abs(gas_estimate - gas_used) < 21000
Expand All @@ -66,7 +66,7 @@ def test_contract_constructor_gas_estimate_with_constructor_with_arguments(

deploy_txn = WithConstructorArgumentsContract.constructor(
*constructor_args, **constructor_kwargs).transact()
txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
txn_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
gas_used = txn_receipt.get('gasUsed')

assert abs(gas_estimate - gas_used) < 21000
Expand All @@ -81,7 +81,7 @@ def test_contract_constructor_gas_estimate_with_constructor_with_address_argumen

deploy_txn = WithConstructorAddressArgumentsContract.constructor(
address_conversion_func("0x16D9983245De15E7A9A73bC586E01FF6E08dE737")).transact()
txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
txn_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
gas_used = txn_receipt.get('gasUsed')

assert abs(gas_estimate - gas_used) < 21000
Expand All @@ -94,7 +94,7 @@ def test_contract_constructor_transact_no_constructor(
address_conversion_func):
deploy_txn = MathContract.constructor().transact()

txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
txn_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert txn_receipt is not None

assert txn_receipt['contractAddress']
Expand All @@ -111,7 +111,7 @@ def test_contract_constructor_transact_with_constructor_without_arguments(
address_conversion_func):
deploy_txn = SimpleConstructorContract.constructor().transact()

txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
txn_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert txn_receipt is not None

assert txn_receipt['contractAddress']
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_contract_constructor_transact_with_constructor_with_arguments(
deploy_txn = WithConstructorArgumentsContract.constructor(
*constructor_args, **constructor_kwargs).transact()

txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
txn_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert txn_receipt is not None

assert txn_receipt['contractAddress']
Expand All @@ -162,7 +162,7 @@ def test_contract_constructor_transact_with_constructor_with_address_arguments(
WITH_CONSTRUCTOR_ADDRESS_RUNTIME,
address_conversion_func):
deploy_txn = WithConstructorAddressArgumentsContract.constructor(TEST_ADDRESS).transact()
txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
txn_receipt = web3.eth.wait_for_transaction_receipt(deploy_txn)
assert txn_receipt is not None
assert txn_receipt['contractAddress']
contract_address = address_conversion_func(txn_receipt['contractAddress'])
Expand Down
Loading

0 comments on commit 506a302

Please sign in to comment.