Skip to content

Commit

Permalink
Restore weak test
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Jan 15, 2025
1 parent ea3f411 commit 92f66ad
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions app/tests/workers/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import json
import unittest
from typing import Any, Awaitable
Expand Down Expand Up @@ -72,16 +71,12 @@ async def asyncSetUp(self):

async def asyncTearDown(self):
await super().asyncTearDown()
redis = get_redis()
redis.flushall()
self.worker.stop()

async def _wait_tasks_execution(self):
def _wait_tasks_execution(self):
redis_tasks = self.worker.broker.client.lrange("dramatiq:default", 0, -1)
while len(redis_tasks) > 0:
redis_tasks = self.worker.broker.client.lrange("dramatiq:default", 0, -1)
# TODO should check anyway the task status instead to randomly wait
await asyncio.sleep(2)

@mock.patch.object(ContractMetadataService, "enabled_clients")
@mock.patch.object(
Expand Down Expand Up @@ -144,7 +139,6 @@ async def test_get_contract_metadata_task(
async def test_get_contract_metadata_task_with_proxy(
self, etherscan_get_contract_metadata_mock: MagicMock, session: AsyncSession
):
await AbiSource(name="Etherscan", url="").create(session)
etherscan_get_contract_metadata_mock.side_effect = [
etherscan_proxy_metadata_mock,
etherscan_metadata_mock,
Expand All @@ -155,18 +149,16 @@ async def test_get_contract_metadata_task_with_proxy(

get_contract_metadata_task.fn(address=contract_address, chain_id=chain_id)

await self._wait_tasks_execution()
self._wait_tasks_execution()

self.assertEqual(etherscan_get_contract_metadata_mock.call_count, 2)
contract = await Contract.get_contract(
session, HexBytes(contract_address), chain_id
)
self.assertIsNotNone(contract)
self.assertEqual(
HexBytes(contract.implementation), HexBytes(proxy_implementation_address)
)

proxy_implementation = await Contract.get_contract(
session, HexBytes(proxy_implementation_address), chain_id
)
self.assertIsNotNone(proxy_implementation)

self.assertEqual(etherscan_get_contract_metadata_mock.call_count, 2)

0 comments on commit 92f66ad

Please sign in to comment.