diff --git a/migrations/env.py b/migrations/env.py index 045211d9..b01e7eb1 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -9,11 +9,11 @@ from sqlalchemy.engine import Connection from sqlalchemy.ext.asyncio import create_async_engine from sqlmodel import SQLModel +from routstr.core.db import DATABASE_URL + # Add the parent directory to the Python path so we can import routstr modules sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from routstr.core.db import DATABASE_URL - config = context.config if config.config_file_name is None: raise ValueError("config_file_name is None") diff --git a/routstr/balance.py b/routstr/balance.py index d9c3376e..99eb19a3 100644 --- a/routstr/balance.py +++ b/routstr/balance.py @@ -33,15 +33,15 @@ async def account_info(key: ApiKey = Depends(get_key_from_header)) -> dict: } - @router.get("/create") -async def create_balance(initial_balance_token: str, session: AsyncSession = Depends(get_session)) -> dict: +async def create_balance( + initial_balance_token: str, session: AsyncSession = Depends(get_session) +) -> dict: key = await validate_bearer_key(initial_balance_token, session) return { "api_key": "sk-" + key.hashed_key, "balance": key.balance, } - @router.get("/info") @@ -51,9 +51,11 @@ async def wallet_info(key: ApiKey = Depends(get_key_from_header)) -> dict: "balance": key.balance, } + class TopupRequest(BaseModel): cashu_token: str + @router.post("/topup") async def topup_wallet_endpoint( cashu_token: str | None = None, @@ -65,7 +67,7 @@ async def topup_wallet_endpoint( cashu_token = topup_request.cashu_token if cashu_token is None: raise HTTPException(status_code=400, detail="A cashu_token is required.") - + cashu_token = cashu_token.replace("\n", "").replace("\r", "").replace("\t", "") if len(cashu_token) < 10 or "cashu" not in cashu_token: raise HTTPException(status_code=400, detail="Invalid token format") diff --git a/tests/integration/test_reserved_balance_negative.py b/tests/integration/test_reserved_balance_negative.py index 791d4b96..21f9b6d0 100644 --- a/tests/integration/test_reserved_balance_negative.py +++ b/tests/integration/test_reserved_balance_negative.py @@ -133,7 +133,9 @@ async def test_reserved_balance_with_successful_requests( @pytest.mark.asyncio -async def test_insufficient_reserved_balance_for_revert(integration_session: AsyncSession) -> None: +async def test_insufficient_reserved_balance_for_revert( + integration_session: AsyncSession, +) -> None: """Test revert_pay_for_request behavior with insufficient reserved balance.""" from routstr.auth import revert_pay_for_request