Skip to content

Commit 14990cb

Browse files
committed
snakecase EstimateGas to estimate_gas
1 parent b5ca8cb commit 14990cb

File tree

11 files changed

+60
-43
lines changed

11 files changed

+60
-43
lines changed

docs/contracts.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ Each Contract Factory exposes the following methods.
229229
will accept ENS names.
230230

231231
If a ``gas`` value is not provided, then the ``gas`` value for the
232-
deployment transaction will be created using the ``web3.eth.estimateGas()``
232+
deployment transaction will be created using the ``web3.eth.estimate_gas()``
233233
method.
234234

235235
Returns the transaction hash for the deploy transaction.
@@ -241,7 +241,7 @@ Each Contract Factory exposes the following methods.
241241
>>> txn_receipt['contractAddress']
242242
'0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318'
243243
244-
.. py:classmethod:: Contract.constructor(*args, **kwargs).estimateGas(transaction=None, block_identifier=None)
244+
.. py:classmethod:: Contract.constructor(*args, **kwargs).estimate_gas(transaction=None,block_identifier=None)
245245
246246
Estimate gas for constructing and deploying the contract.
247247

@@ -260,7 +260,7 @@ Each Contract Factory exposes the following methods.
260260

261261
.. code-block:: python
262262
263-
>>> token_contract.constructor(web3.eth.coinbase, 12345).estimateGas()
263+
>>> token_contract.constructor(web3.eth.coinbase, 12345).estimate_gas()
264264
12563
265265
266266
.. py:classmethod:: Contract.constructor(*args, **kwargs).buildTransaction(transaction=None)
@@ -343,7 +343,7 @@ Each Contract Factory exposes the following methods.
343343
will accept ENS names.
344344

345345
If a ``gas`` value is not provided, then the ``gas`` value for the
346-
deployment transaction will be created using the ``web3.eth.estimateGas()``
346+
deployment transaction will be created using the ``web3.eth.estimate_gas()``
347347
method.
348348

349349
Returns the transaction hash for the deploy transaction.
@@ -765,7 +765,7 @@ Methods
765765
will accept ENS names.
766766

767767
If a ``gas`` value is not provided, then the ``gas`` value for the
768-
method transaction will be created using the ``web3.eth.estimateGas()``
768+
method transaction will be created using the ``web3.eth.estimate_gas()``
769769
method.
770770

771771
Returns the transaction hash.
@@ -823,7 +823,7 @@ Methods
823823
# You can check the state after your pending transactions (if supported by your node):
824824
>>> token_contract.functions.myBalance().call(block_identifier='pending')
825825
826-
.. py:method:: ContractFunction.estimateGas(transaction, block_identifier=None)
826+
.. py:method:: ContractFunction.estimate_gas(transaction, block_identifier=None)
827827
828828
Call a contract function, executing the transaction locally using the
829829
``eth_call`` API. This will not create a new public transaction.
@@ -832,7 +832,7 @@ Methods
832832

833833
.. code-block:: python
834834
835-
myContract.functions.myMethod(*args, **kwargs).estimateGas(transaction)
835+
myContract.functions.myMethod(*args, **kwargs).estimate_gas(transaction)
836836
837837
This method behaves the same as the :py:meth:`ContractFunction.transact` method,
838838
with transaction details being passed into the end portion of the
@@ -843,7 +843,7 @@ Methods
843843

844844
.. code-block:: python
845845
846-
>>> my_contract.functions.multiply7(3).estimateGas()
846+
>>> my_contract.functions.multiply7(3).estimate_gas()
847847
42650
848848
849849
.. note::
@@ -912,7 +912,7 @@ Fallback Function
912912
Call fallback function, executing the transaction locally using the
913913
``eth_call`` API. This will not create a new public transaction.
914914

915-
.. py:method:: Contract.fallback.estimateGas(transaction)
915+
.. py:method:: Contract.fallback.estimate_gas(transaction)
916916
917917
Call fallback function and return the gas estimation.
918918

docs/examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ The following example demonstrates a few things:
333333
334334
store_var_contract = w3.eth.contract(address=address, abi=contract_interface["abi"])
335335
336-
gas_estimate = store_var_contract.functions.setVar(255).estimateGas()
336+
gas_estimate = store_var_contract.functions.setVar(255).estimate_gas()
337337
print(f'Gas estimate to transact with setVar: {gas_estimate}')
338338
339339
if gas_estimate < 100000:

docs/overview.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ API
179179
- :meth:`web3.eth.get_transaction_receipt() <web3.eth.Eth.get_transaction_receipt>`
180180
- :meth:`web3.eth.sign() <web3.eth.Eth.sign>`
181181
- :meth:`web3.eth.signTypedData() <web3.eth.Eth.signTypedData>`
182-
- :meth:`web3.eth.estimateGas() <web3.eth.Eth.estimateGas>`
182+
- :meth:`web3.eth.estimate_gas() <web3.eth.Eth.estimate_gas>`
183183
- :meth:`web3.eth.generateGasPrice() <web3.eth.Eth.generateGasPrice>`
184184
- :meth:`web3.eth.setGasPriceStrategy() <web3.eth.Eth.setGasPriceStrategy>`
185185

docs/web3.eth.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,9 @@ The following methods are available on the ``web3.eth`` namespace.
727727

728728
If the ``transaction`` specifies a ``data`` value but does not specify
729729
``gas`` then the ``gas`` value will be populated using the
730-
:meth:`~web3.eth.Eth.estimateGas()` function with an additional buffer of ``100000``
730+
:meth:`~web3.eth.Eth.estimate_gas()` function with an additional buffer of ``100000``
731731
gas up to the ``gasLimit`` of the latest block. In the event that the
732-
value returned by :meth:`~web3.eth.Eth.estimateGas()` method is greater than the
732+
value returned by :meth:`~web3.eth.Eth.estimate_gas()` method is greater than the
733733
``gasLimit`` a ``ValueError`` will be raised.
734734

735735

@@ -938,9 +938,9 @@ The following methods are available on the ``web3.eth`` namespace.
938938
In most cases it is better to make contract function call through the :py:class:`web3.contract.Contract` interface.
939939

940940

941-
.. py:method:: Eth.estimateGas(transaction, block_identifier=None)
941+
.. py:method:: Eth.estimate_gas(transaction, block_identifier=None)
942942
943-
* Delegates to ``eth_estimateGas`` RPC Method
943+
* Delegates to ``eth_estimate_gas`` RPC Method
944944

945945
Executes the given transaction locally without creating a new transaction
946946
on the blockchain. Returns amount of gas consumed by execution which can
@@ -951,14 +951,19 @@ The following methods are available on the ``web3.eth`` namespace.
951951

952952
.. code-block:: python
953953
954-
>>> web3.eth.estimateGas({'to': '0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'from': web3.eth.coinbase, 'value': 12345})
954+
>>> web3.eth.estimate_gas({'to': '0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'from':
955+
web3.eth.coinbase, 'value': 12345})
955956
21000
956957
957958
.. note::
958959
The parameter ``block_identifier`` is not enabled in geth nodes,
959960
hence passing a value of ``block_identifier`` when connected to a geth
960961
nodes would result in an error like: ``ValueError: {'code': -32602, 'message': 'too many arguments, want at most 1'}``
961962

963+
.. py:method:: Eth.estimateGas(transaction, block_identifier=None)
964+
965+
.. warning:: Deprecated: This property is deprecated in favor of
966+
:attr:`~web3.eth.Eth.estimate_gas()`
962967

963968
.. py:method:: Eth.generateGasPrice(transaction_params=None)
964969

tests/integration/go_ethereum/common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def test_eth_replace_transaction_already_mined(self, web3, unlocked_account_dual
3535
web3.geth.miner.stop()
3636

3737
@pytest.mark.xfail(reason='Block identifier has not been implemented in geth')
38-
def test_eth_estimateGas_with_block(self,
39-
web3,
40-
unlocked_account_dual_type):
41-
super().test_eth_estimateGas_with_block(
38+
def test_eth_estimate_gas_with_block(self,
39+
web3,
40+
unlocked_account_dual_type):
41+
super().test_eth_estimate_gas_with_block(
4242
web3, unlocked_account_dual_type
4343
)
4444

tests/integration/parity/common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def _check_web3_clientVersion(self, client_version):
2727

2828
class ParityEthModuleTest(EthModuleTest):
2929
@pytest.mark.xfail(reason='Parity returns a gas value even when a function will revert')
30-
def test_eth_estimateGas_revert_with_msg(self, web3, revert_contract, unlocked_account):
31-
super().test_eth_estimateGas_revert_with_msg(web3, revert_contract, unlocked_account)
30+
def test_eth_estimate_gas_revert_with_msg(self, web3, revert_contract, unlocked_account):
31+
super().test_eth_estimate_gas_revert_with_msg(web3, revert_contract, unlocked_account)
3232

33-
def test_eth_estimateGas_revert_without_msg(
33+
def test_eth_estimate_gas_revert_without_msg(
3434
self,
3535
web3,
3636
revert_contract,
@@ -44,7 +44,7 @@ def test_eth_estimateGas_revert_without_msg(
4444
"to": revert_contract.address,
4545
},
4646
)
47-
web3.eth.estimateGas(txn_params)
47+
web3.eth.estimate_gas(txn_params)
4848

4949
@pytest.mark.xfail(reason='Parity dropped "pending" option in 1.11.1')
5050
def test_eth_getBlockByNumber_pending(self, web3):

tests/integration/test_ethereum_tester.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,10 @@ def test_eth_getStorageAt_deprecated(self, web3, emitter_contract_address):
339339
def test_eth_get_storage_at_ens_name(self, web3, emitter_contract_address):
340340
super().test_eth_get_storage_at_ens_name(web3, emitter_contract_address)
341341

342-
def test_eth_estimateGas_with_block(self,
343-
web3,
344-
unlocked_account_dual_type):
345-
super().test_eth_estimateGas_with_block(
342+
def test_eth_estimate_gas_with_block(self,
343+
web3,
344+
unlocked_account_dual_type):
345+
super().test_eth_estimate_gas_with_block(
346346
web3, unlocked_account_dual_type
347347
)
348348

@@ -390,7 +390,7 @@ def test_eth_call_revert_without_msg(self, web3, revert_contract, unlocked_accou
390390
)
391391
web3.eth.call(txn_params)
392392

393-
def test_eth_estimateGas_revert_with_msg(self, web3, revert_contract, unlocked_account):
393+
def test_eth_estimate_gas_revert_with_msg(self, web3, revert_contract, unlocked_account):
394394
with pytest.raises(TransactionFailed,
395395
match='execution reverted: Function has been reverted'):
396396
txn_params = revert_contract._prepare_transaction(
@@ -400,9 +400,9 @@ def test_eth_estimateGas_revert_with_msg(self, web3, revert_contract, unlocked_a
400400
"to": revert_contract.address,
401401
},
402402
)
403-
web3.eth.estimateGas(txn_params)
403+
web3.eth.estimate_gas(txn_params)
404404

405-
def test_eth_estimateGas_revert_without_msg(self, web3, revert_contract, unlocked_account):
405+
def test_eth_estimate_gas_revert_without_msg(self, web3, revert_contract, unlocked_account):
406406
with pytest.raises(TransactionFailed, match="execution reverted"):
407407
txn_params = revert_contract._prepare_transaction(
408408
fn_name="revertWithoutMessage",
@@ -411,7 +411,7 @@ def test_eth_estimateGas_revert_without_msg(self, web3, revert_contract, unlocke
411411
"to": revert_contract.address,
412412
},
413413
)
414-
web3.eth.estimateGas(txn_params)
414+
web3.eth.estimate_gas(txn_params)
415415

416416

417417
class TestEthereumTesterVersionModule(VersionModuleTest):

web3/_utils/module_testing/eth_module.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ def test_eth_call_revert_without_msg(
973973
)
974974
web3.eth.call(txn_params)
975975

976-
def test_eth_estimateGas_revert_with_msg(
976+
def test_eth_estimate_gas_revert_with_msg(
977977
self,
978978
web3: "Web3",
979979
revert_contract: "Contract",
@@ -988,9 +988,9 @@ def test_eth_estimateGas_revert_with_msg(
988988
"to": revert_contract.address,
989989
},
990990
)
991-
web3.eth.estimateGas(txn_params)
991+
web3.eth.estimate_gas(txn_params)
992992

993-
def test_eth_estimateGas_revert_without_msg(
993+
def test_eth_estimate_gas_revert_without_msg(
994994
self,
995995
web3: "Web3",
996996
revert_contract: "Contract",
@@ -1004,26 +1004,37 @@ def test_eth_estimateGas_revert_without_msg(
10041004
"to": revert_contract.address,
10051005
},
10061006
)
1007-
web3.eth.estimateGas(txn_params)
1007+
web3.eth.estimate_gas(txn_params)
10081008

1009-
def test_eth_estimateGas(
1009+
def test_eth_estimate_gas(
10101010
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
10111011
) -> None:
1012-
gas_estimate = web3.eth.estimateGas({
1012+
gas_estimate = web3.eth.estimate_gas({
10131013
'from': unlocked_account_dual_type,
10141014
'to': unlocked_account_dual_type,
10151015
'value': Wei(1),
10161016
})
10171017
assert is_integer(gas_estimate)
10181018
assert gas_estimate > 0
10191019

1020-
def test_eth_estimateGas_with_block(
1020+
def test_eth_estimateGas_deprecated(
10211021
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
10221022
) -> None:
10231023
gas_estimate = web3.eth.estimateGas({
10241024
'from': unlocked_account_dual_type,
10251025
'to': unlocked_account_dual_type,
10261026
'value': Wei(1),
1027+
})
1028+
assert is_integer(gas_estimate)
1029+
assert gas_estimate > 0
1030+
1031+
def test_eth_estimate_gas_with_block(
1032+
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
1033+
) -> None:
1034+
gas_estimate = web3.eth.estimate_gas({
1035+
'from': unlocked_account_dual_type,
1036+
'to': unlocked_account_dual_type,
1037+
'value': Wei(1),
10271038
}, 'latest')
10281039
assert is_integer(gas_estimate)
10291040
assert gas_estimate > 0

web3/_utils/transactions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
TRANSACTION_DEFAULTS = {
5353
'value': 0,
5454
'data': b'',
55-
'gas': lambda web3, tx: web3.eth.estimateGas(tx),
55+
'gas': lambda web3, tx: web3.eth.estimate_gas(tx),
5656
'gasPrice': lambda web3, tx: web3.eth.generateGasPrice(tx) or web3.eth.gas_price,
5757
'chainId': lambda web3, tx: web3.eth.chain_id,
5858
}
@@ -124,7 +124,7 @@ def get_buffered_gas_estimate(
124124
) -> Wei:
125125
gas_estimate_transaction = cast(TxParams, dict(**transaction))
126126

127-
gas_estimate = web3.eth.estimateGas(gas_estimate_transaction)
127+
gas_estimate = web3.eth.estimate_gas(gas_estimate_transaction)
128128

129129
gas_limit = get_block_gas_limit(web3)
130130

web3/eth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ def estimate_gas_munger(
549549

550550
return params
551551

552-
estimateGas: Method[Callable[..., Wei]] = Method(
552+
estimate_gas: Method[Callable[..., Wei]] = Method(
553553
RPC.eth_estimateGas,
554554
mungers=[estimate_gas_munger]
555555
)
@@ -685,6 +685,7 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None:
685685
getUncleCount = DeprecatedMethod(get_uncle_count, 'getUncleCount', 'get_uncle_count')
686686
sendTransaction = DeprecatedMethod(send_transaction, 'sendTransaction', 'send_transaction')
687687
signTransaction = DeprecatedMethod(sign_transaction, 'signTransaction', 'sign_transaction')
688+
estimateGas = DeprecatedMethod(estimate_gas, 'estimateGas', 'estimate_gas')
688689
sendRawTransaction = DeprecatedMethod(send_raw_transaction,
689690
'sendRawTransaction',
690691
'send_raw_transaction')

0 commit comments

Comments
 (0)