This commit is contained in:
Shroominic
2025-08-23 17:01:28 -03:00
parent 6a746eb3df
commit 8175188b06
3 changed files with 11 additions and 7 deletions
+2 -2
View File
@@ -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")
+6 -4
View File
@@ -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")
@@ -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