Skip to content

asyncify eth.syncing #2331

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

Merged
merged 1 commit into from
Feb 2, 2022
Merged
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 @@ -415,6 +415,7 @@ Eth
- :meth:`web3.eth.hashrate <web3.eth.Eth.hashrate>`
- :meth:`web3.eth.max_priority_fee <web3.eth.Eth.max_priority_fee>`
- :meth:`web3.eth.mining <web3.eth.Eth.mining>`
- :meth:`web3.eth.syncing <web3.eth.Eth.syncing>`
- :meth:`web3.eth.call() <web3.eth.Eth.call>`
- :meth:`web3.eth.estimate_gas() <web3.eth.Eth.estimate_gas>`
- :meth:`web3.eth.generate_gas_price() <web3.eth.Eth.generate_gas_price>`
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2331.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add async `eth.syncing` method
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 @@ -1025,6 +1025,24 @@ async def test_async_eth_get_logs_with_logs_none_topic_args(self, async_w3: "Web
result = await async_w3.eth.get_logs(filter_params) # type: ignore
assert len(result) == 0

@pytest.mark.asyncio
async def test_async_eth_syncing(self, async_w3: "Web3") -> None:
syncing = await async_w3.eth.syncing # type: ignore

assert is_boolean(syncing) or is_dict(syncing)

if is_boolean(syncing):
assert syncing is False
elif is_dict(syncing):
sync_dict = cast(SyncStatus, syncing)
assert 'startingBlock' in sync_dict
assert 'currentBlock' in sync_dict
assert 'highestBlock' in sync_dict

assert is_integer(sync_dict['startingBlock'])
assert is_integer(sync_dict['currentBlock'])
assert is_integer(sync_dict['highestBlock'])

def test_async_provider_default_account(
self,
async_w3: "Web3",
Expand Down
16 changes: 10 additions & 6 deletions web3/eth.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ def call_munger(
mungers=None,
)

_is_syncing: Method[Callable[[], Union[SyncStatus, bool]]] = Method(
RPC.eth_syncing,
mungers=None,
)

_get_transaction_receipt: Method[Callable[[_Hash32], TxReceipt]] = Method(
RPC.eth_getTransactionReceipt,
mungers=[default_root_munger]
Expand Down Expand Up @@ -377,6 +382,10 @@ async def max_priority_fee(self) -> Wei:
async def mining(self) -> bool:
return await self._is_mining() # type: ignore

@property
async def syncing(self) -> Union[SyncStatus, bool]:
return await self._is_syncing() # type: ignore

async def fee_history(
self,
block_count: int,
Expand Down Expand Up @@ -551,14 +560,9 @@ def protocolVersion(self) -> str:
)
return self.protocol_version

is_syncing: Method[Callable[[], Union[SyncStatus, bool]]] = Method(
RPC.eth_syncing,
mungers=None,
)

@property
def syncing(self) -> Union[SyncStatus, bool]:
return self.is_syncing()
return self._is_syncing()

@property
def coinbase(self) -> ChecksumAddress:
Expand Down