diff --git a/docs/providers.rst b/docs/providers.rst index 21ba60a97e..aac27b9a61 100644 --- a/docs/providers.rst +++ b/docs/providers.rst @@ -295,6 +295,7 @@ Eth - :meth:`web3.eth.sign() ` - :meth:`web3.eth.sign_transaction() ` - :meth:`web3.eth.replace_transaction() ` +- :meth:`web3.eth.get_uncle_count() ` Net *** diff --git a/newsfragments/2822.feature.rst b/newsfragments/2822.feature.rst new file mode 100644 index 0000000000..a3879e6254 --- /dev/null +++ b/newsfragments/2822.feature.rst @@ -0,0 +1 @@ +Adds async version of `eth_getUncleCount` methods \ No newline at end of file diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index f36a3b61ef..d985c07399 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -1589,6 +1589,24 @@ async def test_eth_getBlockTransactionCountByHash_block_with_txn( assert is_integer(transaction_count) assert transaction_count >= 1 + @pytest.mark.asyncio + async def test_eth_getUncleCountByBlockHash( + self, async_w3: "AsyncWeb3", empty_block: BlockData + ) -> None: + uncle_count = await async_w3.eth.get_uncle_count(empty_block["hash"]) + + assert is_integer(uncle_count) + assert uncle_count == 0 + + @pytest.mark.asyncio + async def test_eth_getUncleCountByBlockNumber( + self, async_w3: "AsyncWeb3", empty_block: BlockData + ) -> None: + uncle_count = await async_w3.eth.get_uncle_count(empty_block["number"]) + + assert is_integer(uncle_count) + assert uncle_count == 0 + @pytest.mark.asyncio async def test_eth_getBlockTransactionCountByNumber_block_with_txn( self, async_w3: "AsyncWeb3", block_with_txn: BlockData diff --git a/web3/eth/async_eth.py b/web3/eth/async_eth.py index a0811e7b28..5a24108b45 100644 --- a/web3/eth/async_eth.py +++ b/web3/eth/async_eth.py @@ -558,6 +558,21 @@ async def sign( async def sign_transaction(self, transaction: TxParams) -> SignedTx: return await self._sign_transaction(transaction) + # eth_getUncleCountByBlockHash + # eth_getUncleCountByBlockNumber + + _get_uncle_count: Method[Callable[[BlockIdentifier], Awaitable[int]]] = Method( + method_choice_depends_on_args=select_method_for_block_identifier( + if_predefined=RPC.eth_getUncleCountByBlockNumber, + if_hash=RPC.eth_getUncleCountByBlockHash, + if_number=RPC.eth_getUncleCountByBlockNumber, + ), + mungers=[default_root_munger], + ) + + async def get_uncle_count(self, block_identifier: BlockIdentifier) -> int: + return await self._get_uncle_count(block_identifier) + # eth_newFilter, eth_newBlockFilter, eth_newPendingTransactionFilter filter: Method[