Skip to content

Commit 99b21f4

Browse files
pacrobpacrob
pacrob
authored andcommitted
asyncify eth.syncing
1 parent df45de4 commit 99b21f4

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

docs/providers.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ Eth
415415
- :meth:`web3.eth.hashrate <web3.eth.Eth.hashrate>`
416416
- :meth:`web3.eth.max_priority_fee <web3.eth.Eth.max_priority_fee>`
417417
- :meth:`web3.eth.mining <web3.eth.Eth.mining>`
418+
- :meth:`web3.eth.syncing <web3.eth.Eth.syncing>`
418419
- :meth:`web3.eth.call() <web3.eth.Eth.call>`
419420
- :meth:`web3.eth.estimate_gas() <web3.eth.Eth.estimate_gas>`
420421
- :meth:`web3.eth.generate_gas_price() <web3.eth.Eth.generate_gas_price>`

newsfragments/2331.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add async `eth.syncing` method

web3/_utils/module_testing/eth_module.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,24 @@ async def test_async_eth_get_logs_with_logs_none_topic_args(self, async_w3: "Web
10251025
result = await async_w3.eth.get_logs(filter_params) # type: ignore
10261026
assert len(result) == 0
10271027

1028+
@pytest.mark.asyncio
1029+
async def test_async_eth_syncing(self, async_w3: "Web3") -> None:
1030+
syncing = await async_w3.eth.syncing # type: ignore
1031+
1032+
assert is_boolean(syncing) or is_dict(syncing)
1033+
1034+
if is_boolean(syncing):
1035+
assert syncing is False
1036+
elif is_dict(syncing):
1037+
sync_dict = cast(SyncStatus, syncing)
1038+
assert 'startingBlock' in sync_dict
1039+
assert 'currentBlock' in sync_dict
1040+
assert 'highestBlock' in sync_dict
1041+
1042+
assert is_integer(sync_dict['startingBlock'])
1043+
assert is_integer(sync_dict['currentBlock'])
1044+
assert is_integer(sync_dict['highestBlock'])
1045+
10281046
def test_async_provider_default_account(
10291047
self,
10301048
async_w3: "Web3",

web3/eth.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ def call_munger(
322322
mungers=None,
323323
)
324324

325+
_is_syncing: Method[Callable[[], Union[SyncStatus, bool]]] = Method(
326+
RPC.eth_syncing,
327+
mungers=None,
328+
)
329+
325330
_get_transaction_receipt: Method[Callable[[_Hash32], TxReceipt]] = Method(
326331
RPC.eth_getTransactionReceipt,
327332
mungers=[default_root_munger]
@@ -377,6 +382,10 @@ async def max_priority_fee(self) -> Wei:
377382
async def mining(self) -> bool:
378383
return await self._is_mining() # type: ignore
379384

385+
@property
386+
async def syncing(self) -> Union[SyncStatus, bool]:
387+
return await self._is_syncing() # type: ignore
388+
380389
async def fee_history(
381390
self,
382391
block_count: int,
@@ -551,14 +560,9 @@ def protocolVersion(self) -> str:
551560
)
552561
return self.protocol_version
553562

554-
is_syncing: Method[Callable[[], Union[SyncStatus, bool]]] = Method(
555-
RPC.eth_syncing,
556-
mungers=None,
557-
)
558-
559563
@property
560564
def syncing(self) -> Union[SyncStatus, bool]:
561-
return self.is_syncing()
565+
return self._is_syncing()
562566

563567
@property
564568
def coinbase(self) -> ChecksumAddress:

0 commit comments

Comments
 (0)