fake_wallet.rs 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  1. //! Fake Wallet Integration Tests
  2. //!
  3. //! This file contains tests for the fake wallet backend functionality.
  4. //! The fake wallet simulates Lightning Network behavior for testing purposes,
  5. //! allowing verification of mint behavior in various payment scenarios without
  6. //! requiring a real Lightning node.
  7. //!
  8. //! Test Scenarios:
  9. //! - Pending payment states and proof handling
  10. //! - Payment failure cases and proof state management
  11. //! - Change output verification in melt operations
  12. //! - Witness signature validation
  13. //! - Cross-unit transaction validation
  14. //! - Overflow and balance validation
  15. //! - Duplicate proof detection
  16. use std::sync::Arc;
  17. use bip39::Mnemonic;
  18. use cashu::Amount;
  19. use cdk::amount::SplitTarget;
  20. use cdk::nuts::nut00::ProofsMethods;
  21. use cdk::nuts::{
  22. CurrencyUnit, MeltQuoteState, MeltRequest, MintRequest, PreMintSecrets, Proofs, SecretKey,
  23. State, SwapRequest,
  24. };
  25. use cdk::wallet::types::TransactionDirection;
  26. use cdk::wallet::{HttpClient, MintConnector, Wallet};
  27. use cdk_fake_wallet::{create_fake_invoice, FakeInvoiceDescription};
  28. use cdk_integration_tests::{attempt_to_swap_pending, wait_for_mint_to_be_paid};
  29. use cdk_sqlite::wallet::memory;
  30. const MINT_URL: &str = "http://127.0.0.1:8086";
  31. /// Tests that when both pay and check return pending status, input proofs should remain pending
  32. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  33. async fn test_fake_tokens_pending() {
  34. let wallet = Wallet::new(
  35. MINT_URL,
  36. CurrencyUnit::Sat,
  37. Arc::new(memory::empty().await.unwrap()),
  38. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  39. None,
  40. )
  41. .expect("failed to create new wallet");
  42. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  43. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  44. .await
  45. .unwrap();
  46. let _mint_amount = wallet
  47. .mint(&mint_quote.id, SplitTarget::default(), None)
  48. .await
  49. .unwrap();
  50. let fake_description = FakeInvoiceDescription {
  51. pay_invoice_state: MeltQuoteState::Pending,
  52. check_payment_state: MeltQuoteState::Pending,
  53. pay_err: false,
  54. check_err: false,
  55. };
  56. let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
  57. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  58. let melt = wallet.melt(&melt_quote.id).await;
  59. assert!(melt.is_err());
  60. attempt_to_swap_pending(&wallet).await.unwrap();
  61. }
  62. /// Tests that if the pay error fails and the check returns unknown or failed,
  63. /// the input proofs should be unset as spending (returned to unspent state)
  64. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  65. async fn test_fake_melt_payment_fail() {
  66. let wallet = Wallet::new(
  67. MINT_URL,
  68. CurrencyUnit::Sat,
  69. Arc::new(memory::empty().await.unwrap()),
  70. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  71. None,
  72. )
  73. .expect("Failed to create new wallet");
  74. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  75. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  76. .await
  77. .unwrap();
  78. let _mint_amount = wallet
  79. .mint(&mint_quote.id, SplitTarget::default(), None)
  80. .await
  81. .unwrap();
  82. let fake_description = FakeInvoiceDescription {
  83. pay_invoice_state: MeltQuoteState::Unknown,
  84. check_payment_state: MeltQuoteState::Unknown,
  85. pay_err: true,
  86. check_err: false,
  87. };
  88. let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
  89. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  90. // The melt should error at the payment invoice command
  91. let melt = wallet.melt(&melt_quote.id).await;
  92. assert!(melt.is_err());
  93. let fake_description = FakeInvoiceDescription {
  94. pay_invoice_state: MeltQuoteState::Failed,
  95. check_payment_state: MeltQuoteState::Failed,
  96. pay_err: true,
  97. check_err: false,
  98. };
  99. let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap());
  100. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  101. // The melt should error at the payment invoice command
  102. let melt = wallet.melt(&melt_quote.id).await;
  103. assert!(melt.is_err());
  104. // The mint should have unset proofs from pending since payment failed
  105. let all_proof = wallet.get_unspent_proofs().await.unwrap();
  106. let states = wallet.check_proofs_spent(all_proof).await.unwrap();
  107. for state in states {
  108. assert!(state.state == State::Unspent);
  109. }
  110. let wallet_bal = wallet.total_balance().await.unwrap();
  111. assert_eq!(wallet_bal, 100.into());
  112. }
  113. /// Tests that when both the pay_invoice and check_invoice both fail,
  114. /// the proofs should remain in pending state
  115. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  116. async fn test_fake_melt_payment_fail_and_check() {
  117. let wallet = Wallet::new(
  118. MINT_URL,
  119. CurrencyUnit::Sat,
  120. Arc::new(memory::empty().await.unwrap()),
  121. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  122. None,
  123. )
  124. .expect("Failed to create new wallet");
  125. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  126. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  127. .await
  128. .unwrap();
  129. let _mint_amount = wallet
  130. .mint(&mint_quote.id, SplitTarget::default(), None)
  131. .await
  132. .unwrap();
  133. let fake_description = FakeInvoiceDescription {
  134. pay_invoice_state: MeltQuoteState::Unknown,
  135. check_payment_state: MeltQuoteState::Unknown,
  136. pay_err: true,
  137. check_err: true,
  138. };
  139. let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
  140. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  141. // The melt should error at the payment invoice command
  142. let melt = wallet.melt(&melt_quote.id).await;
  143. assert!(melt.is_err());
  144. let pending = wallet
  145. .localstore
  146. .get_proofs(None, None, Some(vec![State::Pending]), None)
  147. .await
  148. .unwrap();
  149. assert!(!pending.is_empty());
  150. }
  151. /// Tests that when the ln backend returns a failed status but does not error,
  152. /// the mint should do a second check, then remove proofs from pending state
  153. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  154. async fn test_fake_melt_payment_return_fail_status() {
  155. let wallet = Wallet::new(
  156. MINT_URL,
  157. CurrencyUnit::Sat,
  158. Arc::new(memory::empty().await.unwrap()),
  159. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  160. None,
  161. )
  162. .expect("Failed to create new wallet");
  163. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  164. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  165. .await
  166. .unwrap();
  167. let _mint_amount = wallet
  168. .mint(&mint_quote.id, SplitTarget::default(), None)
  169. .await
  170. .unwrap();
  171. let fake_description = FakeInvoiceDescription {
  172. pay_invoice_state: MeltQuoteState::Failed,
  173. check_payment_state: MeltQuoteState::Failed,
  174. pay_err: false,
  175. check_err: false,
  176. };
  177. let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
  178. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  179. // The melt should error at the payment invoice command
  180. let melt = wallet.melt(&melt_quote.id).await;
  181. assert!(melt.is_err());
  182. let fake_description = FakeInvoiceDescription {
  183. pay_invoice_state: MeltQuoteState::Unknown,
  184. check_payment_state: MeltQuoteState::Unknown,
  185. pay_err: false,
  186. check_err: false,
  187. };
  188. let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
  189. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  190. // The melt should error at the payment invoice command
  191. let melt = wallet.melt(&melt_quote.id).await;
  192. assert!(melt.is_err());
  193. let pending = wallet
  194. .localstore
  195. .get_proofs(None, None, Some(vec![State::Pending]), None)
  196. .await
  197. .unwrap();
  198. assert!(pending.is_empty());
  199. }
  200. /// Tests that when the ln backend returns an error with unknown status,
  201. /// the mint should do a second check, then remove proofs from pending state
  202. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  203. async fn test_fake_melt_payment_error_unknown() {
  204. let wallet = Wallet::new(
  205. MINT_URL,
  206. CurrencyUnit::Sat,
  207. Arc::new(memory::empty().await.unwrap()),
  208. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  209. None,
  210. )
  211. .unwrap();
  212. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  213. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  214. .await
  215. .unwrap();
  216. let _mint_amount = wallet
  217. .mint(&mint_quote.id, SplitTarget::default(), None)
  218. .await
  219. .unwrap();
  220. let fake_description = FakeInvoiceDescription {
  221. pay_invoice_state: MeltQuoteState::Failed,
  222. check_payment_state: MeltQuoteState::Unknown,
  223. pay_err: true,
  224. check_err: false,
  225. };
  226. let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
  227. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  228. // The melt should error at the payment invoice command
  229. let melt = wallet.melt(&melt_quote.id).await;
  230. assert_eq!(melt.unwrap_err().to_string(), "Payment failed");
  231. let fake_description = FakeInvoiceDescription {
  232. pay_invoice_state: MeltQuoteState::Unknown,
  233. check_payment_state: MeltQuoteState::Unknown,
  234. pay_err: true,
  235. check_err: false,
  236. };
  237. let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
  238. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  239. // The melt should error at the payment invoice command
  240. let melt = wallet.melt(&melt_quote.id).await;
  241. assert_eq!(melt.unwrap_err().to_string(), "Payment failed");
  242. let pending = wallet
  243. .localstore
  244. .get_proofs(None, None, Some(vec![State::Pending]), None)
  245. .await
  246. .unwrap();
  247. assert!(pending.is_empty());
  248. }
  249. /// Tests that when the ln backend returns an error but the second check returns paid,
  250. /// proofs should remain in pending state
  251. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  252. async fn test_fake_melt_payment_err_paid() {
  253. let wallet = Wallet::new(
  254. MINT_URL,
  255. CurrencyUnit::Sat,
  256. Arc::new(memory::empty().await.unwrap()),
  257. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  258. None,
  259. )
  260. .expect("Failed to create new wallet");
  261. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  262. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  263. .await
  264. .unwrap();
  265. let _mint_amount = wallet
  266. .mint(&mint_quote.id, SplitTarget::default(), None)
  267. .await
  268. .unwrap();
  269. let fake_description = FakeInvoiceDescription {
  270. pay_invoice_state: MeltQuoteState::Failed,
  271. check_payment_state: MeltQuoteState::Paid,
  272. pay_err: true,
  273. check_err: false,
  274. };
  275. let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap());
  276. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  277. // The melt should error at the payment invoice command
  278. let melt = wallet.melt(&melt_quote.id).await;
  279. assert!(melt.is_err());
  280. attempt_to_swap_pending(&wallet).await.unwrap();
  281. }
  282. /// Tests that change outputs in a melt quote are correctly handled
  283. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  284. async fn test_fake_melt_change_in_quote() {
  285. let wallet = Wallet::new(
  286. MINT_URL,
  287. CurrencyUnit::Sat,
  288. Arc::new(memory::empty().await.unwrap()),
  289. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  290. None,
  291. )
  292. .expect("Failed to create new wallet");
  293. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  294. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  295. .await
  296. .unwrap();
  297. let _mint_amount = wallet
  298. .mint(&mint_quote.id, SplitTarget::default(), None)
  299. .await
  300. .unwrap();
  301. let transaction = wallet
  302. .list_transactions(Some(TransactionDirection::Incoming))
  303. .await
  304. .unwrap()
  305. .pop()
  306. .expect("No transaction found");
  307. assert_eq!(wallet.mint_url, transaction.mint_url);
  308. assert_eq!(TransactionDirection::Incoming, transaction.direction);
  309. assert_eq!(Amount::from(100), transaction.amount);
  310. assert_eq!(Amount::from(0), transaction.fee);
  311. assert_eq!(CurrencyUnit::Sat, transaction.unit);
  312. let fake_description = FakeInvoiceDescription::default();
  313. let invoice = create_fake_invoice(9000, serde_json::to_string(&fake_description).unwrap());
  314. let proofs = wallet.get_unspent_proofs().await.unwrap();
  315. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  316. let keyset = wallet.fetch_active_keyset().await.unwrap();
  317. let premint_secrets =
  318. PreMintSecrets::random(keyset.id, 100.into(), &SplitTarget::default()).unwrap();
  319. let client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  320. let melt_request = MeltRequest::new(
  321. melt_quote.id.clone(),
  322. proofs.clone(),
  323. Some(premint_secrets.blinded_messages()),
  324. );
  325. let melt_response = client.post_melt(melt_request).await.unwrap();
  326. assert!(melt_response.change.is_some());
  327. let check = wallet.melt_quote_status(&melt_quote.id).await.unwrap();
  328. let mut melt_change = melt_response.change.unwrap();
  329. melt_change.sort_by(|a, b| a.amount.cmp(&b.amount));
  330. let mut check = check.change.unwrap();
  331. check.sort_by(|a, b| a.amount.cmp(&b.amount));
  332. assert_eq!(melt_change, check);
  333. }
  334. /// Tests minting tokens with a valid witness signature
  335. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  336. async fn test_fake_mint_with_witness() {
  337. let wallet = Wallet::new(
  338. MINT_URL,
  339. CurrencyUnit::Sat,
  340. Arc::new(memory::empty().await.unwrap()),
  341. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  342. None,
  343. )
  344. .expect("failed to create new wallet");
  345. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  346. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  347. .await
  348. .unwrap();
  349. let proofs = wallet
  350. .mint(&mint_quote.id, SplitTarget::default(), None)
  351. .await
  352. .unwrap();
  353. let mint_amount = proofs.total_amount().unwrap();
  354. assert!(mint_amount == 100.into());
  355. }
  356. /// Tests that minting without a witness signature fails with the correct error
  357. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  358. async fn test_fake_mint_without_witness() {
  359. let wallet = Wallet::new(
  360. MINT_URL,
  361. CurrencyUnit::Sat,
  362. Arc::new(memory::empty().await.unwrap()),
  363. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  364. None,
  365. )
  366. .expect("failed to create new wallet");
  367. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  368. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  369. .await
  370. .unwrap();
  371. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  372. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  373. let premint_secrets =
  374. PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::default()).unwrap();
  375. let request = MintRequest {
  376. quote: mint_quote.id,
  377. outputs: premint_secrets.blinded_messages(),
  378. signature: None,
  379. };
  380. let response = http_client.post_mint(request.clone()).await;
  381. match response {
  382. Err(cdk::error::Error::SignatureMissingOrInvalid) => {} //pass
  383. Err(err) => panic!("Wrong mint response for minting without witness: {}", err),
  384. Ok(_) => panic!("Minting should not have succeed without a witness"),
  385. }
  386. }
  387. /// Tests that minting with an incorrect witness signature fails with the correct error
  388. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  389. async fn test_fake_mint_with_wrong_witness() {
  390. let wallet = Wallet::new(
  391. MINT_URL,
  392. CurrencyUnit::Sat,
  393. Arc::new(memory::empty().await.unwrap()),
  394. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  395. None,
  396. )
  397. .expect("failed to create new wallet");
  398. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  399. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  400. .await
  401. .unwrap();
  402. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  403. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  404. let premint_secrets =
  405. PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::default()).unwrap();
  406. let mut request = MintRequest {
  407. quote: mint_quote.id,
  408. outputs: premint_secrets.blinded_messages(),
  409. signature: None,
  410. };
  411. let secret_key = SecretKey::generate();
  412. request
  413. .sign(secret_key)
  414. .expect("failed to sign the mint request");
  415. let response = http_client.post_mint(request.clone()).await;
  416. match response {
  417. Err(cdk::error::Error::SignatureMissingOrInvalid) => {} //pass
  418. Err(err) => panic!("Wrong mint response for minting without witness: {}", err),
  419. Ok(_) => panic!("Minting should not have succeed without a witness"),
  420. }
  421. }
  422. /// Tests that attempting to mint more tokens than allowed by the quote fails
  423. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  424. async fn test_fake_mint_inflated() {
  425. let wallet = Wallet::new(
  426. MINT_URL,
  427. CurrencyUnit::Sat,
  428. Arc::new(memory::empty().await.unwrap()),
  429. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  430. None,
  431. )
  432. .expect("failed to create new wallet");
  433. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  434. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  435. .await
  436. .unwrap();
  437. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  438. let pre_mint =
  439. PreMintSecrets::random(active_keyset_id, 500.into(), &SplitTarget::None).unwrap();
  440. let quote_info = wallet
  441. .localstore
  442. .get_mint_quote(&mint_quote.id)
  443. .await
  444. .unwrap()
  445. .expect("there is a quote");
  446. let mut mint_request = MintRequest {
  447. quote: mint_quote.id,
  448. outputs: pre_mint.blinded_messages(),
  449. signature: None,
  450. };
  451. if let Some(secret_key) = quote_info.secret_key {
  452. mint_request
  453. .sign(secret_key)
  454. .expect("failed to sign the mint request");
  455. }
  456. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  457. let response = http_client.post_mint(mint_request.clone()).await;
  458. match response {
  459. Err(err) => match err {
  460. cdk::Error::TransactionUnbalanced(_, _, _) => (),
  461. err => {
  462. panic!("Wrong mint error returned: {}", err);
  463. }
  464. },
  465. Ok(_) => {
  466. panic!("Should not have allowed second payment");
  467. }
  468. }
  469. }
  470. /// Tests that attempting to mint with multiple currency units in the same request fails
  471. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  472. async fn test_fake_mint_multiple_units() {
  473. let wallet = Wallet::new(
  474. MINT_URL,
  475. CurrencyUnit::Sat,
  476. Arc::new(memory::empty().await.unwrap()),
  477. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  478. None,
  479. )
  480. .expect("failed to create new wallet");
  481. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  482. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  483. .await
  484. .unwrap();
  485. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  486. let pre_mint = PreMintSecrets::random(active_keyset_id, 50.into(), &SplitTarget::None).unwrap();
  487. let wallet_usd = Wallet::new(
  488. MINT_URL,
  489. CurrencyUnit::Usd,
  490. Arc::new(memory::empty().await.unwrap()),
  491. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  492. None,
  493. )
  494. .expect("failed to create new wallet");
  495. let active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
  496. let usd_pre_mint =
  497. PreMintSecrets::random(active_keyset_id, 50.into(), &SplitTarget::None).unwrap();
  498. let quote_info = wallet
  499. .localstore
  500. .get_mint_quote(&mint_quote.id)
  501. .await
  502. .unwrap()
  503. .expect("there is a quote");
  504. let mut sat_outputs = pre_mint.blinded_messages();
  505. let mut usd_outputs = usd_pre_mint.blinded_messages();
  506. sat_outputs.append(&mut usd_outputs);
  507. let mut mint_request = MintRequest {
  508. quote: mint_quote.id,
  509. outputs: sat_outputs,
  510. signature: None,
  511. };
  512. if let Some(secret_key) = quote_info.secret_key {
  513. mint_request
  514. .sign(secret_key)
  515. .expect("failed to sign the mint request");
  516. }
  517. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  518. let response = http_client.post_mint(mint_request.clone()).await;
  519. match response {
  520. Err(err) => match err {
  521. cdk::Error::MultipleUnits => (),
  522. err => {
  523. panic!("Wrong mint error returned: {}", err);
  524. }
  525. },
  526. Ok(_) => {
  527. panic!("Should not have allowed to mint with multiple units");
  528. }
  529. }
  530. }
  531. /// Tests that attempting to swap tokens with multiple currency units fails
  532. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  533. async fn test_fake_mint_multiple_unit_swap() {
  534. let wallet = Wallet::new(
  535. MINT_URL,
  536. CurrencyUnit::Sat,
  537. Arc::new(memory::empty().await.unwrap()),
  538. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  539. None,
  540. )
  541. .expect("failed to create new wallet");
  542. wallet.refresh_keysets().await.unwrap();
  543. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  544. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  545. .await
  546. .unwrap();
  547. let proofs = wallet
  548. .mint(&mint_quote.id, SplitTarget::None, None)
  549. .await
  550. .unwrap();
  551. let wallet_usd = Wallet::new(
  552. MINT_URL,
  553. CurrencyUnit::Usd,
  554. Arc::new(memory::empty().await.unwrap()),
  555. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  556. None,
  557. )
  558. .expect("failed to create usd wallet");
  559. wallet_usd.refresh_keysets().await.unwrap();
  560. let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap();
  561. wait_for_mint_to_be_paid(&wallet_usd, &mint_quote.id, 60)
  562. .await
  563. .unwrap();
  564. let usd_proofs = wallet_usd
  565. .mint(&mint_quote.id, SplitTarget::None, None)
  566. .await
  567. .unwrap();
  568. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  569. {
  570. let inputs: Proofs = vec![
  571. proofs.first().expect("There is a proof").clone(),
  572. usd_proofs.first().expect("There is a proof").clone(),
  573. ];
  574. let pre_mint = PreMintSecrets::random(
  575. active_keyset_id,
  576. inputs.total_amount().unwrap(),
  577. &SplitTarget::None,
  578. )
  579. .unwrap();
  580. let swap_request = SwapRequest::new(inputs, pre_mint.blinded_messages());
  581. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  582. let response = http_client.post_swap(swap_request.clone()).await;
  583. match response {
  584. Err(err) => match err {
  585. cdk::Error::MultipleUnits => (),
  586. err => {
  587. panic!("Wrong mint error returned: {}", err);
  588. }
  589. },
  590. Ok(_) => {
  591. panic!("Should not have allowed to mint with multiple units");
  592. }
  593. }
  594. }
  595. {
  596. let usd_active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
  597. let inputs: Proofs = proofs.into_iter().take(2).collect();
  598. let total_inputs = inputs.total_amount().unwrap();
  599. let half = total_inputs / 2.into();
  600. let usd_pre_mint =
  601. PreMintSecrets::random(usd_active_keyset_id, half, &SplitTarget::None).unwrap();
  602. let pre_mint =
  603. PreMintSecrets::random(active_keyset_id, total_inputs - half, &SplitTarget::None)
  604. .unwrap();
  605. let mut usd_outputs = usd_pre_mint.blinded_messages();
  606. let mut sat_outputs = pre_mint.blinded_messages();
  607. usd_outputs.append(&mut sat_outputs);
  608. let swap_request = SwapRequest::new(inputs, usd_outputs);
  609. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  610. let response = http_client.post_swap(swap_request.clone()).await;
  611. match response {
  612. Err(err) => match err {
  613. cdk::Error::MultipleUnits => (),
  614. err => {
  615. panic!("Wrong mint error returned: {}", err);
  616. }
  617. },
  618. Ok(_) => {
  619. panic!("Should not have allowed to mint with multiple units");
  620. }
  621. }
  622. }
  623. }
  624. /// Tests that attempting to melt tokens with multiple currency units fails
  625. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  626. async fn test_fake_mint_multiple_unit_melt() {
  627. let wallet = Wallet::new(
  628. MINT_URL,
  629. CurrencyUnit::Sat,
  630. Arc::new(memory::empty().await.unwrap()),
  631. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  632. None,
  633. )
  634. .expect("failed to create new wallet");
  635. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  636. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  637. .await
  638. .unwrap();
  639. let proofs = wallet
  640. .mint(&mint_quote.id, SplitTarget::None, None)
  641. .await
  642. .unwrap();
  643. println!("Minted sat");
  644. let wallet_usd = Wallet::new(
  645. MINT_URL,
  646. CurrencyUnit::Usd,
  647. Arc::new(memory::empty().await.unwrap()),
  648. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  649. None,
  650. )
  651. .expect("failed to create new wallet");
  652. let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap();
  653. println!("Minted quote usd");
  654. wait_for_mint_to_be_paid(&wallet_usd, &mint_quote.id, 60)
  655. .await
  656. .unwrap();
  657. let usd_proofs = wallet_usd
  658. .mint(&mint_quote.id, SplitTarget::None, None)
  659. .await
  660. .unwrap();
  661. {
  662. let inputs: Proofs = vec![
  663. proofs.first().expect("There is a proof").clone(),
  664. usd_proofs.first().expect("There is a proof").clone(),
  665. ];
  666. let input_amount: u64 = inputs.total_amount().unwrap().into();
  667. let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
  668. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  669. let melt_request = MeltRequest::new(melt_quote.id, inputs, None);
  670. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  671. let response = http_client.post_melt(melt_request.clone()).await;
  672. match response {
  673. Err(err) => match err {
  674. cdk::Error::MultipleUnits => (),
  675. err => {
  676. panic!("Wrong mint error returned: {}", err);
  677. }
  678. },
  679. Ok(_) => {
  680. panic!("Should not have allowed to melt with multiple units");
  681. }
  682. }
  683. }
  684. {
  685. let inputs: Proofs = vec![proofs.first().expect("There is a proof").clone()];
  686. let input_amount: u64 = inputs.total_amount().unwrap().into();
  687. let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
  688. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  689. let usd_active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
  690. let usd_pre_mint = PreMintSecrets::random(
  691. usd_active_keyset_id,
  692. inputs.total_amount().unwrap() + 100.into(),
  693. &SplitTarget::None,
  694. )
  695. .unwrap();
  696. let pre_mint =
  697. PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None).unwrap();
  698. let mut usd_outputs = usd_pre_mint.blinded_messages();
  699. let mut sat_outputs = pre_mint.blinded_messages();
  700. usd_outputs.append(&mut sat_outputs);
  701. let quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  702. let melt_request = MeltRequest::new(quote.id, inputs, Some(usd_outputs));
  703. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  704. let response = http_client.post_melt(melt_request.clone()).await;
  705. match response {
  706. Err(err) => match err {
  707. cdk::Error::MultipleUnits => (),
  708. err => {
  709. panic!("Wrong mint error returned: {}", err);
  710. }
  711. },
  712. Ok(_) => {
  713. panic!("Should not have allowed to melt with multiple units");
  714. }
  715. }
  716. }
  717. }
  718. /// Tests that swapping tokens where input unit doesn't match output unit fails
  719. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  720. async fn test_fake_mint_input_output_mismatch() {
  721. let wallet = Wallet::new(
  722. MINT_URL,
  723. CurrencyUnit::Sat,
  724. Arc::new(memory::empty().await.unwrap()),
  725. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  726. None,
  727. )
  728. .expect("failed to create new wallet");
  729. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  730. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  731. .await
  732. .unwrap();
  733. let proofs = wallet
  734. .mint(&mint_quote.id, SplitTarget::None, None)
  735. .await
  736. .unwrap();
  737. let wallet_usd = Wallet::new(
  738. MINT_URL,
  739. CurrencyUnit::Usd,
  740. Arc::new(memory::empty().await.unwrap()),
  741. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  742. None,
  743. )
  744. .expect("failed to create new usd wallet");
  745. let usd_active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
  746. let inputs = proofs;
  747. let pre_mint = PreMintSecrets::random(
  748. usd_active_keyset_id,
  749. inputs.total_amount().unwrap(),
  750. &SplitTarget::None,
  751. )
  752. .unwrap();
  753. let swap_request = SwapRequest::new(inputs, pre_mint.blinded_messages());
  754. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  755. let response = http_client.post_swap(swap_request.clone()).await;
  756. match response {
  757. Err(err) => match err {
  758. cdk::Error::UnitMismatch => (),
  759. err => panic!("Wrong error returned: {}", err),
  760. },
  761. Ok(_) => {
  762. panic!("Should not have allowed to mint with multiple units");
  763. }
  764. }
  765. }
  766. /// Tests that swapping tokens where output amount is greater than input amount fails
  767. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  768. async fn test_fake_mint_swap_inflated() {
  769. let wallet = Wallet::new(
  770. MINT_URL,
  771. CurrencyUnit::Sat,
  772. Arc::new(memory::empty().await.unwrap()),
  773. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  774. None,
  775. )
  776. .expect("failed to create new wallet");
  777. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  778. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  779. .await
  780. .unwrap();
  781. let proofs = wallet
  782. .mint(&mint_quote.id, SplitTarget::None, None)
  783. .await
  784. .unwrap();
  785. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  786. let pre_mint =
  787. PreMintSecrets::random(active_keyset_id, 101.into(), &SplitTarget::None).unwrap();
  788. let swap_request = SwapRequest::new(proofs, pre_mint.blinded_messages());
  789. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  790. let response = http_client.post_swap(swap_request.clone()).await;
  791. match response {
  792. Err(err) => match err {
  793. cdk::Error::TransactionUnbalanced(_, _, _) => (),
  794. err => {
  795. panic!("Wrong mint error returned: {}", err);
  796. }
  797. },
  798. Ok(_) => {
  799. panic!("Should not have allowed to mint with multiple units");
  800. }
  801. }
  802. }
  803. /// Tests that tokens cannot be spent again after a failed swap attempt
  804. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  805. async fn test_fake_mint_swap_spend_after_fail() {
  806. let wallet = Wallet::new(
  807. MINT_URL,
  808. CurrencyUnit::Sat,
  809. Arc::new(memory::empty().await.unwrap()),
  810. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  811. None,
  812. )
  813. .expect("failed to create new wallet");
  814. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  815. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  816. .await
  817. .unwrap();
  818. let proofs = wallet
  819. .mint(&mint_quote.id, SplitTarget::None, None)
  820. .await
  821. .unwrap();
  822. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  823. let pre_mint =
  824. PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None).unwrap();
  825. let swap_request = SwapRequest::new(proofs.clone(), pre_mint.blinded_messages());
  826. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  827. let response = http_client.post_swap(swap_request.clone()).await;
  828. assert!(response.is_ok());
  829. let pre_mint =
  830. PreMintSecrets::random(active_keyset_id, 101.into(), &SplitTarget::None).unwrap();
  831. let swap_request = SwapRequest::new(proofs.clone(), pre_mint.blinded_messages());
  832. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  833. let response = http_client.post_swap(swap_request.clone()).await;
  834. match response {
  835. Err(err) => match err {
  836. cdk::Error::TransactionUnbalanced(_, _, _) => (),
  837. err => panic!("Wrong mint error returned expected TransactionUnbalanced, got: {err}"),
  838. },
  839. Ok(_) => panic!("Should not have allowed swap with unbalanced"),
  840. }
  841. let pre_mint =
  842. PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None).unwrap();
  843. let swap_request = SwapRequest::new(proofs, pre_mint.blinded_messages());
  844. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  845. let response = http_client.post_swap(swap_request.clone()).await;
  846. match response {
  847. Err(err) => match err {
  848. cdk::Error::TokenAlreadySpent => (),
  849. err => {
  850. panic!("Wrong mint error returned: {}", err);
  851. }
  852. },
  853. Ok(_) => {
  854. panic!("Should not have allowed to mint with multiple units");
  855. }
  856. }
  857. }
  858. /// Tests that tokens cannot be melted after a failed swap attempt
  859. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  860. async fn test_fake_mint_melt_spend_after_fail() {
  861. let wallet = Wallet::new(
  862. MINT_URL,
  863. CurrencyUnit::Sat,
  864. Arc::new(memory::empty().await.unwrap()),
  865. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  866. None,
  867. )
  868. .expect("failed to create new wallet");
  869. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  870. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  871. .await
  872. .unwrap();
  873. let proofs = wallet
  874. .mint(&mint_quote.id, SplitTarget::None, None)
  875. .await
  876. .unwrap();
  877. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  878. let pre_mint =
  879. PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None).unwrap();
  880. let swap_request = SwapRequest::new(proofs.clone(), pre_mint.blinded_messages());
  881. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  882. let response = http_client.post_swap(swap_request.clone()).await;
  883. assert!(response.is_ok());
  884. let pre_mint =
  885. PreMintSecrets::random(active_keyset_id, 101.into(), &SplitTarget::None).unwrap();
  886. let swap_request = SwapRequest::new(proofs.clone(), pre_mint.blinded_messages());
  887. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  888. let response = http_client.post_swap(swap_request.clone()).await;
  889. match response {
  890. Err(err) => match err {
  891. cdk::Error::TransactionUnbalanced(_, _, _) => (),
  892. err => panic!("Wrong mint error returned expected TransactionUnbalanced, got: {err}"),
  893. },
  894. Ok(_) => panic!("Should not have allowed swap with unbalanced"),
  895. }
  896. let input_amount: u64 = proofs.total_amount().unwrap().into();
  897. let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
  898. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  899. let melt_request = MeltRequest::new(melt_quote.id, proofs, None);
  900. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  901. let response = http_client.post_melt(melt_request.clone()).await;
  902. match response {
  903. Err(err) => match err {
  904. cdk::Error::TokenAlreadySpent => (),
  905. err => {
  906. panic!("Wrong mint error returned: {}", err);
  907. }
  908. },
  909. Ok(_) => {
  910. panic!("Should not have allowed to melt with multiple units");
  911. }
  912. }
  913. }
  914. /// Tests that attempting to swap with duplicate proofs fails
  915. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  916. async fn test_fake_mint_duplicate_proofs_swap() {
  917. let wallet = Wallet::new(
  918. MINT_URL,
  919. CurrencyUnit::Sat,
  920. Arc::new(memory::empty().await.unwrap()),
  921. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  922. None,
  923. )
  924. .expect("failed to create new wallet");
  925. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  926. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  927. .await
  928. .unwrap();
  929. let proofs = wallet
  930. .mint(&mint_quote.id, SplitTarget::None, None)
  931. .await
  932. .unwrap();
  933. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  934. let inputs = vec![proofs[0].clone(), proofs[0].clone()];
  935. let pre_mint = PreMintSecrets::random(
  936. active_keyset_id,
  937. inputs.total_amount().unwrap(),
  938. &SplitTarget::None,
  939. )
  940. .unwrap();
  941. let swap_request = SwapRequest::new(inputs.clone(), pre_mint.blinded_messages());
  942. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  943. let response = http_client.post_swap(swap_request.clone()).await;
  944. match response {
  945. Err(err) => match err {
  946. cdk::Error::DuplicateInputs => (),
  947. err => {
  948. panic!(
  949. "Wrong mint error returned, expected duplicate inputs: {}",
  950. err
  951. );
  952. }
  953. },
  954. Ok(_) => {
  955. panic!("Should not have allowed duplicate inputs");
  956. }
  957. }
  958. let blinded_message = pre_mint.blinded_messages();
  959. let inputs = vec![proofs[0].clone()];
  960. let outputs = vec![blinded_message[0].clone(), blinded_message[0].clone()];
  961. let swap_request = SwapRequest::new(inputs, outputs);
  962. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  963. let response = http_client.post_swap(swap_request.clone()).await;
  964. match response {
  965. Err(err) => match err {
  966. cdk::Error::DuplicateOutputs => (),
  967. err => {
  968. panic!(
  969. "Wrong mint error returned, expected duplicate outputs: {}",
  970. err
  971. );
  972. }
  973. },
  974. Ok(_) => {
  975. panic!("Should not have allow duplicate inputs");
  976. }
  977. }
  978. }
  979. /// Tests that attempting to melt with duplicate proofs fails
  980. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  981. async fn test_fake_mint_duplicate_proofs_melt() {
  982. let wallet = Wallet::new(
  983. MINT_URL,
  984. CurrencyUnit::Sat,
  985. Arc::new(memory::empty().await.unwrap()),
  986. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  987. None,
  988. )
  989. .expect("failed to create new wallet");
  990. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  991. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  992. .await
  993. .unwrap();
  994. let proofs = wallet
  995. .mint(&mint_quote.id, SplitTarget::None, None)
  996. .await
  997. .unwrap();
  998. let inputs = vec![proofs[0].clone(), proofs[0].clone()];
  999. let invoice = create_fake_invoice(7000, "".to_string());
  1000. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  1001. let melt_request = MeltRequest::new(melt_quote.id, inputs, None);
  1002. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  1003. let response = http_client.post_melt(melt_request.clone()).await;
  1004. match response {
  1005. Err(err) => match err {
  1006. cdk::Error::DuplicateInputs => (),
  1007. err => {
  1008. panic!("Wrong mint error returned: {}", err);
  1009. }
  1010. },
  1011. Ok(_) => {
  1012. panic!("Should not have allow duplicate inputs");
  1013. }
  1014. }
  1015. }