Skip to content

Commit

Permalink
Fix return types
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Jan 16, 2025
1 parent 133a83b commit bb736b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/datasources/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ async def get_abi_by_contract_address(
@classmethod
async def get_contracts_without_abi(
cls, session: AsyncSession, max_retries: int = 0
):
) -> AsyncGenerator["Contract", None]:
"""
Fetches contracts without an ABI and fewer retries than max_retries, streaming results in batches to reduce memory usage for large datasets.
More information about streaming results can be found here: https://docs.sqlalchemy.org/en/20/core/connections.html#streaming-with-a-dynamically-growing-buffer-using-stream-results
Expand All @@ -298,13 +298,13 @@ async def get_contracts_without_abi(
.where(cls.fetch_retries <= max_retries)
)
result = await session.stream(query)
async for contract in result:
async for (contract,) in result:
yield contract

@classmethod
async def get_proxy_contracts(
cls, session: AsyncSession
) -> AsyncGenerator["Contract"]:
) -> AsyncGenerator["Contract", None]:
"""
Return all the contracts with implementation address, so proxy contracts.
Expand Down
6 changes: 4 additions & 2 deletions app/tests/datasources/db/test_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import cast

from eth_account import Account
from hexbytes import HexBytes
from safe_eth.eth.utils import fast_to_checksum_address
Expand Down Expand Up @@ -157,7 +159,7 @@ async def test_get_contracts_without_abi(self, session: AsyncSession):
address=random_address, name="A test contract", chain_id=1
).create(session)
async for contract in Contract.get_contracts_without_abi(session, 0):
self.assertEqual(expected_contract, contract[0])
self.assertEqual(expected_contract, contract)

# Contracts with more retries shouldn't be returned
expected_contract.fetch_retries = 1
Expand Down Expand Up @@ -194,6 +196,6 @@ async def test_get_proxy_contracts(self, session: AsyncSession):
fast_to_checksum_address(proxy_contract.address), random_address
)
self.assertEqual(
fast_to_checksum_address(proxy_contract.implementation),
fast_to_checksum_address(cast(bytes, proxy_contract.implementation)),
"0x43506849D7C04F9138D1A2050bbF3A0c054402dd",
)
4 changes: 2 additions & 2 deletions app/workers/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ async def get_missing_contract_metadata_task():
session, settings.CONTRACT_MAX_DOWNLOAD_RETRIES
):
get_contract_metadata_task.send(
address=HexBytes(contract[0].address).hex(),
chain_id=contract[0].chain_id,
address=HexBytes(contract.address).hex(),
chain_id=contract.chain_id,
skip_attemp_download=True,
)

Expand Down

0 comments on commit bb736b3

Please sign in to comment.