| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302 | 
							- //! Fake Wallet Integration Tests
 
- //!
 
- //! This file contains tests for the fake wallet backend functionality.
 
- //! The fake wallet simulates Lightning Network behavior for testing purposes,
 
- //! allowing verification of mint behavior in various payment scenarios without
 
- //! requiring a real Lightning node.
 
- //!
 
- //! Test Scenarios:
 
- //! - Pending payment states and proof handling
 
- //! - Payment failure cases and proof state management
 
- //! - Change output verification in melt operations
 
- //! - Witness signature validation
 
- //! - Cross-unit transaction validation
 
- //! - Overflow and balance validation
 
- //! - Duplicate proof detection
 
- use std::sync::Arc;
 
- use std::time::Duration;
 
- use bip39::Mnemonic;
 
- use cashu::Amount;
 
- use cdk::amount::SplitTarget;
 
- use cdk::nuts::nut00::ProofsMethods;
 
- use cdk::nuts::{
 
-     CurrencyUnit, MeltQuoteState, MeltRequest, MintRequest, PreMintSecrets, Proofs, SecretKey,
 
-     State, SwapRequest,
 
- };
 
- use cdk::wallet::types::TransactionDirection;
 
- use cdk::wallet::{HttpClient, MintConnector, Wallet};
 
- use cdk_fake_wallet::{create_fake_invoice, FakeInvoiceDescription};
 
- use cdk_integration_tests::attempt_to_swap_pending;
 
- use cdk_sqlite::wallet::memory;
 
- const MINT_URL: &str = "http://127.0.0.1:8086";
 
- /// Tests that when both pay and check return pending status, input proofs should remain pending
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_tokens_pending() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let _mint_amount = wallet
 
-         .mint(&mint_quote.id, SplitTarget::default(), None)
 
-         .await
 
-         .unwrap();
 
-     let fake_description = FakeInvoiceDescription {
 
-         pay_invoice_state: MeltQuoteState::Pending,
 
-         check_payment_state: MeltQuoteState::Pending,
 
-         pay_err: false,
 
-         check_err: false,
 
-     };
 
-     let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
 
-     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-     let melt = wallet.melt(&melt_quote.id).await;
 
-     assert!(melt.is_err());
 
-     attempt_to_swap_pending(&wallet).await.unwrap();
 
- }
 
- /// Tests that if the pay error fails and the check returns unknown or failed,
 
- /// the input proofs should be unset as spending (returned to unspent state)
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_melt_payment_fail() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("Failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let _mint_amount = wallet
 
-         .mint(&mint_quote.id, SplitTarget::default(), None)
 
-         .await
 
-         .unwrap();
 
-     let fake_description = FakeInvoiceDescription {
 
-         pay_invoice_state: MeltQuoteState::Unknown,
 
-         check_payment_state: MeltQuoteState::Unknown,
 
-         pay_err: true,
 
-         check_err: false,
 
-     };
 
-     let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
 
-     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-     // The melt should error at the payment invoice command
 
-     let melt = wallet.melt(&melt_quote.id).await;
 
-     assert!(melt.is_err());
 
-     let fake_description = FakeInvoiceDescription {
 
-         pay_invoice_state: MeltQuoteState::Failed,
 
-         check_payment_state: MeltQuoteState::Failed,
 
-         pay_err: true,
 
-         check_err: false,
 
-     };
 
-     let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
 
-     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-     // The melt should error at the payment invoice command
 
-     let melt = wallet.melt(&melt_quote.id).await;
 
-     assert!(melt.is_err());
 
-     // The mint should have unset proofs from pending since payment failed
 
-     let all_proof = wallet.get_unspent_proofs().await.unwrap();
 
-     let states = wallet.check_proofs_spent(all_proof).await.unwrap();
 
-     for state in states {
 
-         assert!(state.state == State::Unspent);
 
-     }
 
-     let wallet_bal = wallet.total_balance().await.unwrap();
 
-     assert_eq!(wallet_bal, 100.into());
 
- }
 
- /// Tests that when both the pay_invoice and check_invoice both fail,
 
- /// the proofs should remain in pending state
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_melt_payment_fail_and_check() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("Failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let _mint_amount = wallet
 
-         .mint(&mint_quote.id, SplitTarget::default(), None)
 
-         .await
 
-         .unwrap();
 
-     let fake_description = FakeInvoiceDescription {
 
-         pay_invoice_state: MeltQuoteState::Unknown,
 
-         check_payment_state: MeltQuoteState::Unknown,
 
-         pay_err: true,
 
-         check_err: true,
 
-     };
 
-     let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
 
-     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-     // The melt should error at the payment invoice command
 
-     let melt = wallet.melt(&melt_quote.id).await;
 
-     assert!(melt.is_err());
 
-     let pending = wallet
 
-         .localstore
 
-         .get_proofs(None, None, Some(vec![State::Pending]), None)
 
-         .await
 
-         .unwrap();
 
-     assert!(!pending.is_empty());
 
- }
 
- /// Tests that when the ln backend returns a failed status but does not error,
 
- /// the mint should do a second check, then remove proofs from pending state
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_melt_payment_return_fail_status() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("Failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let _mint_amount = wallet
 
-         .mint(&mint_quote.id, SplitTarget::default(), None)
 
-         .await
 
-         .unwrap();
 
-     let fake_description = FakeInvoiceDescription {
 
-         pay_invoice_state: MeltQuoteState::Failed,
 
-         check_payment_state: MeltQuoteState::Failed,
 
-         pay_err: false,
 
-         check_err: false,
 
-     };
 
-     let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
 
-     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-     // The melt should error at the payment invoice command
 
-     let melt = wallet.melt(&melt_quote.id).await;
 
-     assert!(melt.is_err());
 
-     let fake_description = FakeInvoiceDescription {
 
-         pay_invoice_state: MeltQuoteState::Unknown,
 
-         check_payment_state: MeltQuoteState::Unknown,
 
-         pay_err: false,
 
-         check_err: false,
 
-     };
 
-     let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
 
-     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-     // The melt should error at the payment invoice command
 
-     let melt = wallet.melt(&melt_quote.id).await;
 
-     assert!(melt.is_err());
 
-     let pending = wallet
 
-         .localstore
 
-         .get_proofs(None, None, Some(vec![State::Pending]), None)
 
-         .await
 
-         .unwrap();
 
-     assert!(pending.is_empty());
 
- }
 
- /// Tests that when the ln backend returns an error with unknown status,
 
- /// the mint should do a second check, then remove proofs from pending state
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_melt_payment_error_unknown() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .unwrap();
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let _mint_amount = wallet
 
-         .mint(&mint_quote.id, SplitTarget::default(), None)
 
-         .await
 
-         .unwrap();
 
-     let fake_description = FakeInvoiceDescription {
 
-         pay_invoice_state: MeltQuoteState::Failed,
 
-         check_payment_state: MeltQuoteState::Unknown,
 
-         pay_err: true,
 
-         check_err: false,
 
-     };
 
-     let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
 
-     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-     // The melt should error at the payment invoice command
 
-     let melt = wallet.melt(&melt_quote.id).await;
 
-     assert_eq!(melt.unwrap_err().to_string(), "Payment failed");
 
-     let fake_description = FakeInvoiceDescription {
 
-         pay_invoice_state: MeltQuoteState::Unknown,
 
-         check_payment_state: MeltQuoteState::Unknown,
 
-         pay_err: true,
 
-         check_err: false,
 
-     };
 
-     let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
 
-     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-     // The melt should error at the payment invoice command
 
-     let melt = wallet.melt(&melt_quote.id).await;
 
-     assert_eq!(melt.unwrap_err().to_string(), "Payment failed");
 
-     let pending = wallet
 
-         .localstore
 
-         .get_proofs(None, None, Some(vec![State::Pending]), None)
 
-         .await
 
-         .unwrap();
 
-     assert!(pending.is_empty());
 
- }
 
- /// Tests that when the ln backend returns an error but the second check returns paid,
 
- /// proofs should remain in pending state
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_melt_payment_err_paid() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("Failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let _mint_amount = wallet
 
-         .mint(&mint_quote.id, SplitTarget::default(), None)
 
-         .await
 
-         .unwrap();
 
-     let fake_description = FakeInvoiceDescription {
 
-         pay_invoice_state: MeltQuoteState::Failed,
 
-         check_payment_state: MeltQuoteState::Paid,
 
-         pay_err: true,
 
-         check_err: false,
 
-     };
 
-     let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
 
-     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-     // The melt should error at the payment invoice command
 
-     let melt = wallet.melt(&melt_quote.id).await;
 
-     assert!(melt.is_err());
 
-     attempt_to_swap_pending(&wallet).await.unwrap();
 
- }
 
- /// Tests that change outputs in a melt quote are correctly handled
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_melt_change_in_quote() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("Failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let _mint_amount = wallet
 
-         .mint(&mint_quote.id, SplitTarget::default(), None)
 
-         .await
 
-         .unwrap();
 
-     let transaction = wallet
 
-         .list_transactions(Some(TransactionDirection::Incoming))
 
-         .await
 
-         .unwrap()
 
-         .pop()
 
-         .expect("No transaction found");
 
-     assert_eq!(wallet.mint_url, transaction.mint_url);
 
-     assert_eq!(TransactionDirection::Incoming, transaction.direction);
 
-     assert_eq!(Amount::from(100), transaction.amount);
 
-     assert_eq!(Amount::from(0), transaction.fee);
 
-     assert_eq!(CurrencyUnit::Sat, transaction.unit);
 
-     let fake_description = FakeInvoiceDescription::default();
 
-     let invoice = create_fake_invoice(9000, serde_json::to_string(&fake_description).unwrap());
 
-     let proofs = wallet.get_unspent_proofs().await.unwrap();
 
-     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-     let keyset = wallet.fetch_active_keyset().await.unwrap();
 
-     let premint_secrets =
 
-         PreMintSecrets::random(keyset.id, 100.into(), &SplitTarget::default()).unwrap();
 
-     let client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let melt_request = MeltRequest::new(
 
-         melt_quote.id.clone(),
 
-         proofs.clone(),
 
-         Some(premint_secrets.blinded_messages()),
 
-     );
 
-     let melt_response = client.post_melt(melt_request).await.unwrap();
 
-     assert!(melt_response.change.is_some());
 
-     let check = wallet.melt_quote_status(&melt_quote.id).await.unwrap();
 
-     let mut melt_change = melt_response.change.unwrap();
 
-     melt_change.sort_by(|a, b| a.amount.cmp(&b.amount));
 
-     let mut check = check.change.unwrap();
 
-     check.sort_by(|a, b| a.amount.cmp(&b.amount));
 
-     assert_eq!(melt_change, check);
 
- }
 
- /// Tests minting tokens with a valid witness signature
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_with_witness() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let proofs = wallet
 
-         .mint(&mint_quote.id, SplitTarget::default(), None)
 
-         .await
 
-         .unwrap();
 
-     let mint_amount = proofs.total_amount().unwrap();
 
-     assert!(mint_amount == 100.into());
 
- }
 
- /// Tests that minting without a witness signature fails with the correct error
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_without_witness() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
 
-     let premint_secrets =
 
-         PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::default()).unwrap();
 
-     let request = MintRequest {
 
-         quote: mint_quote.id,
 
-         outputs: premint_secrets.blinded_messages(),
 
-         signature: None,
 
-     };
 
-     let response = http_client.post_mint(request.clone()).await;
 
-     match response {
 
-         Err(cdk::error::Error::SignatureMissingOrInvalid) => {} //pass
 
-         Err(err) => panic!("Wrong mint response for minting without witness: {}", err),
 
-         Ok(_) => panic!("Minting should not have succeed without a witness"),
 
-     }
 
- }
 
- /// Tests that minting with an incorrect witness signature fails with the correct error
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_with_wrong_witness() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
 
-     let premint_secrets =
 
-         PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::default()).unwrap();
 
-     let mut request = MintRequest {
 
-         quote: mint_quote.id,
 
-         outputs: premint_secrets.blinded_messages(),
 
-         signature: None,
 
-     };
 
-     let secret_key = SecretKey::generate();
 
-     request
 
-         .sign(secret_key)
 
-         .expect("failed to sign the mint request");
 
-     let response = http_client.post_mint(request.clone()).await;
 
-     match response {
 
-         Err(cdk::error::Error::SignatureMissingOrInvalid) => {} //pass
 
-         Err(err) => panic!("Wrong mint response for minting without witness: {}", err),
 
-         Ok(_) => panic!("Minting should not have succeed without a witness"),
 
-     }
 
- }
 
- /// Tests that attempting to mint more tokens than allowed by the quote fails
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_inflated() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
 
-     let pre_mint =
 
-         PreMintSecrets::random(active_keyset_id, 500.into(), &SplitTarget::None).unwrap();
 
-     let quote_info = wallet
 
-         .localstore
 
-         .get_mint_quote(&mint_quote.id)
 
-         .await
 
-         .unwrap()
 
-         .expect("there is a quote");
 
-     let mut mint_request = MintRequest {
 
-         quote: mint_quote.id,
 
-         outputs: pre_mint.blinded_messages(),
 
-         signature: None,
 
-     };
 
-     if let Some(secret_key) = quote_info.secret_key {
 
-         mint_request
 
-             .sign(secret_key)
 
-             .expect("failed to sign the mint request");
 
-     }
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_mint(mint_request.clone()).await;
 
-     match response {
 
-         Err(err) => match err {
 
-             cdk::Error::TransactionUnbalanced(_, _, _) => (),
 
-             err => {
 
-                 panic!("Wrong mint error returned: {}", err);
 
-             }
 
-         },
 
-         Ok(_) => {
 
-             panic!("Should not have allowed second payment");
 
-         }
 
-     }
 
- }
 
- /// Tests that attempting to mint with multiple currency units in the same request fails
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_multiple_units() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
 
-     let pre_mint = PreMintSecrets::random(active_keyset_id, 50.into(), &SplitTarget::None).unwrap();
 
-     let wallet_usd = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Usd,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
 
-     let usd_pre_mint =
 
-         PreMintSecrets::random(active_keyset_id, 50.into(), &SplitTarget::None).unwrap();
 
-     let quote_info = wallet
 
-         .localstore
 
-         .get_mint_quote(&mint_quote.id)
 
-         .await
 
-         .unwrap()
 
-         .expect("there is a quote");
 
-     let mut sat_outputs = pre_mint.blinded_messages();
 
-     let mut usd_outputs = usd_pre_mint.blinded_messages();
 
-     sat_outputs.append(&mut usd_outputs);
 
-     let mut mint_request = MintRequest {
 
-         quote: mint_quote.id,
 
-         outputs: sat_outputs,
 
-         signature: None,
 
-     };
 
-     if let Some(secret_key) = quote_info.secret_key {
 
-         mint_request
 
-             .sign(secret_key)
 
-             .expect("failed to sign the mint request");
 
-     }
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_mint(mint_request.clone()).await;
 
-     match response {
 
-         Err(err) => match err {
 
-             cdk::Error::MultipleUnits => (),
 
-             err => {
 
-                 panic!("Wrong mint error returned: {}", err);
 
-             }
 
-         },
 
-         Ok(_) => {
 
-             panic!("Should not have allowed to mint with multiple units");
 
-         }
 
-     }
 
- }
 
- /// Tests that attempting to swap tokens with multiple currency units fails
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_multiple_unit_swap() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     wallet.refresh_keysets().await.unwrap();
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let proofs = wallet
 
-         .mint(&mint_quote.id, SplitTarget::None, None)
 
-         .await
 
-         .unwrap();
 
-     let wallet_usd = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Usd,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create usd wallet");
 
-     wallet_usd.refresh_keysets().await.unwrap();
 
-     let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let usd_proofs = wallet_usd
 
-         .mint(&mint_quote.id, SplitTarget::None, None)
 
-         .await
 
-         .unwrap();
 
-     let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
 
-     {
 
-         let inputs: Proofs = vec![
 
-             proofs.first().expect("There is a proof").clone(),
 
-             usd_proofs.first().expect("There is a proof").clone(),
 
-         ];
 
-         let pre_mint = PreMintSecrets::random(
 
-             active_keyset_id,
 
-             inputs.total_amount().unwrap(),
 
-             &SplitTarget::None,
 
-         )
 
-         .unwrap();
 
-         let swap_request = SwapRequest::new(inputs, pre_mint.blinded_messages());
 
-         let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-         let response = http_client.post_swap(swap_request.clone()).await;
 
-         match response {
 
-             Err(err) => match err {
 
-                 cdk::Error::MultipleUnits => (),
 
-                 err => {
 
-                     panic!("Wrong mint error returned: {}", err);
 
-                 }
 
-             },
 
-             Ok(_) => {
 
-                 panic!("Should not have allowed to mint with multiple units");
 
-             }
 
-         }
 
-     }
 
-     {
 
-         let usd_active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
 
-         let inputs: Proofs = proofs.into_iter().take(2).collect();
 
-         let total_inputs = inputs.total_amount().unwrap();
 
-         let half = total_inputs / 2.into();
 
-         let usd_pre_mint =
 
-             PreMintSecrets::random(usd_active_keyset_id, half, &SplitTarget::None).unwrap();
 
-         let pre_mint =
 
-             PreMintSecrets::random(active_keyset_id, total_inputs - half, &SplitTarget::None)
 
-                 .unwrap();
 
-         let mut usd_outputs = usd_pre_mint.blinded_messages();
 
-         let mut sat_outputs = pre_mint.blinded_messages();
 
-         usd_outputs.append(&mut sat_outputs);
 
-         let swap_request = SwapRequest::new(inputs, usd_outputs);
 
-         let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-         let response = http_client.post_swap(swap_request.clone()).await;
 
-         match response {
 
-             Err(err) => match err {
 
-                 cdk::Error::MultipleUnits => (),
 
-                 err => {
 
-                     panic!("Wrong mint error returned: {}", err);
 
-                 }
 
-             },
 
-             Ok(_) => {
 
-                 panic!("Should not have allowed to mint with multiple units");
 
-             }
 
-         }
 
-     }
 
- }
 
- /// Tests that attempting to melt tokens with multiple currency units fails
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_multiple_unit_melt() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let proofs = wallet
 
-         .mint(&mint_quote.id, SplitTarget::None, None)
 
-         .await
 
-         .unwrap();
 
-     println!("Minted sat");
 
-     let wallet_usd = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Usd,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap();
 
-     println!("Minted quote usd");
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let usd_proofs = wallet_usd
 
-         .mint(&mint_quote.id, SplitTarget::None, None)
 
-         .await
 
-         .unwrap();
 
-     {
 
-         let inputs: Proofs = vec![
 
-             proofs.first().expect("There is a proof").clone(),
 
-             usd_proofs.first().expect("There is a proof").clone(),
 
-         ];
 
-         let input_amount: u64 = inputs.total_amount().unwrap().into();
 
-         let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
 
-         let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-         let melt_request = MeltRequest::new(melt_quote.id, inputs, None);
 
-         let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-         let response = http_client.post_melt(melt_request.clone()).await;
 
-         match response {
 
-             Err(err) => match err {
 
-                 cdk::Error::MultipleUnits => (),
 
-                 err => {
 
-                     panic!("Wrong mint error returned: {}", err);
 
-                 }
 
-             },
 
-             Ok(_) => {
 
-                 panic!("Should not have allowed to melt with multiple units");
 
-             }
 
-         }
 
-     }
 
-     {
 
-         let inputs: Proofs = vec![proofs.first().expect("There is a proof").clone()];
 
-         let input_amount: u64 = inputs.total_amount().unwrap().into();
 
-         let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
 
-         let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
 
-         let usd_active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
 
-         let usd_pre_mint = PreMintSecrets::random(
 
-             usd_active_keyset_id,
 
-             inputs.total_amount().unwrap() + 100.into(),
 
-             &SplitTarget::None,
 
-         )
 
-         .unwrap();
 
-         let pre_mint =
 
-             PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None).unwrap();
 
-         let mut usd_outputs = usd_pre_mint.blinded_messages();
 
-         let mut sat_outputs = pre_mint.blinded_messages();
 
-         usd_outputs.append(&mut sat_outputs);
 
-         let quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-         let melt_request = MeltRequest::new(quote.id, inputs, Some(usd_outputs));
 
-         let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-         let response = http_client.post_melt(melt_request.clone()).await;
 
-         match response {
 
-             Err(err) => match err {
 
-                 cdk::Error::MultipleUnits => (),
 
-                 err => {
 
-                     panic!("Wrong mint error returned: {}", err);
 
-                 }
 
-             },
 
-             Ok(_) => {
 
-                 panic!("Should not have allowed to melt with multiple units");
 
-             }
 
-         }
 
-     }
 
- }
 
- /// Tests that swapping tokens where input unit doesn't match output unit fails
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_input_output_mismatch() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let proofs = wallet
 
-         .mint(&mint_quote.id, SplitTarget::None, None)
 
-         .await
 
-         .unwrap();
 
-     let wallet_usd = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Usd,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new  usd wallet");
 
-     let usd_active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
 
-     let inputs = proofs;
 
-     let pre_mint = PreMintSecrets::random(
 
-         usd_active_keyset_id,
 
-         inputs.total_amount().unwrap(),
 
-         &SplitTarget::None,
 
-     )
 
-     .unwrap();
 
-     let swap_request = SwapRequest::new(inputs, pre_mint.blinded_messages());
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_swap(swap_request.clone()).await;
 
-     match response {
 
-         Err(err) => match err {
 
-             cdk::Error::UnitMismatch => (),
 
-             err => panic!("Wrong error returned: {}", err),
 
-         },
 
-         Ok(_) => {
 
-             panic!("Should not have allowed to mint with multiple units");
 
-         }
 
-     }
 
- }
 
- /// Tests that swapping tokens where output amount is greater than input amount fails
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_swap_inflated() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let proofs = wallet
 
-         .mint(&mint_quote.id, SplitTarget::None, None)
 
-         .await
 
-         .unwrap();
 
-     let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
 
-     let pre_mint =
 
-         PreMintSecrets::random(active_keyset_id, 101.into(), &SplitTarget::None).unwrap();
 
-     let swap_request = SwapRequest::new(proofs, pre_mint.blinded_messages());
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_swap(swap_request.clone()).await;
 
-     match response {
 
-         Err(err) => match err {
 
-             cdk::Error::TransactionUnbalanced(_, _, _) => (),
 
-             err => {
 
-                 panic!("Wrong mint error returned: {}", err);
 
-             }
 
-         },
 
-         Ok(_) => {
 
-             panic!("Should not have allowed to mint with multiple units");
 
-         }
 
-     }
 
- }
 
- /// Tests that tokens cannot be spent again after a failed swap attempt
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_swap_spend_after_fail() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let proofs = wallet
 
-         .mint(&mint_quote.id, SplitTarget::None, None)
 
-         .await
 
-         .unwrap();
 
-     let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
 
-     let pre_mint =
 
-         PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None).unwrap();
 
-     let swap_request = SwapRequest::new(proofs.clone(), pre_mint.blinded_messages());
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_swap(swap_request.clone()).await;
 
-     assert!(response.is_ok());
 
-     let pre_mint =
 
-         PreMintSecrets::random(active_keyset_id, 101.into(), &SplitTarget::None).unwrap();
 
-     let swap_request = SwapRequest::new(proofs.clone(), pre_mint.blinded_messages());
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_swap(swap_request.clone()).await;
 
-     match response {
 
-         Err(err) => match err {
 
-             cdk::Error::TransactionUnbalanced(_, _, _) => (),
 
-             err => panic!("Wrong mint error returned expected TransactionUnbalanced, got: {err}"),
 
-         },
 
-         Ok(_) => panic!("Should not have allowed swap with unbalanced"),
 
-     }
 
-     let pre_mint =
 
-         PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None).unwrap();
 
-     let swap_request = SwapRequest::new(proofs, pre_mint.blinded_messages());
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_swap(swap_request.clone()).await;
 
-     match response {
 
-         Err(err) => match err {
 
-             cdk::Error::TokenAlreadySpent => (),
 
-             err => {
 
-                 panic!("Wrong mint error returned: {}", err);
 
-             }
 
-         },
 
-         Ok(_) => {
 
-             panic!("Should not have allowed to mint with multiple units");
 
-         }
 
-     }
 
- }
 
- /// Tests that tokens cannot be melted after a failed swap attempt
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_melt_spend_after_fail() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let proofs = wallet
 
-         .mint(&mint_quote.id, SplitTarget::None, None)
 
-         .await
 
-         .unwrap();
 
-     let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
 
-     let pre_mint =
 
-         PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None).unwrap();
 
-     let swap_request = SwapRequest::new(proofs.clone(), pre_mint.blinded_messages());
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_swap(swap_request.clone()).await;
 
-     assert!(response.is_ok());
 
-     let pre_mint =
 
-         PreMintSecrets::random(active_keyset_id, 101.into(), &SplitTarget::None).unwrap();
 
-     let swap_request = SwapRequest::new(proofs.clone(), pre_mint.blinded_messages());
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_swap(swap_request.clone()).await;
 
-     match response {
 
-         Err(err) => match err {
 
-             cdk::Error::TransactionUnbalanced(_, _, _) => (),
 
-             err => panic!("Wrong mint error returned expected TransactionUnbalanced, got: {err}"),
 
-         },
 
-         Ok(_) => panic!("Should not have allowed swap with unbalanced"),
 
-     }
 
-     let input_amount: u64 = proofs.total_amount().unwrap().into();
 
-     let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
 
-     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-     let melt_request = MeltRequest::new(melt_quote.id, proofs, None);
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_melt(melt_request.clone()).await;
 
-     match response {
 
-         Err(err) => match err {
 
-             cdk::Error::TokenAlreadySpent => (),
 
-             err => {
 
-                 panic!("Wrong mint error returned: {}", err);
 
-             }
 
-         },
 
-         Ok(_) => {
 
-             panic!("Should not have allowed to melt with multiple units");
 
-         }
 
-     }
 
- }
 
- /// Tests that attempting to swap with duplicate proofs fails
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_duplicate_proofs_swap() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let proofs = wallet
 
-         .mint(&mint_quote.id, SplitTarget::None, None)
 
-         .await
 
-         .unwrap();
 
-     let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
 
-     let inputs = vec![proofs[0].clone(), proofs[0].clone()];
 
-     let pre_mint = PreMintSecrets::random(
 
-         active_keyset_id,
 
-         inputs.total_amount().unwrap(),
 
-         &SplitTarget::None,
 
-     )
 
-     .unwrap();
 
-     let swap_request = SwapRequest::new(inputs.clone(), pre_mint.blinded_messages());
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_swap(swap_request.clone()).await;
 
-     match response {
 
-         Err(err) => match err {
 
-             cdk::Error::DuplicateInputs => (),
 
-             err => {
 
-                 panic!(
 
-                     "Wrong mint error returned, expected duplicate inputs: {}",
 
-                     err
 
-                 );
 
-             }
 
-         },
 
-         Ok(_) => {
 
-             panic!("Should not have allowed duplicate inputs");
 
-         }
 
-     }
 
-     let blinded_message = pre_mint.blinded_messages();
 
-     let inputs = vec![proofs[0].clone()];
 
-     let outputs = vec![blinded_message[0].clone(), blinded_message[0].clone()];
 
-     let swap_request = SwapRequest::new(inputs, outputs);
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_swap(swap_request.clone()).await;
 
-     match response {
 
-         Err(err) => match err {
 
-             cdk::Error::DuplicateOutputs => (),
 
-             err => {
 
-                 panic!(
 
-                     "Wrong mint error returned, expected duplicate outputs: {}",
 
-                     err
 
-                 );
 
-             }
 
-         },
 
-         Ok(_) => {
 
-             panic!("Should not have allow duplicate inputs");
 
-         }
 
-     }
 
- }
 
- /// Tests that attempting to melt with duplicate proofs fails
 
- #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
 
- async fn test_fake_mint_duplicate_proofs_melt() {
 
-     let wallet = Wallet::new(
 
-         MINT_URL,
 
-         CurrencyUnit::Sat,
 
-         Arc::new(memory::empty().await.unwrap()),
 
-         Mnemonic::generate(12).unwrap().to_seed_normalized(""),
 
-         None,
 
-     )
 
-     .expect("failed to create new wallet");
 
-     let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
 
-     wallet
 
-         .wait_for_payment(&mint_quote, Duration::from_secs(60))
 
-         .await
 
-         .unwrap();
 
-     let proofs = wallet
 
-         .mint(&mint_quote.id, SplitTarget::None, None)
 
-         .await
 
-         .unwrap();
 
-     let inputs = vec![proofs[0].clone(), proofs[0].clone()];
 
-     let invoice = create_fake_invoice(7000, "".to_string());
 
-     let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
 
-     let melt_request = MeltRequest::new(melt_quote.id, inputs, None);
 
-     let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
 
-     let response = http_client.post_melt(melt_request.clone()).await;
 
-     match response {
 
-         Err(err) => match err {
 
-             cdk::Error::DuplicateInputs => (),
 
-             err => {
 
-                 panic!("Wrong mint error returned: {}", err);
 
-             }
 
-         },
 
-         Ok(_) => {
 
-             panic!("Should not have allow duplicate inputs");
 
-         }
 
-     }
 
- }
 
 
  |