mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-10-05 12:28:22 +00:00
test: accept foreign swap failures for invalid tokens
This commit is contained in:
@@ -136,13 +136,13 @@ async def test_error_handling(
|
|||||||
"/v1/wallet/topup", params={"cashu_token": invalid_token}
|
"/v1/wallet/topup", params={"cashu_token": invalid_token}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Should get 400 for invalid token
|
# Locally malformed tokens return 400. A decodable token naming an
|
||||||
# But the endpoint might return 200 with 0 msats for some invalid tokens
|
# untrusted mint reaches the automatic swap path and can fail safely with
|
||||||
|
# the documented 422 foreign-swap error instead.
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
# Check if it returned 0 msats
|
|
||||||
assert response.json()["msats"] == 0
|
assert response.json()["msats"] == 0
|
||||||
else:
|
else:
|
||||||
assert response.status_code == 400
|
assert response.status_code in (400, 422)
|
||||||
assert "detail" in response.json()
|
assert "detail" in response.json()
|
||||||
|
|
||||||
# Test unauthorized access
|
# Test unauthorized access
|
||||||
|
|||||||
@@ -141,15 +141,19 @@ async def test_topup_with_invalid_token(
|
|||||||
"/v1/wallet/topup", params={"cashu_token": invalid_token}
|
"/v1/wallet/topup", params={"cashu_token": invalid_token}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Should fail with 400
|
# Locally malformed tokens return 400. A decodable token naming an
|
||||||
assert response.status_code == 400, (
|
# untrusted mint reaches the automatic swap path and can fail safely
|
||||||
f"Token {invalid_token[:20]}... should be invalid"
|
# with the documented 422 foreign-swap error instead.
|
||||||
|
assert response.status_code in (400, 422), (
|
||||||
|
f"Token {invalid_token[:20]}... should fail without being credited"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validate error response
|
# Validate error response
|
||||||
validator = ResponseValidator()
|
validator = ResponseValidator()
|
||||||
error_validation = validator.validate_error_response(
|
error_validation = validator.validate_error_response(
|
||||||
response, expected_status=400, expected_error_key="detail"
|
response,
|
||||||
|
expected_status=response.status_code,
|
||||||
|
expected_error_key="detail",
|
||||||
)
|
)
|
||||||
assert error_validation["valid"]
|
assert error_validation["valid"]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user