mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-10-05 20:28:23 +00:00
clean up
This commit is contained in:
@@ -53,7 +53,6 @@ class Settings(BaseSettings):
|
|||||||
tolerance_percentage: float = Field(default=1.0, env="TOLERANCE_PERCENTAGE")
|
tolerance_percentage: float = Field(default=1.0, env="TOLERANCE_PERCENTAGE")
|
||||||
# Minimum per-request charge in millisatoshis when model pricing is free/zero
|
# Minimum per-request charge in millisatoshis when model pricing is free/zero
|
||||||
min_request_msat: int = Field(default=1, env="MIN_REQUEST_MSAT")
|
min_request_msat: int = Field(default=1, env="MIN_REQUEST_MSAT")
|
||||||
cashu_mint_fee_msat: int = Field(default=60, env="CASHU_MINT_FEE_MSAT")
|
|
||||||
|
|
||||||
# Network
|
# Network
|
||||||
cors_origins: list[str] = Field(default_factory=lambda: ["*"], env="CORS_ORIGINS")
|
cors_origins: list[str] = Field(default_factory=lambda: ["*"], env="CORS_ORIGINS")
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ def check_token_balance(headers: dict, body: dict, max_cost_for_model: int) -> N
|
|||||||
token_obj.amount if token_obj.unit == "msat" else token_obj.amount * 1000
|
token_obj.amount if token_obj.unit == "msat" else token_obj.amount * 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
fee_buffer = getattr(settings, "cashu_mint_fee_msat", 60)
|
fee_buffer = 60
|
||||||
if max_cost_for_model > amount_msat + fee_buffer:
|
if max_cost_for_model > amount_msat + fee_buffer:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=413,
|
status_code=413,
|
||||||
|
|||||||
@@ -139,10 +139,9 @@ async def test_check_token_balance_with_fee_buffer(
|
|||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
"routstr.payment.helpers.deserialize_token_from_string", mock_deserialize
|
"routstr.payment.helpers.deserialize_token_from_string", mock_deserialize
|
||||||
)
|
)
|
||||||
with patch.object(settings, "cashu_mint_fee_msat", 100):
|
headers = {"x-cashu": "token"}
|
||||||
headers = {"x-cashu": "token"}
|
body = {"model": "gpt-4"}
|
||||||
body = {"model": "gpt-4"}
|
check_token_balance(headers, body, max_cost_for_model=320450)
|
||||||
check_token_balance(headers, body, max_cost_for_model=320450)
|
|
||||||
|
|
||||||
|
|
||||||
def test_check_token_balance_insufficient(monkeypatch: pytest.MonkeyPatch) -> None:
|
def test_check_token_balance_insufficient(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
@@ -156,12 +155,11 @@ def test_check_token_balance_insufficient(monkeypatch: pytest.MonkeyPatch) -> No
|
|||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
"routstr.payment.helpers.deserialize_token_from_string", mock_deserialize
|
"routstr.payment.helpers.deserialize_token_from_string", mock_deserialize
|
||||||
)
|
)
|
||||||
with patch.object(settings, "cashu_mint_fee_msat", 100):
|
headers = {"x-cashu": "token"}
|
||||||
headers = {"x-cashu": "token"}
|
body = {"model": "gpt-4"}
|
||||||
body = {"model": "gpt-4"}
|
with pytest.raises(HTTPException) as exc:
|
||||||
with pytest.raises(HTTPException) as exc:
|
check_token_balance(headers, body, max_cost_for_model=320450)
|
||||||
check_token_balance(headers, body, max_cost_for_model=320450)
|
assert exc.value.status_code == 413
|
||||||
assert exc.value.status_code == 413
|
detail = exc.value.detail # type: ignore[assignment]
|
||||||
detail = exc.value.detail # type: ignore[assignment]
|
assert isinstance(detail, dict)
|
||||||
assert isinstance(detail, dict)
|
assert detail.get("type") == "minimum_balance_required"
|
||||||
assert detail.get("type") == "minimum_balance_required"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user