Skip to content
Open
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
14 changes: 12 additions & 2 deletions integrations/rustchain-mcp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,18 @@
# Default configuration
RUSTCHAIN_API_BASE = os.getenv("RUSTCHAIN_API_BASE", "https://50.28.86.131")
RUSTCHAIN_NODE_URL = os.getenv("RUSTCHAIN_NODE_URL", "https://50.28.86.131:5000")
REQUEST_TIMEOUT = int(os.getenv("RUSTCHAIN_TIMEOUT", "30"))
RETRY_COUNT = int(os.getenv("RUSTCHAIN_RETRY", "2"))


def _safe_int_env(name: str, default: int) -> int:
try:
return int(os.getenv(name, str(default)))
except (TypeError, ValueError):
logger.warning("Invalid %s env value; using default %s", name, default)
return default


REQUEST_TIMEOUT = _safe_int_env("RUSTCHAIN_TIMEOUT", 30)
RETRY_COUNT = _safe_int_env("RUSTCHAIN_RETRY", 2)


class RustChainClient:
Expand Down
23 changes: 23 additions & 0 deletions integrations/rustchain-mcp/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Unit tests for RustChainClient with mocked HTTP responses.
"""

import importlib
import os
import sys
from unittest.mock import AsyncMock, MagicMock, patch
Expand All @@ -14,6 +15,7 @@
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

try:
import rustchain_mcp.client as client_module
from rustchain_mcp.client import RustChainClient
from rustchain_mcp.schemas import (
APIError,
Expand All @@ -24,6 +26,7 @@
WalletBalance,
)
except ImportError:
import client as client_module
from client import RustChainClient
from schemas import (
APIError,
Expand All @@ -35,6 +38,26 @@
)


def test_malformed_numeric_env_uses_safe_defaults(monkeypatch):
monkeypatch.setenv("RUSTCHAIN_TIMEOUT", "not-a-timeout")
monkeypatch.setenv("RUSTCHAIN_RETRY", "bad-retry")

module = importlib.reload(client_module)

assert module.REQUEST_TIMEOUT == 30
assert module.RETRY_COUNT == 2


def test_numeric_env_overrides_are_preserved(monkeypatch):
monkeypatch.setenv("RUSTCHAIN_TIMEOUT", "12")
monkeypatch.setenv("RUSTCHAIN_RETRY", "4")

module = importlib.reload(client_module)

assert module.REQUEST_TIMEOUT == 12
assert module.RETRY_COUNT == 4


class AsyncContextManager:
"""Simple async context manager for testing."""

Expand Down
Loading