test: accept foreign swap failures for invalid tokens

This commit is contained in:
9qeklajc
2026-10-04 22:53:02 +02:00
parent 3301a8fb8b
commit 48c7abaab3
2 changed files with 12 additions and 8 deletions
+4 -4
View File
@@ -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
+8 -4
View File
@@ -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"]