@@ -4,11 +4,11 @@ use std::time::Duration;
44
55use anyhow:: { bail, Result } ;
66use bip39:: Mnemonic ;
7- use cashu:: { MeltOptions , Mpp } ;
7+ use cashu:: ProofsMethods ;
88use cdk:: amount:: { Amount , SplitTarget } ;
99use cdk:: nuts:: {
10- CurrencyUnit , MeltQuoteState , MintBolt11Request , MintQuoteState , NotificationPayload ,
11- PreMintSecrets ,
10+ CurrencyUnit , MeltOptions , MeltQuoteState , MintBolt11Request , MintQuoteState , Mpp ,
11+ NotificationPayload , PreMintSecrets ,
1212} ;
1313use cdk:: wallet:: { HttpClient , MintConnector , Wallet , WalletSubscription } ;
1414use cdk_integration_tests:: init_regtest:: {
@@ -189,17 +189,21 @@ async fn test_websocket_connection() -> Result<()> {
189189async fn test_multimint_melt ( ) -> Result < ( ) > {
190190 let lnd_client = init_lnd_client ( ) . await ;
191191
192+ let db = Arc :: new ( memory:: empty ( ) . await ?) ;
192193 let wallet1 = Wallet :: new (
193194 & get_mint_url_from_env ( ) ,
194195 CurrencyUnit :: Sat ,
195- Arc :: new ( memory :: empty ( ) . await ? ) ,
196+ db ,
196197 & Mnemonic :: generate ( 12 ) ?. to_seed_normalized ( "" ) ,
197198 None ,
198199 ) ?;
200+
201+ let db = Arc :: new ( memory:: empty ( ) . await ?) ;
202+ db. migrate ( ) . await ;
199203 let wallet2 = Wallet :: new (
200204 & get_second_mint_url_from_env ( ) ,
201205 CurrencyUnit :: Sat ,
202- Arc :: new ( memory :: empty ( ) . await ? ) ,
206+ db ,
203207 & Mnemonic :: generate ( 12 ) ?. to_seed_normalized ( "" ) ,
204208 None ,
205209 ) ?;
@@ -293,3 +297,44 @@ async fn test_cached_mint() -> Result<()> {
293297 assert ! ( response == response1) ;
294298 Ok ( ( ) )
295299}
300+
301+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
302+ async fn test_regtest_melt_amountless ( ) -> Result < ( ) > {
303+ let lnd_client = init_lnd_client ( ) . await ;
304+
305+ let wallet = Wallet :: new (
306+ & get_mint_url_from_env ( ) ,
307+ CurrencyUnit :: Sat ,
308+ Arc :: new ( memory:: empty ( ) . await ?) ,
309+ & Mnemonic :: generate ( 12 ) ?. to_seed_normalized ( "" ) ,
310+ None ,
311+ ) ?;
312+
313+ let mint_amount = Amount :: from ( 100 ) ;
314+
315+ let mint_quote = wallet. mint_quote ( mint_amount, None ) . await ?;
316+
317+ assert_eq ! ( mint_quote. amount, mint_amount) ;
318+
319+ lnd_client. pay_invoice ( mint_quote. request ) . await ?;
320+
321+ let proofs = wallet
322+ . mint ( & mint_quote. id , SplitTarget :: default ( ) , None )
323+ . await ?;
324+
325+ let amount = proofs. total_amount ( ) ?;
326+
327+ assert ! ( mint_amount == amount) ;
328+
329+ let invoice = lnd_client. create_invoice ( None ) . await ?;
330+
331+ let options = MeltOptions :: new_amountless ( 5_000 ) ;
332+
333+ let melt_quote = wallet. melt_quote ( invoice. clone ( ) , Some ( options) ) . await ?;
334+
335+ let melt = wallet. melt ( & melt_quote. id ) . await . unwrap ( ) ;
336+
337+ assert ! ( melt. amount == 5 . into( ) ) ;
338+
339+ Ok ( ( ) )
340+ }
0 commit comments