Skip to content

Commit

Permalink
Add get_uncle_count, deprecate getUncleCount
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Jan 29, 2021
1 parent a5f05d5 commit d8996bd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ API
- :meth:`web3.eth.get_transaction_by_block() <web3.eth.Eth.get_transaction_by_block>`
- :meth:`web3.eth.getTransactionCount() <web3.eth.Eth.getTransactionCount>`
- :meth:`web3.eth.get_uncle_by_block() <web3.eth.Eth.get_uncle_by_block>`
- :meth:`web3.eth.getUncleCount() <web3.eth.Eth.getUncleCount>`
- :meth:`web3.eth.get_uncle_count() <web3.eth.Eth.get_uncle_count>`


Making Transactions
Expand Down
10 changes: 7 additions & 3 deletions docs/web3.eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ The following methods are available on the ``web3.eth`` namespace.
.. warning:: Deprecated: This method is deprecated in favor of
:meth:`~web3.eth.Eth.get_uncle_by_block()`

.. py:method:: Eth.getUncleCount(block_identifier)
.. py:method:: Eth.get_uncle_count(block_identifier)
* Delegates to ``eth_getUncleCountByBlockHash`` or
``eth_getUncleCountByBlockNumber`` RPC methods
Expand All @@ -518,13 +518,17 @@ The following methods are available on the ``web3.eth`` namespace.

.. code-block:: python
>>> web3.eth.getUncleCount(56160)
>>> web3.eth.get_uncle_count(56160)
1
# You can also refer to the block by hash:
>>> web3.eth.getUncleCount('0x685b2226cbf6e1f890211010aa192bf16f0a0cba9534264a033b023d7367b845')
>>> web3.eth.get_uncle_count('0x685b2226cbf6e1f890211010aa192bf16f0a0cba9534264a033b023d7367b845')
1
.. py:method:: Eth.getUncleCount(block_identifier)
.. warning:: Deprecated: This property is deprecated in favor of
:attr:`~web3.eth.Eth.get_uncle_count()`

.. py:method:: Eth.get_transaction(transaction_hash)
Expand Down
1 change: 1 addition & 0 deletions newsfragments/1863.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add get_uncle_count, deprecate getUncleCount
24 changes: 22 additions & 2 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,33 @@ def test_eth_getBlockTransactionCountByNumber_block_with_txn_deprecated(
assert transaction_count >= 1

def test_eth_getUncleCountByBlockHash(self, web3: "Web3", empty_block: BlockData) -> None:
uncle_count = web3.eth.getUncleCount(empty_block['hash'])
uncle_count = web3.eth.get_uncle_count(empty_block['hash'])

assert is_integer(uncle_count)
assert uncle_count == 0

def test_eth_getUncleCountByBlockHash_deprecated(self,
web3: "Web3",
empty_block: BlockData) -> None:
with pytest.warns(DeprecationWarning,
match='getUncleCount is deprecated in favor of get_uncle_count'):
uncle_count = web3.eth.getUncleCount(empty_block['hash'])

assert is_integer(uncle_count)
assert uncle_count == 0

def test_eth_getUncleCountByBlockNumber(self, web3: "Web3", empty_block: BlockData) -> None:
uncle_count = web3.eth.getUncleCount(empty_block['number'])
uncle_count = web3.eth.get_uncle_count(empty_block['number'])

assert is_integer(uncle_count)
assert uncle_count == 0

def test_eth_getUncleCountByBlockNumber_deprecated(self,
web3: "Web3",
empty_block: BlockData) -> None:
with pytest.warns(DeprecationWarning,
match='getUncleCount is deprecated in favor of get_uncle_count'):
uncle_count = web3.eth.getUncleCount(empty_block['number'])

assert is_integer(uncle_count)
assert uncle_count == 0
Expand Down
3 changes: 2 additions & 1 deletion web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def get_block_munger(
`eth_getUncleCountByBlockHash`
`eth_getUncleCountByBlockNumber`
"""
getUncleCount: Method[Callable[[BlockIdentifier], int]] = Method(
get_uncle_count: Method[Callable[[BlockIdentifier], int]] = Method(
method_choice_depends_on_args=select_method_for_block_identifier(
if_predefined=RPC.eth_getUncleCountByBlockNumber,
if_hash=RPC.eth_getUncleCountByBlockHash,
Expand Down Expand Up @@ -660,3 +660,4 @@ def setGasPriceStrategy(self, gas_price_strategy: GasPriceStrategy) -> None:
'getTransactionByBlock',
'get_transaction_by_block')
getUncleByBlock = DeprecatedMethod(get_uncle_by_block, 'getUncleByBlock', 'get_uncle_by_block')
getUncleCount = DeprecatedMethod(get_uncle_count, 'getUncleCount', 'get_uncle_count')

0 comments on commit d8996bd

Please sign in to comment.