Skip to content

Commit

Permalink
Adds async version of eth_getUncleCount methods
Browse files Browse the repository at this point in the history
  • Loading branch information
konichuvak authored and kclowes committed Apr 7, 2023
1 parent 402d001 commit fc66279
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ Eth
- :meth:`web3.eth.sign() <web3.eth.Eth.sign>`
- :meth:`web3.eth.sign_transaction() <web3.eth.Eth.sign_transaction>`
- :meth:`web3.eth.replace_transaction() <web3.eth.Eth.replace_transaction>`
- :meth:`web3.eth.get_uncle_count() <web3.eth.Eth.get_uncle_count>`

Net
***
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2822.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds async version of `eth_getUncleCount` methods
18 changes: 18 additions & 0 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions web3/eth/async_eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand Down

0 comments on commit fc66279

Please sign in to comment.