Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds async version of eth_getUncleCount methods #2909

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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