fix: resolve linting and formatting issues for CI
- Use contextlib.suppress instead of try/except/pass (SIM105) - Prefix unused fixture arguments with underscore (ARG002) - Replace asyncio.TimeoutError with TimeoutError (UP041) - Apply ruff formatting to all files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
a15086688a
commit
1f4f1fa557
@@ -144,9 +144,7 @@ class TestWalletAnalyzerAnalyze:
|
||||
assert profile.age_hours is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_analyze_uses_cache(
|
||||
self, mock_client: AsyncMock, mock_redis: AsyncMock
|
||||
) -> None:
|
||||
async def test_analyze_uses_cache(self, mock_client: AsyncMock, mock_redis: AsyncMock) -> None:
|
||||
"""Test that analyze uses cached data."""
|
||||
cached_data = {
|
||||
"address": VALID_ADDRESS.lower(),
|
||||
@@ -164,6 +162,7 @@ class TestWalletAnalyzerAnalyze:
|
||||
|
||||
# Actually mock it properly with json
|
||||
import json
|
||||
|
||||
mock_redis.get = AsyncMock(return_value=json.dumps(cached_data).encode())
|
||||
|
||||
analyzer = WalletAnalyzer(mock_client, redis=mock_redis)
|
||||
|
||||
@@ -166,9 +166,7 @@ class TestPolygonClient:
|
||||
|
||||
await client._set_cached("test:key", "value")
|
||||
|
||||
mock_redis.set.assert_called_once_with(
|
||||
"test:key", "value", ex=DEFAULT_CACHE_TTL_SECONDS
|
||||
)
|
||||
mock_redis.set.assert_called_once_with("test:key", "value", ex=DEFAULT_CACHE_TTL_SECONDS)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_set_cached_custom_ttl(self, mock_redis: AsyncMock) -> None:
|
||||
@@ -274,9 +272,7 @@ class TestPolygonClient:
|
||||
assert info.first_transaction is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_first_transaction_no_transactions(
|
||||
self, mock_redis: AsyncMock
|
||||
) -> None:
|
||||
async def test_get_first_transaction_no_transactions(self, mock_redis: AsyncMock) -> None:
|
||||
"""Test get_first_transaction when wallet has no transactions."""
|
||||
client = PolygonClient("https://polygon-rpc.com", redis=mock_redis)
|
||||
|
||||
@@ -451,9 +447,7 @@ class TestPolygonClientTokenBalance:
|
||||
|
||||
# Mock the contract call
|
||||
mock_contract = MagicMock()
|
||||
mock_contract.functions.balanceOf.return_value.call = AsyncMock(
|
||||
return_value=5000000
|
||||
)
|
||||
mock_contract.functions.balanceOf.return_value.call = AsyncMock(return_value=5000000)
|
||||
client._w3.eth.contract = MagicMock(return_value=mock_contract)
|
||||
|
||||
balance = await client.get_token_balance(VALID_ADDRESS, VALID_TOKEN)
|
||||
|
||||
@@ -59,9 +59,7 @@ class TestEntityData:
|
||||
"""Test that CEX addresses are populated."""
|
||||
assert len(CEX_ADDRESSES) > 0
|
||||
# Check Binance address is present
|
||||
binance_found = any(
|
||||
entity == EntityType.CEX_BINANCE for entity in CEX_ADDRESSES.values()
|
||||
)
|
||||
binance_found = any(entity == EntityType.CEX_BINANCE for entity in CEX_ADDRESSES.values())
|
||||
assert binance_found
|
||||
|
||||
def test_bridge_addresses_populated(self) -> None:
|
||||
@@ -72,9 +70,7 @@ class TestEntityData:
|
||||
"""Test that DEX addresses are populated."""
|
||||
assert len(DEX_ADDRESSES) > 0
|
||||
# Check Uniswap is present
|
||||
uniswap_found = any(
|
||||
entity == EntityType.DEX_UNISWAP for entity in DEX_ADDRESSES.values()
|
||||
)
|
||||
uniswap_found = any(entity == EntityType.DEX_UNISWAP for entity in DEX_ADDRESSES.values())
|
||||
assert uniswap_found
|
||||
|
||||
def test_token_addresses_include_usdc(self) -> None:
|
||||
|
||||
@@ -74,27 +74,19 @@ class TestFundingTracerInit:
|
||||
tracer = FundingTracer(mock_polygon_client, max_hops=5)
|
||||
assert tracer.max_hops == 5
|
||||
|
||||
def test_init_with_custom_usdc_addresses(
|
||||
self, mock_polygon_client: MagicMock
|
||||
) -> None:
|
||||
def test_init_with_custom_usdc_addresses(self, mock_polygon_client: MagicMock) -> None:
|
||||
"""Test initialization with custom USDC addresses."""
|
||||
custom_addresses = ["0x1111111111111111111111111111111111111111"]
|
||||
tracer = FundingTracer(
|
||||
mock_polygon_client, usdc_addresses=custom_addresses
|
||||
)
|
||||
tracer = FundingTracer(mock_polygon_client, usdc_addresses=custom_addresses)
|
||||
assert tracer._usdc_addresses == [custom_addresses[0].lower()]
|
||||
|
||||
def test_init_with_custom_entity_registry(
|
||||
self, mock_polygon_client: MagicMock
|
||||
) -> None:
|
||||
def test_init_with_custom_entity_registry(self, mock_polygon_client: MagicMock) -> None:
|
||||
"""Test initialization with custom entity registry."""
|
||||
registry = EntityRegistry()
|
||||
tracer = FundingTracer(mock_polygon_client, entity_registry=registry)
|
||||
assert tracer.entity_registry is registry
|
||||
|
||||
def test_init_creates_default_entity_registry(
|
||||
self, mock_polygon_client: MagicMock
|
||||
) -> None:
|
||||
def test_init_creates_default_entity_registry(self, mock_polygon_client: MagicMock) -> None:
|
||||
"""Test initialization creates default EntityRegistry if None."""
|
||||
tracer = FundingTracer(mock_polygon_client, entity_registry=None)
|
||||
assert isinstance(tracer.entity_registry, EntityRegistry)
|
||||
@@ -186,9 +178,7 @@ class TestFundingTracerTrace:
|
||||
|
||||
call_count = 0
|
||||
|
||||
async def mock_get_logs(
|
||||
*_args: Any, **_kwargs: Any
|
||||
) -> list[dict[str, Any]]:
|
||||
async def mock_get_logs(*_args: Any, **_kwargs: Any) -> list[dict[str, Any]]:
|
||||
nonlocal call_count
|
||||
result = [mock_logs[call_count]] if call_count < len(mock_logs) else []
|
||||
call_count += 1
|
||||
@@ -213,9 +203,7 @@ class TestFundingTracerTrace:
|
||||
|
||||
call_count = 0
|
||||
|
||||
async def mock_get_logs(
|
||||
*_args: Any, **_kwargs: Any
|
||||
) -> list[dict[str, Any]]:
|
||||
async def mock_get_logs(*_args: Any, **_kwargs: Any) -> list[dict[str, Any]]:
|
||||
nonlocal call_count
|
||||
if call_count < len(wallets) - 1:
|
||||
log = _create_mock_log(
|
||||
@@ -286,9 +274,7 @@ class TestGetFirstUsdcTransfer:
|
||||
"""Test fallback to native USDC contract."""
|
||||
call_count = 0
|
||||
|
||||
async def mock_get_logs(
|
||||
*_args: Any, **_kwargs: Any
|
||||
) -> list[dict[str, Any]]:
|
||||
async def mock_get_logs(*_args: Any, **_kwargs: Any) -> list[dict[str, Any]]:
|
||||
nonlocal call_count
|
||||
call_count += 1
|
||||
if call_count == 1: # First call (bridged) returns nothing
|
||||
@@ -410,9 +396,7 @@ class TestLogToFundingTransfer:
|
||||
block_number=50000000,
|
||||
)
|
||||
|
||||
result = await funding_tracer._log_to_funding_transfer(
|
||||
mock_log, USDC_BRIDGED
|
||||
)
|
||||
result = await funding_tracer._log_to_funding_transfer(mock_log, USDC_BRIDGED)
|
||||
|
||||
assert result.from_address == TEST_SOURCE.lower()
|
||||
assert result.to_address == TEST_WALLET.lower()
|
||||
@@ -438,9 +422,7 @@ class TestLogToFundingTransfer:
|
||||
block_number=50000000,
|
||||
)
|
||||
|
||||
result = await funding_tracer._log_to_funding_transfer(
|
||||
mock_log, USDC_BRIDGED
|
||||
)
|
||||
result = await funding_tracer._log_to_funding_transfer(mock_log, USDC_BRIDGED)
|
||||
|
||||
# Should still return a valid transfer with current timestamp
|
||||
assert result.from_address == TEST_SOURCE.lower()
|
||||
@@ -460,7 +442,9 @@ class TestGetFundingChainsBatch:
|
||||
|
||||
# Mock trace to return simple chains
|
||||
async def mock_trace(
|
||||
addr: str, *, max_hops: int | None = None # noqa: ARG001
|
||||
addr: str,
|
||||
*,
|
||||
max_hops: int | None = None, # noqa: ARG001
|
||||
) -> FundingChain:
|
||||
return FundingChain(
|
||||
target_address=addr.lower(),
|
||||
@@ -486,7 +470,9 @@ class TestGetFundingChainsBatch:
|
||||
call_count = 0
|
||||
|
||||
async def mock_trace(
|
||||
addr: str, *, max_hops: int | None = None # noqa: ARG001
|
||||
addr: str,
|
||||
*,
|
||||
max_hops: int | None = None, # noqa: ARG001
|
||||
) -> FundingChain:
|
||||
nonlocal call_count
|
||||
call_count += 1
|
||||
@@ -525,9 +511,7 @@ class TestGetFundingChainsBatch:
|
||||
addresses = ["0x" + "11" * 20]
|
||||
captured_max_hops: list[int | None] = []
|
||||
|
||||
async def mock_trace(
|
||||
addr: str, max_hops: int | None = None
|
||||
) -> FundingChain:
|
||||
async def mock_trace(addr: str, max_hops: int | None = None) -> FundingChain:
|
||||
captured_max_hops.append(max_hops)
|
||||
return FundingChain(target_address=addr.lower())
|
||||
|
||||
@@ -565,9 +549,7 @@ class TestGetSuspiciousnessScore:
|
||||
|
||||
assert score == 0.3
|
||||
|
||||
def test_unknown_no_transfers_high_score(
|
||||
self, funding_tracer: FundingTracer
|
||||
) -> None:
|
||||
def test_unknown_no_transfers_high_score(self, funding_tracer: FundingTracer) -> None:
|
||||
"""Test unknown origin with no transfers is most suspicious."""
|
||||
chain = FundingChain(
|
||||
target_address=TEST_WALLET,
|
||||
@@ -579,9 +561,7 @@ class TestGetSuspiciousnessScore:
|
||||
|
||||
assert score == 1.0
|
||||
|
||||
def test_unknown_max_hops_high_score(
|
||||
self, funding_tracer: FundingTracer
|
||||
) -> None:
|
||||
def test_unknown_max_hops_high_score(self, funding_tracer: FundingTracer) -> None:
|
||||
"""Test unknown origin at max hops is suspicious."""
|
||||
chain = FundingChain(
|
||||
target_address=TEST_WALLET,
|
||||
@@ -593,9 +573,7 @@ class TestGetSuspiciousnessScore:
|
||||
|
||||
assert score == 0.7
|
||||
|
||||
def test_unknown_partial_hops_medium_score(
|
||||
self, funding_tracer: FundingTracer
|
||||
) -> None:
|
||||
def test_unknown_partial_hops_medium_score(self, funding_tracer: FundingTracer) -> None:
|
||||
"""Test unknown origin with partial hops is moderately suspicious."""
|
||||
chain = FundingChain(
|
||||
target_address=TEST_WALLET,
|
||||
|
||||
@@ -160,9 +160,7 @@ class TestWalletInfo:
|
||||
"""Test wallet age when no first transaction."""
|
||||
assert sample_wallet.wallet_age_days is None
|
||||
|
||||
def test_wallet_age_days_with_transaction(
|
||||
self, wallet_with_transaction: WalletInfo
|
||||
) -> None:
|
||||
def test_wallet_age_days_with_transaction(self, wallet_with_transaction: WalletInfo) -> None:
|
||||
"""Test wallet age calculation."""
|
||||
age = wallet_with_transaction.wallet_age_days
|
||||
|
||||
|
||||
Reference in New Issue
Block a user