Skip to content

Commit 2e81408

Browse files
tmckenzie51kclowes
authored andcommitted
snakecase estimateGas to estimate_gas
1 parent f9dfe42 commit 2e81408

File tree

11 files changed

+53
-39
lines changed

11 files changed

+53
-39
lines changed

docs/contracts.rst

Lines changed: 3 additions & 3 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.
@@ -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.

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.sign_typed_data() <web3.eth.Eth.sign_typed_data>`
182-
- :meth:`web3.eth.estimateGas() <web3.eth.Eth.estimateGas>`
182+
- :meth:`web3.eth.estimate_gas() <web3.eth.Eth.estimate_gas>`
183183
- :meth:`web3.eth.generate_gas_price() <web3.eth.Eth.generate_gas_price>`
184184
- :meth:`web3.eth.set_gas_price_strategy() <web3.eth.Eth.set_gas_price_strategy>`
185185

docs/web3.eth.rst

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

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

740740

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

949949

950-
.. py:method:: Eth.estimateGas(transaction, block_identifier=None)
950+
.. py:method:: Eth.estimate_gas(transaction, block_identifier=None)
951951
952952
* Delegates to ``eth_estimateGas`` RPC Method
953953

@@ -956,18 +956,17 @@ The following methods are available on the ``web3.eth`` namespace.
956956
be used as a gas estimate.
957957

958958
The ``transaction`` and ``block_identifier`` parameters are handled in the
959-
same manner as the :meth:`~web3.eth.call()` method.
959+
same manner as the :meth:`~web3.eth.Eth.send_transaction()` method.
960960

961961
.. code-block:: python
962962
963-
>>> web3.eth.estimateGas({'to': '0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'from': web3.eth.coinbase, 'value': 12345})
963+
>>> web3.eth.estimate_gas({'to': '0xd3CdA913deB6f67967B99D67aCDFa1712C293601', 'from':web3.eth.coinbase, 'value': 12345})
964964
21000
965965
966-
.. note::
967-
The parameter ``block_identifier`` is not enabled in geth nodes,
968-
hence passing a value of ``block_identifier`` when connected to a geth
969-
nodes would result in an error like: ``ValueError: {'code': -32602, 'message': 'too many arguments, want at most 1'}``
966+
.. py:method:: Eth.estimateGas(transaction, block_identifier=None)
970967
968+
.. warning:: Deprecated: This method is deprecated in favor of
969+
:meth:`~web3.eth.Eth.estimate_gas()`
971970

972971
.. py:method:: Eth.generate_gas_price(transaction_params=None)
973972

newsfragments/1913.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``w3.eth.estimate_gas`` deprecate ``w3.eth.estimateGas``

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
@@ -350,10 +350,10 @@ def test_eth_getStorageAt_deprecated(self, web3, emitter_contract_address):
350350
def test_eth_get_storage_at_ens_name(self, web3, emitter_contract_address):
351351
super().test_eth_get_storage_at_ens_name(web3, emitter_contract_address)
352352

353-
def test_eth_estimateGas_with_block(self,
354-
web3,
355-
unlocked_account_dual_type):
356-
super().test_eth_estimateGas_with_block(
353+
def test_eth_estimate_gas_with_block(self,
354+
web3,
355+
unlocked_account_dual_type):
356+
super().test_eth_estimate_gas_with_block(
357357
web3, unlocked_account_dual_type
358358
)
359359

@@ -401,7 +401,7 @@ def test_eth_call_revert_without_msg(self, web3, revert_contract, unlocked_accou
401401
)
402402
web3.eth.call(txn_params)
403403

404-
def test_eth_estimateGas_revert_with_msg(self, web3, revert_contract, unlocked_account):
404+
def test_eth_estimate_gas_revert_with_msg(self, web3, revert_contract, unlocked_account):
405405
with pytest.raises(TransactionFailed,
406406
match='execution reverted: Function has been reverted'):
407407
txn_params = revert_contract._prepare_transaction(
@@ -411,9 +411,9 @@ def test_eth_estimateGas_revert_with_msg(self, web3, revert_contract, unlocked_a
411411
"to": revert_contract.address,
412412
},
413413
)
414-
web3.eth.estimateGas(txn_params)
414+
web3.eth.estimate_gas(txn_params)
415415

416-
def test_eth_estimateGas_revert_without_msg(self, web3, revert_contract, unlocked_account):
416+
def test_eth_estimate_gas_revert_without_msg(self, web3, revert_contract, unlocked_account):
417417
with pytest.raises(TransactionFailed, match="execution reverted"):
418418
txn_params = revert_contract._prepare_transaction(
419419
fn_name="revertWithoutMessage",
@@ -422,7 +422,7 @@ def test_eth_estimateGas_revert_without_msg(self, web3, revert_contract, unlocke
422422
"to": revert_contract.address,
423423
},
424424
)
425-
web3.eth.estimateGas(txn_params)
425+
web3.eth.estimate_gas(txn_params)
426426

427427

428428
class TestEthereumTesterVersionModule(VersionModuleTest):

web3/_utils/module_testing/eth_module.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ def test_eth_call_revert_without_msg(
10211021
)
10221022
web3.eth.call(txn_params)
10231023

1024-
def test_eth_estimateGas_revert_with_msg(
1024+
def test_eth_estimate_gas_revert_with_msg(
10251025
self,
10261026
web3: "Web3",
10271027
revert_contract: "Contract",
@@ -1036,9 +1036,9 @@ def test_eth_estimateGas_revert_with_msg(
10361036
"to": revert_contract.address,
10371037
},
10381038
)
1039-
web3.eth.estimateGas(txn_params)
1039+
web3.eth.estimate_gas(txn_params)
10401040

1041-
def test_eth_estimateGas_revert_without_msg(
1041+
def test_eth_estimate_gas_revert_without_msg(
10421042
self,
10431043
web3: "Web3",
10441044
revert_contract: "Contract",
@@ -1052,23 +1052,36 @@ def test_eth_estimateGas_revert_without_msg(
10521052
"to": revert_contract.address,
10531053
},
10541054
)
1055-
web3.eth.estimateGas(txn_params)
1055+
web3.eth.estimate_gas(txn_params)
10561056

1057-
def test_eth_estimateGas(
1057+
def test_eth_estimate_gas(
10581058
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
10591059
) -> None:
1060-
gas_estimate = web3.eth.estimateGas({
1060+
gas_estimate = web3.eth.estimate_gas({
10611061
'from': unlocked_account_dual_type,
10621062
'to': unlocked_account_dual_type,
10631063
'value': Wei(1),
10641064
})
10651065
assert is_integer(gas_estimate)
10661066
assert gas_estimate > 0
10671067

1068-
def test_eth_estimateGas_with_block(
1068+
def test_eth_estimateGas_deprecated(
10691069
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
10701070
) -> None:
1071-
gas_estimate = web3.eth.estimateGas({
1071+
with pytest.warns(DeprecationWarning,
1072+
match="estimateGas is deprecated in favor of estimate_gas"):
1073+
gas_estimate = web3.eth.estimateGas({
1074+
'from': unlocked_account_dual_type,
1075+
'to': unlocked_account_dual_type,
1076+
'value': Wei(1),
1077+
})
1078+
assert is_integer(gas_estimate)
1079+
assert gas_estimate > 0
1080+
1081+
def test_eth_estimate_gas_with_block(
1082+
self, web3: "Web3", unlocked_account_dual_type: ChecksumAddress
1083+
) -> None:
1084+
gas_estimate = web3.eth.estimate_gas({
10721085
'from': unlocked_account_dual_type,
10731086
'to': unlocked_account_dual_type,
10741087
'value': Wei(1),

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.generate_gas_price(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/contract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def estimateGas(
639639

640640
estimate_gas_transaction['data'] = self.data_in_transaction
641641

642-
return self.web3.eth.estimateGas(
642+
return self.web3.eth.estimate_gas(
643643
estimate_gas_transaction, block_identifier=block_identifier
644644
)
645645

@@ -1615,7 +1615,7 @@ def estimate_gas_for_function(
16151615
fn_kwargs=kwargs,
16161616
)
16171617

1618-
return web3.eth.estimateGas(estimate_transaction, block_identifier)
1618+
return web3.eth.estimate_gas(estimate_transaction, block_identifier)
16191619

16201620

16211621
def build_transaction_for_function(

web3/eth.py

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

560560
return params
561561

562-
estimateGas: Method[Callable[..., Wei]] = Method(
562+
estimate_gas: Method[Callable[..., Wei]] = Method(
563563
RPC.eth_estimateGas,
564564
mungers=[estimate_gas_munger]
565565
)
@@ -707,6 +707,7 @@ def set_gas_price_strategy(self, gas_price_strategy: GasPriceStrategy) -> None:
707707
submitHashrate = DeprecatedMethod(submit_hashrate, 'submitHashrate', 'submit_hashrate')
708708
submitWork = DeprecatedMethod(submit_work, 'submitWork', 'submit_work')
709709
getLogs = DeprecatedMethod(get_logs, 'getLogs', 'get_logs')
710+
estimateGas = DeprecatedMethod(estimate_gas, 'estimateGas', 'estimate_gas')
710711
sendRawTransaction = DeprecatedMethod(send_raw_transaction,
711712
'sendRawTransaction',
712713
'send_raw_transaction')

0 commit comments

Comments
 (0)