diff --git a/cashu/core/base.py b/cashu/core/base.py index 8abc69f5..c3ab37e4 100644 --- a/cashu/core/base.py +++ b/cashu/core/base.py @@ -365,7 +365,7 @@ class PostMeltRequest(BaseModel): quote: str = Field(..., max_length=settings.mint_max_request_length) # quote id inputs: List[Proof] = Field(..., max_items=settings.mint_max_request_length) outputs: Union[List[BlindedMessage], None] = Field( - ..., max_items=settings.mint_max_request_length + None, max_items=settings.mint_max_request_length ) @@ -379,7 +379,7 @@ class PostMeltRequest_deprecated(BaseModel): proofs: List[Proof] = Field(..., max_items=settings.mint_max_request_length) pr: str = Field(..., max_length=settings.mint_max_request_length) outputs: Union[List[BlindedMessage], None] = Field( - ..., max_items=settings.mint_max_request_length + None, max_items=settings.mint_max_request_length ) diff --git a/tests/test_mint_api_deprecated.py b/tests/test_mint_api_deprecated.py index 12676ebc..fcdcf8cd 100644 --- a/tests/test_mint_api_deprecated.py +++ b/tests/test_mint_api_deprecated.py @@ -186,6 +186,44 @@ async def test_melt_internal(ledger: Ledger, wallet: Wallet): assert result["paid"] is True +@pytest.mark.asyncio +async def test_melt_internal_no_change_outputs(ledger: Ledger, wallet: Wallet): + # Clients without NUT-08 will not send change outputs + # internal invoice + invoice = await wallet.request_mint(64) + pay_if_regtest(invoice.bolt11) + await wallet.mint(64, id=invoice.id) + assert wallet.balance == 64 + + # create invoice to melt to + invoice = await wallet.request_mint(64) + + invoice_payment_request = invoice.bolt11 + + quote = await wallet.melt_quote(invoice_payment_request) + assert quote.amount == 64 + assert quote.fee_reserve == 0 + + inputs_payload = [p.to_dict() for p in wallet.proofs] + + # outputs for change + secrets, rs, derivation_paths = await wallet.generate_n_secrets(1) + outputs, rs = wallet._construct_outputs([2], secrets, rs) + + response = httpx.post( + f"{BASE_URL}/melt", + json={ + "pr": invoice_payment_request, + "proofs": inputs_payload, + }, + timeout=None, + ) + assert response.status_code == 200, f"{response.url} {response.status_code}" + result = response.json() + assert result.get("preimage") is not None + assert result["paid"] is True + + @pytest.mark.asyncio @pytest.mark.skipif( is_fake,