From 48c7abaab372bd30910a21b6d8d272f88b437703 Mon Sep 17 00:00:00 2001 From: 9qeklajc Date: Sun, 4 Oct 2026 22:53:02 +0200 Subject: [PATCH] test: accept foreign swap failures for invalid tokens --- tests/integration/test_example.py | 8 ++++---- tests/integration/test_wallet_topup.py | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/integration/test_example.py b/tests/integration/test_example.py index 030f7bcb..924f9b12 100644 --- a/tests/integration/test_example.py +++ b/tests/integration/test_example.py @@ -136,13 +136,13 @@ async def test_error_handling( "/v1/wallet/topup", params={"cashu_token": invalid_token} ) - # Should get 400 for invalid token - # But the endpoint might return 200 with 0 msats for some invalid tokens + # Locally malformed tokens return 400. A decodable token naming an + # untrusted mint reaches the automatic swap path and can fail safely with + # the documented 422 foreign-swap error instead. if response.status_code == 200: - # Check if it returned 0 msats assert response.json()["msats"] == 0 else: - assert response.status_code == 400 + assert response.status_code in (400, 422) assert "detail" in response.json() # Test unauthorized access diff --git a/tests/integration/test_wallet_topup.py b/tests/integration/test_wallet_topup.py index 3a7bff6f..5da6e0a3 100644 --- a/tests/integration/test_wallet_topup.py +++ b/tests/integration/test_wallet_topup.py @@ -141,15 +141,19 @@ async def test_topup_with_invalid_token( "/v1/wallet/topup", params={"cashu_token": invalid_token} ) - # Should fail with 400 - assert response.status_code == 400, ( - f"Token {invalid_token[:20]}... should be invalid" + # Locally malformed tokens return 400. A decodable token naming an + # untrusted mint reaches the automatic swap path and can fail safely + # 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 validator = ResponseValidator() 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"]