fake_wallet.rs 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  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. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  543. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  544. .await
  545. .unwrap();
  546. let proofs = wallet
  547. .mint(&mint_quote.id, SplitTarget::None, None)
  548. .await
  549. .unwrap();
  550. let wallet_usd = Wallet::new(
  551. MINT_URL,
  552. CurrencyUnit::Usd,
  553. Arc::new(memory::empty().await.unwrap()),
  554. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  555. None,
  556. )
  557. .expect("failed to create usd wallet");
  558. let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap();
  559. wait_for_mint_to_be_paid(&wallet_usd, &mint_quote.id, 60)
  560. .await
  561. .unwrap();
  562. let usd_proofs = wallet_usd
  563. .mint(&mint_quote.id, SplitTarget::None, None)
  564. .await
  565. .unwrap();
  566. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  567. {
  568. let inputs: Proofs = vec![
  569. proofs.first().expect("There is a proof").clone(),
  570. usd_proofs.first().expect("There is a proof").clone(),
  571. ];
  572. let pre_mint = PreMintSecrets::random(
  573. active_keyset_id,
  574. inputs.total_amount().unwrap(),
  575. &SplitTarget::None,
  576. )
  577. .unwrap();
  578. let swap_request = SwapRequest::new(inputs, pre_mint.blinded_messages());
  579. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  580. let response = http_client.post_swap(swap_request.clone()).await;
  581. match response {
  582. Err(err) => match err {
  583. cdk::Error::MultipleUnits => (),
  584. err => {
  585. panic!("Wrong mint error returned: {}", err);
  586. }
  587. },
  588. Ok(_) => {
  589. panic!("Should not have allowed to mint with multiple units");
  590. }
  591. }
  592. }
  593. {
  594. let usd_active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
  595. let inputs: Proofs = proofs.into_iter().take(2).collect();
  596. let total_inputs = inputs.total_amount().unwrap();
  597. let half = total_inputs / 2.into();
  598. let usd_pre_mint =
  599. PreMintSecrets::random(usd_active_keyset_id, half, &SplitTarget::None).unwrap();
  600. let pre_mint =
  601. PreMintSecrets::random(active_keyset_id, total_inputs - half, &SplitTarget::None)
  602. .unwrap();
  603. let mut usd_outputs = usd_pre_mint.blinded_messages();
  604. let mut sat_outputs = pre_mint.blinded_messages();
  605. usd_outputs.append(&mut sat_outputs);
  606. let swap_request = SwapRequest::new(inputs, usd_outputs);
  607. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  608. let response = http_client.post_swap(swap_request.clone()).await;
  609. match response {
  610. Err(err) => match err {
  611. cdk::Error::MultipleUnits => (),
  612. err => {
  613. panic!("Wrong mint error returned: {}", err);
  614. }
  615. },
  616. Ok(_) => {
  617. panic!("Should not have allowed to mint with multiple units");
  618. }
  619. }
  620. }
  621. }
  622. /// Tests that attempting to melt tokens with multiple currency units fails
  623. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  624. async fn test_fake_mint_multiple_unit_melt() {
  625. let wallet = Wallet::new(
  626. MINT_URL,
  627. CurrencyUnit::Sat,
  628. Arc::new(memory::empty().await.unwrap()),
  629. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  630. None,
  631. )
  632. .expect("failed to create new wallet");
  633. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  634. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  635. .await
  636. .unwrap();
  637. let proofs = wallet
  638. .mint(&mint_quote.id, SplitTarget::None, None)
  639. .await
  640. .unwrap();
  641. println!("Minted sat");
  642. let wallet_usd = Wallet::new(
  643. MINT_URL,
  644. CurrencyUnit::Usd,
  645. Arc::new(memory::empty().await.unwrap()),
  646. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  647. None,
  648. )
  649. .expect("failed to create new wallet");
  650. let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap();
  651. println!("Minted quote usd");
  652. wait_for_mint_to_be_paid(&wallet_usd, &mint_quote.id, 60)
  653. .await
  654. .unwrap();
  655. let usd_proofs = wallet_usd
  656. .mint(&mint_quote.id, SplitTarget::None, None)
  657. .await
  658. .unwrap();
  659. {
  660. let inputs: Proofs = vec![
  661. proofs.first().expect("There is a proof").clone(),
  662. usd_proofs.first().expect("There is a proof").clone(),
  663. ];
  664. let input_amount: u64 = inputs.total_amount().unwrap().into();
  665. let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
  666. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  667. let melt_request = MeltRequest::new(melt_quote.id, inputs, None);
  668. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  669. let response = http_client.post_melt(melt_request.clone()).await;
  670. match response {
  671. Err(err) => match err {
  672. cdk::Error::MultipleUnits => (),
  673. err => {
  674. panic!("Wrong mint error returned: {}", err);
  675. }
  676. },
  677. Ok(_) => {
  678. panic!("Should not have allowed to melt with multiple units");
  679. }
  680. }
  681. }
  682. {
  683. let inputs: Proofs = vec![proofs.first().expect("There is a proof").clone()];
  684. let input_amount: u64 = inputs.total_amount().unwrap().into();
  685. let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
  686. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  687. let usd_active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
  688. let usd_pre_mint = PreMintSecrets::random(
  689. usd_active_keyset_id,
  690. inputs.total_amount().unwrap() + 100.into(),
  691. &SplitTarget::None,
  692. )
  693. .unwrap();
  694. let pre_mint =
  695. PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None).unwrap();
  696. let mut usd_outputs = usd_pre_mint.blinded_messages();
  697. let mut sat_outputs = pre_mint.blinded_messages();
  698. usd_outputs.append(&mut sat_outputs);
  699. let quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  700. let melt_request = MeltRequest::new(quote.id, inputs, Some(usd_outputs));
  701. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  702. let response = http_client.post_melt(melt_request.clone()).await;
  703. match response {
  704. Err(err) => match err {
  705. cdk::Error::MultipleUnits => (),
  706. err => {
  707. panic!("Wrong mint error returned: {}", err);
  708. }
  709. },
  710. Ok(_) => {
  711. panic!("Should not have allowed to melt with multiple units");
  712. }
  713. }
  714. }
  715. }
  716. /// Tests that swapping tokens where input unit doesn't match output unit fails
  717. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  718. async fn test_fake_mint_input_output_mismatch() {
  719. let wallet = Wallet::new(
  720. MINT_URL,
  721. CurrencyUnit::Sat,
  722. Arc::new(memory::empty().await.unwrap()),
  723. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  724. None,
  725. )
  726. .expect("failed to create new wallet");
  727. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  728. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  729. .await
  730. .unwrap();
  731. let proofs = wallet
  732. .mint(&mint_quote.id, SplitTarget::None, None)
  733. .await
  734. .unwrap();
  735. let wallet_usd = Wallet::new(
  736. MINT_URL,
  737. CurrencyUnit::Usd,
  738. Arc::new(memory::empty().await.unwrap()),
  739. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  740. None,
  741. )
  742. .expect("failed to create new usd wallet");
  743. let usd_active_keyset_id = wallet_usd.fetch_active_keyset().await.unwrap().id;
  744. let inputs = proofs;
  745. let pre_mint = PreMintSecrets::random(
  746. usd_active_keyset_id,
  747. inputs.total_amount().unwrap(),
  748. &SplitTarget::None,
  749. )
  750. .unwrap();
  751. let swap_request = SwapRequest::new(inputs, pre_mint.blinded_messages());
  752. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  753. let response = http_client.post_swap(swap_request.clone()).await;
  754. match response {
  755. Err(err) => match err {
  756. cdk::Error::UnitMismatch => (),
  757. err => panic!("Wrong error returned: {}", err),
  758. },
  759. Ok(_) => {
  760. panic!("Should not have allowed to mint with multiple units");
  761. }
  762. }
  763. }
  764. /// Tests that swapping tokens where output amount is greater than input amount fails
  765. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  766. async fn test_fake_mint_swap_inflated() {
  767. let wallet = Wallet::new(
  768. MINT_URL,
  769. CurrencyUnit::Sat,
  770. Arc::new(memory::empty().await.unwrap()),
  771. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  772. None,
  773. )
  774. .expect("failed to create new wallet");
  775. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  776. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  777. .await
  778. .unwrap();
  779. let proofs = wallet
  780. .mint(&mint_quote.id, SplitTarget::None, None)
  781. .await
  782. .unwrap();
  783. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  784. let pre_mint =
  785. PreMintSecrets::random(active_keyset_id, 101.into(), &SplitTarget::None).unwrap();
  786. let swap_request = SwapRequest::new(proofs, pre_mint.blinded_messages());
  787. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  788. let response = http_client.post_swap(swap_request.clone()).await;
  789. match response {
  790. Err(err) => match err {
  791. cdk::Error::TransactionUnbalanced(_, _, _) => (),
  792. err => {
  793. panic!("Wrong mint error returned: {}", err);
  794. }
  795. },
  796. Ok(_) => {
  797. panic!("Should not have allowed to mint with multiple units");
  798. }
  799. }
  800. }
  801. /// Tests that tokens cannot be spent again after a failed swap attempt
  802. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  803. async fn test_fake_mint_swap_spend_after_fail() {
  804. let wallet = Wallet::new(
  805. MINT_URL,
  806. CurrencyUnit::Sat,
  807. Arc::new(memory::empty().await.unwrap()),
  808. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  809. None,
  810. )
  811. .expect("failed to create new wallet");
  812. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  813. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  814. .await
  815. .unwrap();
  816. let proofs = wallet
  817. .mint(&mint_quote.id, SplitTarget::None, None)
  818. .await
  819. .unwrap();
  820. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  821. let pre_mint =
  822. PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None).unwrap();
  823. let swap_request = SwapRequest::new(proofs.clone(), pre_mint.blinded_messages());
  824. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  825. let response = http_client.post_swap(swap_request.clone()).await;
  826. assert!(response.is_ok());
  827. let pre_mint =
  828. PreMintSecrets::random(active_keyset_id, 101.into(), &SplitTarget::None).unwrap();
  829. let swap_request = SwapRequest::new(proofs.clone(), pre_mint.blinded_messages());
  830. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  831. let response = http_client.post_swap(swap_request.clone()).await;
  832. match response {
  833. Err(err) => match err {
  834. cdk::Error::TransactionUnbalanced(_, _, _) => (),
  835. err => panic!("Wrong mint error returned expected TransactionUnbalanced, got: {err}"),
  836. },
  837. Ok(_) => panic!("Should not have allowed swap with unbalanced"),
  838. }
  839. let pre_mint =
  840. PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None).unwrap();
  841. let swap_request = SwapRequest::new(proofs, pre_mint.blinded_messages());
  842. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  843. let response = http_client.post_swap(swap_request.clone()).await;
  844. match response {
  845. Err(err) => match err {
  846. cdk::Error::TokenAlreadySpent => (),
  847. err => {
  848. panic!("Wrong mint error returned: {}", err);
  849. }
  850. },
  851. Ok(_) => {
  852. panic!("Should not have allowed to mint with multiple units");
  853. }
  854. }
  855. }
  856. /// Tests that tokens cannot be melted after a failed swap attempt
  857. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  858. async fn test_fake_mint_melt_spend_after_fail() {
  859. let wallet = Wallet::new(
  860. MINT_URL,
  861. CurrencyUnit::Sat,
  862. Arc::new(memory::empty().await.unwrap()),
  863. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  864. None,
  865. )
  866. .expect("failed to create new wallet");
  867. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  868. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  869. .await
  870. .unwrap();
  871. let proofs = wallet
  872. .mint(&mint_quote.id, SplitTarget::None, None)
  873. .await
  874. .unwrap();
  875. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  876. let pre_mint =
  877. PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None).unwrap();
  878. let swap_request = SwapRequest::new(proofs.clone(), pre_mint.blinded_messages());
  879. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  880. let response = http_client.post_swap(swap_request.clone()).await;
  881. assert!(response.is_ok());
  882. let pre_mint =
  883. PreMintSecrets::random(active_keyset_id, 101.into(), &SplitTarget::None).unwrap();
  884. let swap_request = SwapRequest::new(proofs.clone(), pre_mint.blinded_messages());
  885. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  886. let response = http_client.post_swap(swap_request.clone()).await;
  887. match response {
  888. Err(err) => match err {
  889. cdk::Error::TransactionUnbalanced(_, _, _) => (),
  890. err => panic!("Wrong mint error returned expected TransactionUnbalanced, got: {err}"),
  891. },
  892. Ok(_) => panic!("Should not have allowed swap with unbalanced"),
  893. }
  894. let input_amount: u64 = proofs.total_amount().unwrap().into();
  895. let invoice = create_fake_invoice((input_amount - 1) * 1000, "".to_string());
  896. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  897. let melt_request = MeltRequest::new(melt_quote.id, proofs, None);
  898. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  899. let response = http_client.post_melt(melt_request.clone()).await;
  900. match response {
  901. Err(err) => match err {
  902. cdk::Error::TokenAlreadySpent => (),
  903. err => {
  904. panic!("Wrong mint error returned: {}", err);
  905. }
  906. },
  907. Ok(_) => {
  908. panic!("Should not have allowed to melt with multiple units");
  909. }
  910. }
  911. }
  912. /// Tests that attempting to swap with duplicate proofs fails
  913. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  914. async fn test_fake_mint_duplicate_proofs_swap() {
  915. let wallet = Wallet::new(
  916. MINT_URL,
  917. CurrencyUnit::Sat,
  918. Arc::new(memory::empty().await.unwrap()),
  919. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  920. None,
  921. )
  922. .expect("failed to create new wallet");
  923. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  924. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  925. .await
  926. .unwrap();
  927. let proofs = wallet
  928. .mint(&mint_quote.id, SplitTarget::None, None)
  929. .await
  930. .unwrap();
  931. let active_keyset_id = wallet.fetch_active_keyset().await.unwrap().id;
  932. let inputs = vec![proofs[0].clone(), proofs[0].clone()];
  933. let pre_mint = PreMintSecrets::random(
  934. active_keyset_id,
  935. inputs.total_amount().unwrap(),
  936. &SplitTarget::None,
  937. )
  938. .unwrap();
  939. let swap_request = SwapRequest::new(inputs.clone(), pre_mint.blinded_messages());
  940. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  941. let response = http_client.post_swap(swap_request.clone()).await;
  942. match response {
  943. Err(err) => match err {
  944. cdk::Error::DuplicateInputs => (),
  945. err => {
  946. panic!(
  947. "Wrong mint error returned, expected duplicate inputs: {}",
  948. err
  949. );
  950. }
  951. },
  952. Ok(_) => {
  953. panic!("Should not have allowed duplicate inputs");
  954. }
  955. }
  956. let blinded_message = pre_mint.blinded_messages();
  957. let inputs = vec![proofs[0].clone()];
  958. let outputs = vec![blinded_message[0].clone(), blinded_message[0].clone()];
  959. let swap_request = SwapRequest::new(inputs, outputs);
  960. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  961. let response = http_client.post_swap(swap_request.clone()).await;
  962. match response {
  963. Err(err) => match err {
  964. cdk::Error::DuplicateOutputs => (),
  965. err => {
  966. panic!(
  967. "Wrong mint error returned, expected duplicate outputs: {}",
  968. err
  969. );
  970. }
  971. },
  972. Ok(_) => {
  973. panic!("Should not have allow duplicate inputs");
  974. }
  975. }
  976. }
  977. /// Tests that attempting to melt with duplicate proofs fails
  978. #[tokio::test(flavor = "multi_thread", worker_threads = 1)]
  979. async fn test_fake_mint_duplicate_proofs_melt() {
  980. let wallet = Wallet::new(
  981. MINT_URL,
  982. CurrencyUnit::Sat,
  983. Arc::new(memory::empty().await.unwrap()),
  984. Mnemonic::generate(12).unwrap().to_seed_normalized(""),
  985. None,
  986. )
  987. .expect("failed to create new wallet");
  988. let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap();
  989. wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60)
  990. .await
  991. .unwrap();
  992. let proofs = wallet
  993. .mint(&mint_quote.id, SplitTarget::None, None)
  994. .await
  995. .unwrap();
  996. let inputs = vec![proofs[0].clone(), proofs[0].clone()];
  997. let invoice = create_fake_invoice(7000, "".to_string());
  998. let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap();
  999. let melt_request = MeltRequest::new(melt_quote.id, inputs, None);
  1000. let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None);
  1001. let response = http_client.post_melt(melt_request.clone()).await;
  1002. match response {
  1003. Err(err) => match err {
  1004. cdk::Error::DuplicateInputs => (),
  1005. err => {
  1006. panic!("Wrong mint error returned: {}", err);
  1007. }
  1008. },
  1009. Ok(_) => {
  1010. panic!("Should not have allow duplicate inputs");
  1011. }
  1012. }
  1013. }