From 22e0ad4b579de3b5b83fbb07968cbd42792315a3 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 29 Oct 2023 08:57:25 -0300 Subject: [PATCH] use specific keyset for returned change (#351) --- cashu/mint/ledger.py | 7 ++++++- tests/test_wallet.py | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index ed1a0329..371da7dd 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -315,7 +315,11 @@ async def mint( return promises async def melt( - self, proofs: List[Proof], invoice: str, outputs: Optional[List[BlindedMessage]] + self, + proofs: List[Proof], + invoice: str, + outputs: Optional[List[BlindedMessage]], + keyset: Optional[MintKeyset] = None, ) -> Tuple[bool, str, List[BlindedSignature]]: """Invalidates proofs and pays a Lightning invoice. @@ -386,6 +390,7 @@ async def melt( invoice_amount=invoice_amount, ln_fee_msat=payment.fee_msat, outputs=outputs, + keyset=keyset, ) except Exception as e: diff --git a/tests/test_wallet.py b/tests/test_wallet.py index a869a85a..e2bab85c 100644 --- a/tests/test_wallet.py +++ b/tests/test_wallet.py @@ -243,10 +243,17 @@ async def test_melt(wallet1: Wallet): assert fee_reserve_sat == 2 _, send_proofs = await wallet1.split_to_send(wallet1.proofs, total_amount) - await wallet1.pay_lightning( + melt_response = await wallet1.pay_lightning( send_proofs, invoice=invoice.bolt11, fee_reserve_sat=fee_reserve_sat ) + assert melt_response.change + assert len(melt_response.change) == 1 + # NOTE: we assume that we will get a token back from the same keyset as the ones we melted + # this could be wrong if we melted tokens from an old keyset but the returned ones are + # from a newer one. + assert melt_response.change[0].id == send_proofs[0].id + # verify that proofs in proofs_used db have the same melt_id as the invoice in the db assert invoice.payment_hash invoice_db = await get_lightning_invoice(