Skip to content

Commit

Permalink
fix melt requiring outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jan 21, 2024
1 parent 9118868 commit 2645eb5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cashu/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand All @@ -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
)


Expand Down
38 changes: 38 additions & 0 deletions tests/test_mint_api_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2645eb5

Please sign in to comment.