From ffce3a8aef377cf41419456dbc95932f589a1782 Mon Sep 17 00:00:00 2001 From: KnowWhoami Date: Thu, 1 May 2025 03:29:43 +0530 Subject: [PATCH] test: use expect/unwrap instead of anyhow --- .../tests/fake_wallet.rs | 735 ++++++++++-------- .../tests/happy_path_mint_wallet.rs | 185 +++-- crates/cdk-integration-tests/tests/mint.rs | 36 +- .../tests/nutshell_wallet.rs | 2 - crates/cdk-integration-tests/tests/regtest.rs | 194 +++-- .../cdk-integration-tests/tests/test_fees.rs | 77 +- crates/cdk-mintd/src/config.rs | 2 +- crates/cdk/src/fees.rs | 16 +- crates/cdk/src/mint/mod.rs | 32 +- crates/cdk/src/wallet/proofs.rs | 14 +- 10 files changed, 724 insertions(+), 569 deletions(-) diff --git a/crates/cdk-integration-tests/tests/fake_wallet.rs b/crates/cdk-integration-tests/tests/fake_wallet.rs index b20fad90..b19981c3 100644 --- a/crates/cdk-integration-tests/tests/fake_wallet.rs +++ b/crates/cdk-integration-tests/tests/fake_wallet.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use anyhow::{bail, Result}; use bip39::Mnemonic; use cashu::Amount; use cdk::amount::SplitTarget; @@ -19,22 +18,26 @@ 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() -> Result<()> { +async fn test_fake_tokens_pending() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let _mint_amount = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); let fake_description = FakeInvoiceDescription { pay_invoice_state: MeltQuoteState::Pending, @@ -45,36 +48,38 @@ async fn test_fake_tokens_pending() -> Result<()> { let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap()); - let melt_quote = wallet.melt_quote(invoice.to_string(), None).await?; + 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?; - - Ok(()) + 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() -> Result<()> { +async fn test_fake_melt_payment_fail() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let _mint_amount = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); let fake_description = FakeInvoiceDescription { pay_invoice_state: MeltQuoteState::Unknown, @@ -85,7 +90,7 @@ async fn test_fake_melt_payment_fail() -> Result<()> { let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap()); - let melt_quote = wallet.melt_quote(invoice.to_string(), None).await?; + 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; @@ -100,44 +105,46 @@ async fn test_fake_melt_payment_fail() -> Result<()> { let invoice = create_fake_invoice(1000, serde_json::to_string(&fake_description).unwrap()); - let melt_quote = wallet.melt_quote(invoice.to_string(), None).await?; + 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?; - let states = wallet.check_proofs_spent(all_proof).await?; + 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?; + let wallet_bal = wallet.total_balance().await.unwrap(); assert_eq!(wallet_bal, 100.into()); - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_melt_payment_fail_and_check() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let _mint_amount = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); let fake_description = FakeInvoiceDescription { pay_invoice_state: MeltQuoteState::Unknown, @@ -148,7 +155,7 @@ async fn test_fake_melt_payment_fail_and_check() -> Result<()> { let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap()); - let melt_quote = wallet.melt_quote(invoice.to_string(), None).await?; + 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; @@ -157,32 +164,35 @@ async fn test_fake_melt_payment_fail_and_check() -> Result<()> { let pending = wallet .localstore .get_proofs(None, None, Some(vec![State::Pending]), None) - .await?; + .await + .unwrap(); assert!(!pending.is_empty()); - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_melt_payment_return_fail_status() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let _mint_amount = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); let fake_description = FakeInvoiceDescription { pay_invoice_state: MeltQuoteState::Failed, @@ -193,7 +203,7 @@ async fn test_fake_melt_payment_return_fail_status() -> Result<()> { let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap()); - let melt_quote = wallet.melt_quote(invoice.to_string(), None).await?; + 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; @@ -208,7 +218,7 @@ async fn test_fake_melt_payment_return_fail_status() -> Result<()> { let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap()); - let melt_quote = wallet.melt_quote(invoice.to_string(), None).await?; + 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; @@ -217,32 +227,35 @@ async fn test_fake_melt_payment_return_fail_status() -> Result<()> { let pending = wallet .localstore .get_proofs(None, None, Some(vec![State::Pending]), None) - .await?; + .await + .unwrap(); assert!(pending.is_empty()); - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_melt_payment_error_unknown() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let _mint_amount = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); let fake_description = FakeInvoiceDescription { pay_invoice_state: MeltQuoteState::Failed, @@ -253,7 +266,7 @@ async fn test_fake_melt_payment_error_unknown() -> Result<()> { let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap()); - let melt_quote = wallet.melt_quote(invoice.to_string(), None).await?; + 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; @@ -268,7 +281,7 @@ async fn test_fake_melt_payment_error_unknown() -> Result<()> { let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap()); - let melt_quote = wallet.melt_quote(invoice.to_string(), None).await?; + 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; @@ -277,32 +290,35 @@ async fn test_fake_melt_payment_error_unknown() -> Result<()> { let pending = wallet .localstore .get_proofs(None, None, Some(vec![State::Pending]), None) - .await?; + .await + .unwrap(); assert!(pending.is_empty()); - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_melt_payment_err_paid() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let _mint_amount = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); let fake_description = FakeInvoiceDescription { pay_invoice_state: MeltQuoteState::Failed, @@ -313,39 +329,42 @@ async fn test_fake_melt_payment_err_paid() -> Result<()> { let invoice = create_fake_invoice(7000, serde_json::to_string(&fake_description).unwrap()); - let melt_quote = wallet.melt_quote(invoice.to_string(), None).await?; + 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?; - - Ok(()) + 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() -> Result<()> { +async fn test_fake_melt_change_in_quote() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let _mint_amount = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); let transaction = wallet .list_transactions(Some(TransactionDirection::Incoming)) - .await? + .await + .unwrap() .pop() .expect("No transaction found"); assert_eq!(wallet.mint_url, transaction.mint_url); @@ -358,15 +377,16 @@ async fn test_fake_melt_change_in_quote() -> Result<()> { let invoice = create_fake_invoice(9000, serde_json::to_string(&fake_description).unwrap()); - let proofs = wallet.get_unspent_proofs().await?; + let proofs = wallet.get_unspent_proofs().await.unwrap(); - let melt_quote = wallet.melt_quote(invoice.to_string(), None).await?; + let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap(); - let keyset = wallet.get_active_mint_keyset().await?; + let keyset = wallet.get_active_mint_keyset().await.unwrap(); - let premint_secrets = PreMintSecrets::random(keyset.id, 100.into(), &SplitTarget::default())?; + let premint_secrets = + PreMintSecrets::random(keyset.id, 100.into(), &SplitTarget::default()).unwrap(); - let client = HttpClient::new(MINT_URL.parse()?, None); + let client = HttpClient::new(MINT_URL.parse().unwrap(), None); let melt_request = MeltBolt11Request::new( melt_quote.id.clone(), @@ -374,11 +394,11 @@ async fn test_fake_melt_change_in_quote() -> Result<()> { Some(premint_secrets.blinded_messages()), ); - let melt_response = client.post_melt(melt_request).await?; + 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?; + 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)); @@ -386,13 +406,11 @@ async fn test_fake_melt_change_in_quote() -> Result<()> { check.sort_by(|a, b| a.amount.cmp(&b.amount)); assert_eq!(melt_change, check); - - Ok(()) } /// Tests that the correct database type is used based on environment variables #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_database_type() -> Result<()> { +async fn test_database_type() { // Get the database type and work dir from environment let db_type = std::env::var("CDK_MINTD_DATABASE").expect("MINT_DATABASE env var should be set"); let work_dir = @@ -420,55 +438,58 @@ async fn test_database_type() -> Result<()> { // Memory database has no file to check println!("Memory database in use - no file to check"); } - _ => bail!("Unknown database type: {}", db_type), + _ => panic!("Unknown database type: {}", db_type), } - - Ok(()) } /// Tests minting tokens with a valid witness signature #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_fake_mint_with_witness() -> Result<()> { +async fn test_fake_mint_with_witness() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + Arc::new(memory::empty().await.unwrap()), + &Mnemonic::generate(12).unwrap().to_seed_normalized(""), None, - )?; - let mint_quote = wallet.mint_quote(100.into(), None).await?; + ) + .expect("failed to create new wallet"); + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let proofs = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); - let mint_amount = proofs.total_amount()?; + let mint_amount = proofs.total_amount().unwrap(); assert!(mint_amount == 100.into()); - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_mint_without_witness() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); - let http_client = HttpClient::new(MINT_URL.parse()?, None); + let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None); - let active_keyset_id = wallet.get_active_mint_keyset().await?.id; + let active_keyset_id = wallet.get_active_mint_keyset().await.unwrap().id; let premint_secrets = PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::default()).unwrap(); @@ -482,30 +503,33 @@ async fn test_fake_mint_without_witness() -> Result<()> { let response = http_client.post_mint(request.clone()).await; match response { - Err(cdk::error::Error::SignatureMissingOrInvalid) => Ok(()), - Err(err) => bail!("Wrong mint response for minting without witness: {}", err), - Ok(_) => bail!("Minting should not have succeed without a witness"), + 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() -> Result<()> { +async fn test_fake_mint_with_wrong_witness() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); - let http_client = HttpClient::new(MINT_URL.parse()?, None); + let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None); - let active_keyset_id = wallet.get_active_mint_keyset().await?.id; + let active_keyset_id = wallet.get_active_mint_keyset().await.unwrap().id; let premint_secrets = PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::default()).unwrap(); @@ -518,40 +542,47 @@ async fn test_fake_mint_with_wrong_witness() -> Result<()> { let secret_key = SecretKey::generate(); - request.sign(secret_key)?; + 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) => Ok(()), - Err(err) => bail!("Wrong mint response for minting without witness: {}", err), - Ok(_) => bail!("Minting should not have succeed without a witness"), + 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() -> Result<()> { +async fn test_fake_mint_inflated() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); - let active_keyset_id = wallet.get_active_mint_keyset().await?.id; + let active_keyset_id = wallet.get_active_mint_keyset().await.unwrap().id; - let pre_mint = PreMintSecrets::random(active_keyset_id, 500.into(), &SplitTarget::None)?; + 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? + .await + .unwrap() .expect("there is a quote"); let mut mint_request = MintBolt11Request { @@ -561,9 +592,11 @@ async fn test_fake_mint_inflated() -> Result<()> { }; if let Some(secret_key) = quote_info.secret_key { - mint_request.sign(secret_key)?; + mint_request + .sign(secret_key) + .expect("failed to sign the mint request"); } - let http_client = HttpClient::new(MINT_URL.parse()?, None); + let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None); let response = http_client.post_mint(mint_request.clone()).await; @@ -571,52 +604,56 @@ async fn test_fake_mint_inflated() -> Result<()> { Err(err) => match err { cdk::Error::TransactionUnbalanced(_, _, _) => (), err => { - bail!("Wrong mint error returned: {}", err.to_string()); + panic!("Wrong mint error returned: {}", err); } }, Ok(_) => { - bail!("Should not have allowed second payment"); + panic!("Should not have allowed second payment"); } } - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_mint_multiple_units() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); - let active_keyset_id = wallet.get_active_mint_keyset().await?.id; + let active_keyset_id = wallet.get_active_mint_keyset().await.unwrap().id; - let pre_mint = PreMintSecrets::random(active_keyset_id, 50.into(), &SplitTarget::None)?; + 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?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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.get_active_mint_keyset().await?.id; + let active_keyset_id = wallet_usd.get_active_mint_keyset().await.unwrap().id; - let usd_pre_mint = PreMintSecrets::random(active_keyset_id, 50.into(), &SplitTarget::None)?; + 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? + .await + .unwrap() .expect("there is a quote"); let mut sat_outputs = pre_mint.blinded_messages(); @@ -632,9 +669,11 @@ async fn test_fake_mint_multiple_units() -> Result<()> { }; if let Some(secret_key) = quote_info.secret_key { - mint_request.sign(secret_key)?; + mint_request + .sign(secret_key) + .expect("failed to sign the mint request"); } - let http_client = HttpClient::new(MINT_URL.parse()?, None); + let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None); let response = http_client.post_mint(mint_request.clone()).await; @@ -642,51 +681,59 @@ async fn test_fake_mint_multiple_units() -> Result<()> { Err(err) => match err { cdk::Error::MultipleUnits => (), err => { - bail!("Wrong mint error returned: {}", err.to_string()); + panic!("Wrong mint error returned: {}", err); } }, Ok(_) => { - bail!("Should not have allowed to mint with multiple units"); + panic!("Should not have allowed to mint with multiple units"); } } - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_mint_multiple_unit_swap() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); - let proofs = wallet.mint(&mint_quote.id, SplitTarget::None, None).await?; + 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?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + Arc::new(memory::empty().await.unwrap()), + &Mnemonic::generate(12).unwrap().to_seed_normalized(""), None, - )?; + ) + .expect("failed to create usd wallet"); - let mint_quote = wallet_usd.mint_quote(100.into(), None).await?; + let mint_quote = wallet_usd.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet_usd, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet_usd, &mint_quote.id, 60) + .await + .unwrap(); let usd_proofs = wallet_usd .mint(&mint_quote.id, SplitTarget::None, None) - .await?; + .await + .unwrap(); - let active_keyset_id = wallet.get_active_mint_keyset().await?.id; + let active_keyset_id = wallet.get_active_mint_keyset().await.unwrap().id; { let inputs: Proofs = vec![ @@ -694,37 +741,43 @@ async fn test_fake_mint_multiple_unit_swap() -> Result<()> { usd_proofs.first().expect("There is a proof").clone(), ]; - let pre_mint = - PreMintSecrets::random(active_keyset_id, inputs.total_amount()?, &SplitTarget::None)?; + 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()?, None); + 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 => { - bail!("Wrong mint error returned: {}", err.to_string()); + panic!("Wrong mint error returned: {}", err); } }, Ok(_) => { - bail!("Should not have allowed to mint with multiple units"); + panic!("Should not have allowed to mint with multiple units"); } } } { - let usd_active_keyset_id = wallet_usd.get_active_mint_keyset().await?.id; + let usd_active_keyset_id = wallet_usd.get_active_mint_keyset().await.unwrap().id; let inputs: Proofs = proofs.into_iter().take(2).collect(); - let total_inputs = inputs.total_amount()?; + 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)?; + 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)?; + 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(); @@ -733,39 +786,40 @@ async fn test_fake_mint_multiple_unit_swap() -> Result<()> { let swap_request = SwapRequest::new(inputs, usd_outputs); - let http_client = HttpClient::new(MINT_URL.parse()?, None); + 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 => { - bail!("Wrong mint error returned: {}", err.to_string()); + panic!("Wrong mint error returned: {}", err); } }, Ok(_) => { - bail!("Should not have allowed to mint with multiple units"); + panic!("Should not have allowed to mint with multiple units"); } } } - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_mint_multiple_unit_melt() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let proofs = wallet .mint(&mint_quote.id, SplitTarget::None, None) @@ -777,15 +831,18 @@ async fn test_fake_mint_multiple_unit_melt() -> Result<()> { let wallet_usd = Wallet::new( MINT_URL, CurrencyUnit::Usd, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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"); - wait_for_mint_to_be_paid(&wallet_usd, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet_usd, &mint_quote.id, 60) + .await + .unwrap(); let usd_proofs = wallet_usd .mint(&mint_quote.id, SplitTarget::None, None) @@ -798,24 +855,24 @@ async fn test_fake_mint_multiple_unit_melt() -> Result<()> { usd_proofs.first().expect("There is a proof").clone(), ]; - let input_amount: u64 = inputs.total_amount()?.into(); + 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?; + let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap(); let melt_request = MeltBolt11Request::new(melt_quote.id, inputs, None); - let http_client = HttpClient::new(MINT_URL.parse()?, 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 => { - bail!("Wrong mint error returned: {}", err.to_string()); + panic!("Wrong mint error returned: {}", err); } }, Ok(_) => { - bail!("Should not have allowed to melt with multiple units"); + panic!("Should not have allowed to melt with multiple units"); } } } @@ -823,28 +880,30 @@ async fn test_fake_mint_multiple_unit_melt() -> Result<()> { { let inputs: Proofs = vec![proofs.first().expect("There is a proof").clone()]; - let input_amount: u64 = inputs.total_amount()?.into(); + 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.get_active_mint_keyset().await?.id; - let usd_active_keyset_id = wallet_usd.get_active_mint_keyset().await?.id; + let active_keyset_id = wallet.get_active_mint_keyset().await.unwrap().id; + let usd_active_keyset_id = wallet_usd.get_active_mint_keyset().await.unwrap().id; let usd_pre_mint = PreMintSecrets::random( usd_active_keyset_id, - inputs.total_amount()? + 100.into(), + inputs.total_amount().unwrap() + 100.into(), &SplitTarget::None, - )?; - let pre_mint = PreMintSecrets::random(active_keyset_id, 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?; + let quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap(); let melt_request = MeltBolt11Request::new(quote.id, inputs, Some(usd_outputs)); - let http_client = HttpClient::new(MINT_URL.parse()?, None); + let http_client = HttpClient::new(MINT_URL.parse().unwrap(), None); let response = http_client.post_melt(melt_request.clone()).await; @@ -852,280 +911,312 @@ async fn test_fake_mint_multiple_unit_melt() -> Result<()> { Err(err) => match err { cdk::Error::MultipleUnits => (), err => { - bail!("Wrong mint error returned: {}", err.to_string()); + panic!("Wrong mint error returned: {}", err); } }, Ok(_) => { - bail!("Should not have allowed to melt with multiple units"); + panic!("Should not have allowed to melt with multiple units"); } } } - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_mint_input_output_mismatch() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); - let proofs = wallet.mint(&mint_quote.id, SplitTarget::None, None).await?; + 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?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + Arc::new(memory::empty().await.unwrap()), + &Mnemonic::generate(12).unwrap().to_seed_normalized(""), None, - )?; - let usd_active_keyset_id = wallet_usd.get_active_mint_keyset().await?.id; + ) + .expect("failed to create new usd wallet"); + let usd_active_keyset_id = wallet_usd.get_active_mint_keyset().await.unwrap().id; let inputs = proofs; let pre_mint = PreMintSecrets::random( usd_active_keyset_id, - inputs.total_amount()?, + 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()?, None); + 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 => bail!("Wrong error returned: {}", err), + err => panic!("Wrong error returned: {}", err), }, Ok(_) => { - bail!("Should not have allowed to mint with multiple units"); + panic!("Should not have allowed to mint with multiple units"); } } - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_mint_swap_inflated() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); - let proofs = wallet.mint(&mint_quote.id, SplitTarget::None, None).await?; - let active_keyset_id = wallet.get_active_mint_keyset().await?.id; - let pre_mint = PreMintSecrets::random(active_keyset_id, 101.into(), &SplitTarget::None)?; + let proofs = wallet + .mint(&mint_quote.id, SplitTarget::None, None) + .await + .unwrap(); + let active_keyset_id = wallet.get_active_mint_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()?, None); + 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 => { - bail!("Wrong mint error returned: {}", err.to_string()); + panic!("Wrong mint error returned: {}", err); } }, Ok(_) => { - bail!("Should not have allowed to mint with multiple units"); + panic!("Should not have allowed to mint with multiple units"); } } - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_mint_swap_spend_after_fail() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); - let proofs = wallet.mint(&mint_quote.id, SplitTarget::None, None).await?; - let active_keyset_id = wallet.get_active_mint_keyset().await?.id; + let proofs = wallet + .mint(&mint_quote.id, SplitTarget::None, None) + .await + .unwrap(); + let active_keyset_id = wallet.get_active_mint_keyset().await.unwrap().id; - let pre_mint = PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None)?; + 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()?, None); + 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)?; + 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()?, None); + 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 => bail!("Wrong mint error returned expected TransactionUnbalanced, got: {err}"), + err => panic!("Wrong mint error returned expected TransactionUnbalanced, got: {err}"), }, - Ok(_) => bail!("Should not have allowed swap with unbalanced"), + Ok(_) => panic!("Should not have allowed swap with unbalanced"), } - let pre_mint = PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None)?; + 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()?, None); + 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 => { - bail!("Wrong mint error returned: {}", err.to_string()); + panic!("Wrong mint error returned: {}", err); } }, Ok(_) => { - bail!("Should not have allowed to mint with multiple units"); + panic!("Should not have allowed to mint with multiple units"); } } - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_mint_melt_spend_after_fail() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); - let proofs = wallet.mint(&mint_quote.id, SplitTarget::None, None).await?; - let active_keyset_id = wallet.get_active_mint_keyset().await?.id; + let proofs = wallet + .mint(&mint_quote.id, SplitTarget::None, None) + .await + .unwrap(); + let active_keyset_id = wallet.get_active_mint_keyset().await.unwrap().id; - let pre_mint = PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::None)?; + 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()?, None); + 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)?; + 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()?, None); + 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 => bail!("Wrong mint error returned expected TransactionUnbalanced, got: {err}"), + err => panic!("Wrong mint error returned expected TransactionUnbalanced, got: {err}"), }, - Ok(_) => bail!("Should not have allowed swap with unbalanced"), + Ok(_) => panic!("Should not have allowed swap with unbalanced"), } - let input_amount: u64 = proofs.total_amount()?.into(); + 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?; + let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap(); let melt_request = MeltBolt11Request::new(melt_quote.id, proofs, None); - let http_client = HttpClient::new(MINT_URL.parse()?, 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 => { - bail!("Wrong mint error returned: {}", err.to_string()); + panic!("Wrong mint error returned: {}", err); } }, Ok(_) => { - bail!("Should not have allowed to melt with multiple units"); + panic!("Should not have allowed to melt with multiple units"); } } - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_mint_duplicate_proofs_swap() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); - let proofs = wallet.mint(&mint_quote.id, SplitTarget::None, None).await?; + let proofs = wallet + .mint(&mint_quote.id, SplitTarget::None, None) + .await + .unwrap(); - let active_keyset_id = wallet.get_active_mint_keyset().await?.id; + let active_keyset_id = wallet.get_active_mint_keyset().await.unwrap().id; let inputs = vec![proofs[0].clone(), proofs[0].clone()]; - let pre_mint = - PreMintSecrets::random(active_keyset_id, inputs.total_amount()?, &SplitTarget::None)?; + 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()?, None); + 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 => { - bail!( + panic!( "Wrong mint error returned, expected duplicate inputs: {}", - err.to_string() + err ); } }, Ok(_) => { - bail!("Should not have allowed duplicate inputs"); + panic!("Should not have allowed duplicate inputs"); } } @@ -1135,66 +1226,68 @@ async fn test_fake_mint_duplicate_proofs_swap() -> Result<()> { let swap_request = SwapRequest::new(inputs, outputs); - let http_client = HttpClient::new(MINT_URL.parse()?, None); + 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 => { - bail!( + panic!( "Wrong mint error returned, expected duplicate outputs: {}", - err.to_string() + err ); } }, Ok(_) => { - bail!("Should not have allow duplicate inputs"); + panic!("Should not have allow duplicate inputs"); } } - - Ok(()) } /// 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() -> Result<()> { +async fn test_fake_mint_duplicate_proofs_melt() { let wallet = Wallet::new( MINT_URL, CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); - let proofs = wallet.mint(&mint_quote.id, SplitTarget::None, None).await?; + 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?; + let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap(); let melt_request = MeltBolt11Request::new(melt_quote.id, inputs, None); - let http_client = HttpClient::new(MINT_URL.parse()?, 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 => { - bail!("Wrong mint error returned: {}", err.to_string()); + panic!("Wrong mint error returned: {}", err); } }, Ok(_) => { - bail!("Should not have allow duplicate inputs"); + panic!("Should not have allow duplicate inputs"); } } - - Ok(()) } diff --git a/crates/cdk-integration-tests/tests/happy_path_mint_wallet.rs b/crates/cdk-integration-tests/tests/happy_path_mint_wallet.rs index 41bf1ea4..7097113b 100644 --- a/crates/cdk-integration-tests/tests/happy_path_mint_wallet.rs +++ b/crates/cdk-integration-tests/tests/happy_path_mint_wallet.rs @@ -15,7 +15,6 @@ use std::sync::Arc; use std::time::Duration; use std::{char, env}; -use anyhow::{bail, Result}; use bip39::Mnemonic; use cashu::{MeltBolt11Request, PreMintSecrets}; use cdk::amount::{Amount, SplitTarget}; @@ -78,14 +77,15 @@ async fn get_notification> + Unpin, E: De /// This ensures the entire mint-melt flow works correctly and that /// WebSocket notifications are properly sent at each state transition. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_happy_mint_melt_round_trip() -> Result<()> { +async fn test_happy_mint_melt_round_trip() { let wallet = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + Arc::new(memory::empty().await.unwrap()), + &Mnemonic::generate(12).unwrap().to_seed_normalized(""), None, - )?; + ) + .expect("failed to create new wallet"); let (ws_stream, _) = connect_async(format!( "{}/v1/ws", @@ -95,22 +95,23 @@ async fn test_happy_mint_melt_round_trip() -> Result<()> { .expect("Failed to connect"); let (mut write, mut reader) = ws_stream.split(); - let mint_quote = wallet.mint_quote(100.into(), None).await?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - let invoice = Bolt11Invoice::from_str(&mint_quote.request)?; + let invoice = Bolt11Invoice::from_str(&mint_quote.request).unwrap(); pay_if_regtest(&invoice).await.unwrap(); let proofs = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); - let mint_amount = proofs.total_amount()?; + let mint_amount = proofs.total_amount().unwrap(); assert!(mint_amount == 100.into()); let invoice = create_invoice_for_env(Some(50)).await.unwrap(); - let melt = wallet.melt_quote(invoice, None).await?; + let melt = wallet.melt_quote(invoice, None).await.unwrap(); write .send(Message::Text( @@ -126,10 +127,12 @@ async fn test_happy_mint_melt_round_trip() -> Result<()> { "subId": "test-sub", } - }))? + })) + .unwrap() .into(), )) - .await?; + .await + .unwrap(); assert_eq!( reader @@ -179,8 +182,6 @@ async fn test_happy_mint_melt_round_trip() -> Result<()> { assert_eq!(payload.amount, 50.into()); assert_eq!(payload.quote.to_string(), melt.id); assert_eq!(payload.state, MeltQuoteState::Paid); - - Ok(()) } /// Tests basic minting functionality with payment verification @@ -194,35 +195,37 @@ async fn test_happy_mint_melt_round_trip() -> Result<()> { /// /// This ensures the basic minting flow works correctly from quote to token issuance. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_happy_mint() -> Result<()> { +async fn test_happy_mint() { let wallet = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + Arc::new(memory::empty().await.unwrap()), + &Mnemonic::generate(12).unwrap().to_seed_normalized(""), None, - )?; + ) + .expect("failed to create new wallet"); let mint_amount = Amount::from(100); - let mint_quote = wallet.mint_quote(mint_amount, None).await?; + let mint_quote = wallet.mint_quote(mint_amount, None).await.unwrap(); assert_eq!(mint_quote.amount, mint_amount); - let invoice = Bolt11Invoice::from_str(&mint_quote.request)?; - pay_if_regtest(&invoice).await?; + let invoice = Bolt11Invoice::from_str(&mint_quote.request).unwrap(); + pay_if_regtest(&invoice).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let proofs = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); - let mint_amount = proofs.total_amount()?; + let mint_amount = proofs.total_amount().unwrap(); assert!(mint_amount == 100.into()); - - Ok(()) } /// Tests wallet restoration and proof state verification @@ -240,66 +243,70 @@ async fn test_happy_mint() -> Result<()> { /// This ensures wallet restoration works correctly and that /// the mint properly tracks spent proofs across wallet instances. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_restore() -> Result<()> { - let seed = Mnemonic::generate(12)?.to_seed_normalized(""); +async fn test_restore() { + let seed = Mnemonic::generate(12).unwrap().to_seed_normalized(""); let wallet = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(memory::empty().await?), + Arc::new(memory::empty().await.unwrap()), &seed, None, - )?; + ) + .expect("failed to create new wallet"); - let mint_quote = wallet.mint_quote(100.into(), None).await?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - let invoice = Bolt11Invoice::from_str(&mint_quote.request)?; - pay_if_regtest(&invoice).await?; + let invoice = Bolt11Invoice::from_str(&mint_quote.request).unwrap(); + pay_if_regtest(&invoice).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let _mint_amount = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); - assert_eq!(wallet.total_balance().await?, 100.into()); + assert_eq!(wallet.total_balance().await.unwrap(), 100.into()); let wallet_2 = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(memory::empty().await?), + Arc::new(memory::empty().await.unwrap()), &seed, None, - )?; + ) + .expect("failed to create new wallet"); - assert_eq!(wallet_2.total_balance().await?, 0.into()); + assert_eq!(wallet_2.total_balance().await.unwrap(), 0.into()); - let restored = wallet_2.restore().await?; - let proofs = wallet_2.get_unspent_proofs().await?; + let restored = wallet_2.restore().await.unwrap(); + let proofs = wallet_2.get_unspent_proofs().await.unwrap(); - let expected_fee = wallet.get_proofs_fee(&proofs).await?; + let expected_fee = wallet.get_proofs_fee(&proofs).await.unwrap(); wallet_2 .swap(None, SplitTarget::default(), proofs, None, false) - .await?; + .await + .unwrap(); assert_eq!(restored, 100.into()); // Since we have to do a swap we expect to restore amount - fee assert_eq!( - wallet_2.total_balance().await?, + wallet_2.total_balance().await.unwrap(), Amount::from(100) - expected_fee ); - let proofs = wallet.get_unspent_proofs().await?; + let proofs = wallet.get_unspent_proofs().await.unwrap(); - let states = wallet.check_proofs_spent(proofs).await?; + let states = wallet.check_proofs_spent(proofs).await.unwrap(); for state in states { if state.state != State::Spent { - bail!("All proofs should be spent"); + panic!("All proofs should be spent"); } } - - Ok(()) } /// Tests that change outputs in a melt quote are correctly handled @@ -313,38 +320,43 @@ async fn test_restore() -> Result<()> { /// This ensures the mint correctly processes change outputs during melting operations /// and that the wallet can properly verify the change amounts match expectations. #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_fake_melt_change_in_quote() -> Result<()> { +async fn test_fake_melt_change_in_quote() { let wallet = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - let bolt11 = Bolt11Invoice::from_str(&mint_quote.request)?; + let bolt11 = Bolt11Invoice::from_str(&mint_quote.request).unwrap(); - pay_if_regtest(&bolt11).await?; + pay_if_regtest(&bolt11).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let _mint_amount = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); - let invoice = create_invoice_for_env(Some(9)).await?; + let invoice = create_invoice_for_env(Some(9)).await.unwrap(); - let proofs = wallet.get_unspent_proofs().await?; + let proofs = wallet.get_unspent_proofs().await.unwrap(); - let melt_quote = wallet.melt_quote(invoice.to_string(), None).await?; + let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap(); - let keyset = wallet.get_active_mint_keyset().await?; + let keyset = wallet.get_active_mint_keyset().await.unwrap(); - let premint_secrets = PreMintSecrets::random(keyset.id, 100.into(), &SplitTarget::default())?; + let premint_secrets = + PreMintSecrets::random(keyset.id, 100.into(), &SplitTarget::default()).unwrap(); - let client = HttpClient::new(get_mint_url_from_env().parse()?, None); + let client = HttpClient::new(get_mint_url_from_env().parse().unwrap(), None); let melt_request = MeltBolt11Request::new( melt_quote.id.clone(), @@ -352,11 +364,11 @@ async fn test_fake_melt_change_in_quote() -> Result<()> { Some(premint_secrets.blinded_messages()), ); - let melt_response = client.post_melt(melt_request).await?; + 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?; + 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)); @@ -364,11 +376,10 @@ async fn test_fake_melt_change_in_quote() -> Result<()> { check.sort_by(|a, b| a.amount.cmp(&b.amount)); assert_eq!(melt_change, check); - Ok(()) } #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_pay_invoice_twice() -> Result<()> { +async fn test_pay_invoice_twice() { let ln_backend = match env::var("LN_BACKEND") { Ok(val) => Some(val), Err(_) => env::var("CDK_MINTD_LN_BACKEND").ok(), @@ -376,38 +387,44 @@ async fn test_pay_invoice_twice() -> Result<()> { if ln_backend.map(|ln| ln.to_uppercase()) == Some("FAKEWALLET".to_string()) { // We can only perform this test on regtest backends as fake wallet just marks the quote as paid - return Ok(()); + return; } let wallet = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - pay_if_regtest(&mint_quote.request.parse()?).await?; + pay_if_regtest(&mint_quote.request.parse().unwrap()) + .await + .unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let proofs = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); - let mint_amount = proofs.total_amount()?; + let mint_amount = proofs.total_amount().unwrap(); assert_eq!(mint_amount, 100.into()); - let invoice = create_invoice_for_env(Some(25)).await?; + let invoice = create_invoice_for_env(Some(25)).await.unwrap(); - let melt_quote = wallet.melt_quote(invoice.clone(), None).await?; + let melt_quote = wallet.melt_quote(invoice.clone(), None).await.unwrap(); let melt = wallet.melt(&melt_quote.id).await.unwrap(); - let melt_two = wallet.melt_quote(invoice, None).await?; + let melt_two = wallet.melt_quote(invoice, None).await.unwrap(); let melt_two = wallet.melt(&melt_two.id).await; @@ -415,17 +432,15 @@ async fn test_pay_invoice_twice() -> Result<()> { Err(err) => match err { cdk::Error::RequestAlreadyPaid => (), err => { - bail!("Wrong invoice already paid: {}", err.to_string()); + panic!("Wrong invoice already paid: {}", err.to_string()); } }, Ok(_) => { - bail!("Should not have allowed second payment"); + panic!("Should not have allowed second payment"); } } - let balance = wallet.total_balance().await?; + let balance = wallet.total_balance().await.unwrap(); assert_eq!(balance, (Amount::from(100) - melt.fee_paid - melt.amount)); - - Ok(()) } diff --git a/crates/cdk-integration-tests/tests/mint.rs b/crates/cdk-integration-tests/tests/mint.rs index c2ad803e..a7b4956a 100644 --- a/crates/cdk-integration-tests/tests/mint.rs +++ b/crates/cdk-integration-tests/tests/mint.rs @@ -7,7 +7,6 @@ use std::collections::{HashMap, HashSet}; use std::sync::Arc; -use anyhow::Result; use bip39::Mnemonic; use cdk::cdk_database::MintDatabase; use cdk::mint::{MintBuilder, MintMeltLimits}; @@ -19,8 +18,8 @@ use cdk_sqlite::mint::memory; pub const MINT_URL: &str = "http://127.0.0.1:8088"; #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_correct_keyset() -> Result<()> { - let mnemonic = Mnemonic::generate(12)?; +async fn test_correct_keyset() { + let mnemonic = Mnemonic::generate(12).unwrap(); let fee_reserve = FeeReserve { min_fee_reserve: 1.into(), percent_fee_reserve: 1.0, @@ -41,25 +40,31 @@ async fn test_correct_keyset() -> Result<()> { MintMeltLimits::new(1, 5_000), Arc::new(fake_wallet), ) - .await?; + .await + .unwrap(); mint_builder = mint_builder .with_name("regtest mint".to_string()) .with_description("regtest mint".to_string()) .with_seed(mnemonic.to_seed_normalized("").to_vec()); - let mint = mint_builder.build().await?; + let mint = mint_builder.build().await.unwrap(); localstore .set_mint_info(mint_builder.mint_info.clone()) - .await?; + .await + .unwrap(); let quote_ttl = QuoteTTL::new(10000, 10000); - localstore.set_quote_ttl(quote_ttl).await?; + localstore.set_quote_ttl(quote_ttl).await.unwrap(); - mint.rotate_next_keyset(CurrencyUnit::Sat, 32, 0).await?; - mint.rotate_next_keyset(CurrencyUnit::Sat, 32, 0).await?; + mint.rotate_next_keyset(CurrencyUnit::Sat, 32, 0) + .await + .unwrap(); + mint.rotate_next_keyset(CurrencyUnit::Sat, 32, 0) + .await + .unwrap(); - let active = mint.localstore.get_active_keysets().await?; + let active = mint.localstore.get_active_keysets().await.unwrap(); let active = active .get(&CurrencyUnit::Sat) @@ -68,14 +73,15 @@ async fn test_correct_keyset() -> Result<()> { let keyset_info = mint .localstore .get_keyset_info(active) - .await? + .await + .unwrap() .expect("There is keyset"); assert!(keyset_info.derivation_path_index == Some(2)); - let mint = mint_builder.build().await?; + let mint = mint_builder.build().await.unwrap(); - let active = mint.localstore.get_active_keysets().await?; + let active = mint.localstore.get_active_keysets().await.unwrap(); let active = active .get(&CurrencyUnit::Sat) @@ -84,9 +90,9 @@ async fn test_correct_keyset() -> Result<()> { let keyset_info = mint .localstore .get_keyset_info(active) - .await? + .await + .unwrap() .expect("There is keyset"); assert!(keyset_info.derivation_path_index == Some(2)); - Ok(()) } diff --git a/crates/cdk-integration-tests/tests/nutshell_wallet.rs b/crates/cdk-integration-tests/tests/nutshell_wallet.rs index fa0c2ce7..8074ee96 100644 --- a/crates/cdk-integration-tests/tests/nutshell_wallet.rs +++ b/crates/cdk-integration-tests/tests/nutshell_wallet.rs @@ -104,8 +104,6 @@ async fn get_wallet_balance(base_url: &str) -> u64 { .await .expect("Failed to parse balance response"); - println!("Wallet balance: {:?}", balance); - balance["balance"] .as_u64() .expect("Could not parse balance as u64") diff --git a/crates/cdk-integration-tests/tests/regtest.rs b/crates/cdk-integration-tests/tests/regtest.rs index d50b82ff..ec650645 100644 --- a/crates/cdk-integration-tests/tests/regtest.rs +++ b/crates/cdk-integration-tests/tests/regtest.rs @@ -2,7 +2,6 @@ use std::str::FromStr; use std::sync::Arc; use std::time::Duration; -use anyhow::{bail, Result}; use bip39::Mnemonic; use cashu::ProofsMethods; use cdk::amount::{Amount, SplitTarget}; @@ -40,46 +39,59 @@ async fn init_lnd_client() -> LndClient { } #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_internal_payment() -> Result<()> { +async fn test_internal_payment() { let lnd_client = init_lnd_client().await; let wallet = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - lnd_client.pay_invoice(mint_quote.request).await?; + lnd_client + .pay_invoice(mint_quote.request) + .await + .expect("failed to pay invoice"); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let _mint_amount = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); - assert!(wallet.total_balance().await? == 100.into()); + assert!(wallet.total_balance().await.unwrap() == 100.into()); let wallet_2 = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + Arc::new(memory::empty().await.unwrap()), + &Mnemonic::generate(12).unwrap().to_seed_normalized(""), None, - )?; + ) + .expect("failed to create new wallet"); - let mint_quote = wallet_2.mint_quote(10.into(), None).await?; + let mint_quote = wallet_2.mint_quote(10.into(), None).await.unwrap(); - let melt = wallet.melt_quote(mint_quote.request.clone(), None).await?; + let melt = wallet + .melt_quote(mint_quote.request.clone(), None) + .await + .unwrap(); assert_eq!(melt.amount, 10.into()); let _melted = wallet.melt(&melt.id).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let _wallet_2_mint = wallet_2 .mint(&mint_quote.id, SplitTarget::default(), None) @@ -89,9 +101,9 @@ async fn test_internal_payment() -> Result<()> { let check_paid = match get_mint_port("0") { 8085 => { let cln_one_dir = get_cln_dir("one"); - let cln_client = ClnClient::new(cln_one_dir.clone(), None).await?; + let cln_client = ClnClient::new(cln_one_dir.clone(), None).await.unwrap(); - let payment_hash = Bolt11Invoice::from_str(&mint_quote.request)?; + let payment_hash = Bolt11Invoice::from_str(&mint_quote.request).unwrap(); cln_client .check_incoming_payment_status(&payment_hash.payment_hash().to_string()) .await @@ -104,8 +116,9 @@ async fn test_internal_payment() -> Result<()> { get_lnd_cert_file_path(&lnd_two_dir), get_lnd_macaroon_path(&lnd_two_dir), ) - .await?; - let payment_hash = Bolt11Invoice::from_str(&mint_quote.request)?; + .await + .unwrap(); + let payment_hash = Bolt11Invoice::from_str(&mint_quote.request).unwrap(); lnd_client .check_incoming_payment_status(&payment_hash.payment_hash().to_string()) .await @@ -117,33 +130,32 @@ async fn test_internal_payment() -> Result<()> { match check_paid { InvoiceStatus::Unpaid => (), _ => { - bail!("Invoice has incorrect status: {:?}", check_paid); + panic!("Invoice has incorrect status: {:?}", check_paid); } } - let wallet_2_balance = wallet_2.total_balance().await?; + let wallet_2_balance = wallet_2.total_balance().await.unwrap(); assert!(wallet_2_balance == 10.into()); - let wallet_1_balance = wallet.total_balance().await?; + let wallet_1_balance = wallet.total_balance().await.unwrap(); assert!(wallet_1_balance == 90.into()); - - Ok(()) } #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_websocket_connection() -> Result<()> { +async fn test_websocket_connection() { let wallet = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(wallet::memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + Arc::new(wallet::memory::empty().await.unwrap()), + &Mnemonic::generate(12).unwrap().to_seed_normalized(""), None, - )?; + ) + .expect("failed to create new wallet"); // Create a small mint quote to test notifications - let mint_quote = wallet.mint_quote(10.into(), None).await?; + let mint_quote = wallet.mint_quote(10.into(), None).await.unwrap(); // Subscribe to notifications for this quote let mut subscription = wallet @@ -156,76 +168,92 @@ async fn test_websocket_connection() -> Result<()> { let msg = timeout(Duration::from_secs(10), subscription.recv()) .await .expect("timeout waiting for unpaid notification") - .ok_or_else(|| anyhow::anyhow!("No unpaid notification received"))?; + .expect("No paid notification received"); match msg { NotificationPayload::MintQuoteBolt11Response(response) => { assert_eq!(response.quote.to_string(), mint_quote.id); assert_eq!(response.state, MintQuoteState::Unpaid); } - _ => bail!("Unexpected notification type"), + _ => panic!("Unexpected notification type"), } let lnd_client = init_lnd_client().await; - lnd_client.pay_invoice(mint_quote.request).await?; + lnd_client + .pay_invoice(mint_quote.request) + .await + .expect("failed to pay invoice"); // Wait for paid notification with 10 second timeout let msg = timeout(Duration::from_secs(10), subscription.recv()) .await .expect("timeout waiting for paid notification") - .ok_or_else(|| anyhow::anyhow!("No paid notification received"))?; + .expect("No paid notification received"); match msg { NotificationPayload::MintQuoteBolt11Response(response) => { assert_eq!(response.quote.to_string(), mint_quote.id); assert_eq!(response.state, MintQuoteState::Paid); - Ok(()) } - _ => bail!("Unexpected notification type"), + _ => panic!("Unexpected notification type"), } } #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_multimint_melt() -> Result<()> { +async fn test_multimint_melt() { let lnd_client = init_lnd_client().await; - let db = Arc::new(memory::empty().await?); + let db = Arc::new(memory::empty().await.unwrap()); let wallet1 = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, db, - &Mnemonic::generate(12)?.to_seed_normalized(""), + &Mnemonic::generate(12).unwrap().to_seed_normalized(""), None, - )?; + ) + .expect("failed to create new wallet"); - let db = Arc::new(memory::empty().await?); + let db = Arc::new(memory::empty().await.unwrap()); let wallet2 = Wallet::new( &get_second_mint_url_from_env(), CurrencyUnit::Sat, db, - &Mnemonic::generate(12)?.to_seed_normalized(""), + &Mnemonic::generate(12).unwrap().to_seed_normalized(""), None, - )?; + ) + .expect("failed to create new wallet"); let mint_amount = Amount::from(100); // Fund the wallets - let quote = wallet1.mint_quote(mint_amount, None).await?; - lnd_client.pay_invoice(quote.request.clone()).await?; - wait_for_mint_to_be_paid(&wallet1, "e.id, 60).await?; + let quote = wallet1.mint_quote(mint_amount, None).await.unwrap(); + lnd_client + .pay_invoice(quote.request.clone()) + .await + .expect("failed to pay invoice"); + wait_for_mint_to_be_paid(&wallet1, "e.id, 60) + .await + .unwrap(); wallet1 .mint("e.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); - let quote = wallet2.mint_quote(mint_amount, None).await?; - lnd_client.pay_invoice(quote.request.clone()).await?; - wait_for_mint_to_be_paid(&wallet2, "e.id, 60).await?; + let quote = wallet2.mint_quote(mint_amount, None).await.unwrap(); + lnd_client + .pay_invoice(quote.request.clone()) + .await + .expect("failed to pay invoice"); + wait_for_mint_to_be_paid(&wallet2, "e.id, 60) + .await + .unwrap(); wallet2 .mint("e.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); // Get an invoice - let invoice = lnd_client.create_invoice(Some(50)).await?; + let invoice = lnd_client.create_invoice(Some(50)).await.unwrap(); // Get multi-part melt quotes let melt_options = MeltOptions::Mpp { @@ -254,28 +282,33 @@ async fn test_multimint_melt() -> Result<()> { // Check assert!(result1.state == result2.state); assert!(result1.state == MeltQuoteState::Paid); - Ok(()) } #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_cached_mint() -> Result<()> { +async fn test_cached_mint() { let lnd_client = init_lnd_client().await; let wallet = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + Arc::new(memory::empty().await.unwrap()), + &Mnemonic::generate(12).unwrap().to_seed_normalized(""), None, - )?; + ) + .expect("failed to create new wallet"); let mint_amount = Amount::from(100); - let quote = wallet.mint_quote(mint_amount, None).await?; - lnd_client.pay_invoice(quote.request.clone()).await?; + let quote = wallet.mint_quote(mint_amount, None).await.unwrap(); + lnd_client + .pay_invoice(quote.request.clone()) + .await + .expect("failed to pay invoice"); - wait_for_mint_to_be_paid(&wallet, "e.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, "e.id, 60) + .await + .unwrap(); - let active_keyset_id = wallet.get_active_mint_keyset().await?.id; + let active_keyset_id = wallet.get_active_mint_keyset().await.unwrap().id; let http_client = HttpClient::new(get_mint_url_from_env().parse().unwrap(), None); let premint_secrets = PreMintSecrets::random(active_keyset_id, 100.into(), &SplitTarget::default()).unwrap(); @@ -288,52 +321,59 @@ async fn test_cached_mint() -> Result<()> { let secret_key = quote.secret_key; - request.sign(secret_key.expect("Secret key on quote"))?; + request + .sign(secret_key.expect("Secret key on quote")) + .unwrap(); - let response = http_client.post_mint(request.clone()).await?; - let response1 = http_client.post_mint(request).await?; + let response = http_client.post_mint(request.clone()).await.unwrap(); + let response1 = http_client.post_mint(request).await.unwrap(); assert!(response == response1); - Ok(()) } #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_regtest_melt_amountless() -> Result<()> { +async fn test_regtest_melt_amountless() { let lnd_client = init_lnd_client().await; let wallet = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + Arc::new(memory::empty().await.unwrap()), + &Mnemonic::generate(12).unwrap().to_seed_normalized(""), None, - )?; + ) + .expect("failed to create new wallet"); let mint_amount = Amount::from(100); - let mint_quote = wallet.mint_quote(mint_amount, None).await?; + let mint_quote = wallet.mint_quote(mint_amount, None).await.unwrap(); assert_eq!(mint_quote.amount, mint_amount); - lnd_client.pay_invoice(mint_quote.request).await?; + lnd_client + .pay_invoice(mint_quote.request) + .await + .expect("failed to pay invoice"); let proofs = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); - let amount = proofs.total_amount()?; + let amount = proofs.total_amount().unwrap(); assert!(mint_amount == amount); - let invoice = lnd_client.create_invoice(None).await?; + let invoice = lnd_client.create_invoice(None).await.unwrap(); let options = MeltOptions::new_amountless(5_000); - let melt_quote = wallet.melt_quote(invoice.clone(), Some(options)).await?; + let melt_quote = wallet + .melt_quote(invoice.clone(), Some(options)) + .await + .unwrap(); let melt = wallet.melt(&melt_quote.id).await.unwrap(); assert!(melt.amount == 5.into()); - - Ok(()) } diff --git a/crates/cdk-integration-tests/tests/test_fees.rs b/crates/cdk-integration-tests/tests/test_fees.rs index ace2eb6d..da7c24f4 100644 --- a/crates/cdk-integration-tests/tests/test_fees.rs +++ b/crates/cdk-integration-tests/tests/test_fees.rs @@ -1,7 +1,6 @@ use std::str::FromStr; use std::sync::Arc; -use anyhow::Result; use bip39::Mnemonic; use cashu::{Bolt11Invoice, ProofsMethods}; use cdk::amount::{Amount, SplitTarget}; @@ -13,28 +12,31 @@ use cdk_integration_tests::{ use cdk_sqlite::wallet::memory; #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_swap() -> Result<()> { - let seed = Mnemonic::generate(12)?.to_seed_normalized(""); +async fn test_swap() { + let seed = Mnemonic::generate(12).unwrap().to_seed_normalized(""); let wallet = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(memory::empty().await?), + Arc::new(memory::empty().await.unwrap()), &seed, None, - )?; + ) + .expect("failed to create new wallet"); - let mint_quote = wallet.mint_quote(100.into(), None).await?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - let invoice = Bolt11Invoice::from_str(&mint_quote.request)?; - pay_if_regtest(&invoice).await?; + let invoice = Bolt11Invoice::from_str(&mint_quote.request).unwrap(); + pay_if_regtest(&invoice).await.unwrap(); let _mint_amount = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); let proofs: Vec = wallet .get_unspent_proofs() - .await? + .await + .unwrap() .iter() .map(|p| p.amount) .collect(); @@ -49,65 +51,72 @@ async fn test_swap() -> Result<()> { ..Default::default() }, ) - .await?; + .await + .unwrap(); let proofs = send.proofs(); - let fee = wallet.get_proofs_fee(&proofs).await?; + let fee = wallet.get_proofs_fee(&proofs).await.unwrap(); assert_eq!(fee, 1.into()); - let send = wallet.send(send, None).await?; + let send = wallet.send(send, None).await.unwrap(); let rec_amount = wallet .receive(&send.to_string(), ReceiveOptions::default()) - .await?; + .await + .unwrap(); assert_eq!(rec_amount, 3.into()); - let wallet_balance = wallet.total_balance().await?; + let wallet_balance = wallet.total_balance().await.unwrap(); assert_eq!(wallet_balance, 99.into()); - - Ok(()) } #[tokio::test(flavor = "multi_thread", worker_threads = 1)] -async fn test_fake_melt_change_in_quote() -> Result<()> { +async fn test_fake_melt_change_in_quote() { let wallet = Wallet::new( &get_mint_url_from_env(), CurrencyUnit::Sat, - Arc::new(memory::empty().await?), - &Mnemonic::generate(12)?.to_seed_normalized(""), + 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?; + let mint_quote = wallet.mint_quote(100.into(), None).await.unwrap(); - let bolt11 = Bolt11Invoice::from_str(&mint_quote.request)?; + let bolt11 = Bolt11Invoice::from_str(&mint_quote.request).unwrap(); - pay_if_regtest(&bolt11).await?; + pay_if_regtest(&bolt11).await.unwrap(); - wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60).await?; + wait_for_mint_to_be_paid(&wallet, &mint_quote.id, 60) + .await + .unwrap(); let _mint_amount = wallet .mint(&mint_quote.id, SplitTarget::default(), None) - .await?; + .await + .unwrap(); let invoice_amount = 9; - let invoice = create_invoice_for_env(Some(invoice_amount)).await?; + let invoice = create_invoice_for_env(Some(invoice_amount)).await.unwrap(); - let melt_quote = wallet.melt_quote(invoice.to_string(), None).await?; + let melt_quote = wallet.melt_quote(invoice.to_string(), None).await.unwrap(); - let proofs = wallet.get_unspent_proofs().await?; + let proofs = wallet.get_unspent_proofs().await.unwrap(); let proofs_total = proofs.total_amount().unwrap(); - let fee = wallet.get_proofs_fee(&proofs).await?; - let melt = wallet.melt_proofs(&melt_quote.id, proofs.clone()).await?; + let fee = wallet.get_proofs_fee(&proofs).await.unwrap(); + let melt = wallet + .melt_proofs(&melt_quote.id, proofs.clone()) + .await + .unwrap(); let change = melt.change.unwrap().total_amount().unwrap(); - let idk = proofs.total_amount()? - Amount::from(invoice_amount) - change; + let idk = proofs.total_amount().unwrap() - Amount::from(invoice_amount) - change; println!("{}", idk); println!("{}", fee); @@ -117,9 +126,7 @@ async fn test_fake_melt_change_in_quote() -> Result<()> { let ln_fee = 1; assert_eq!( - wallet.total_balance().await?, + wallet.total_balance().await.unwrap(), Amount::from(100 - invoice_amount - u64::from(fee) - ln_fee) ); - - Ok(()) } diff --git a/crates/cdk-mintd/src/config.rs b/crates/cdk-mintd/src/config.rs index 5919b697..6aaaff7b 100644 --- a/crates/cdk-mintd/src/config.rs +++ b/crates/cdk-mintd/src/config.rs @@ -383,7 +383,7 @@ mod tests { }; // Convert the Info struct to a debug string - let debug_output = format!("{:?}", info); + let debug_output = format!("{info:?}"); // Verify the debug output contains expected fields assert!(debug_output.contains("url: \"http://example.com\"")); diff --git a/crates/cdk/src/fees.rs b/crates/cdk/src/fees.rs index 69cb39f7..40d4a239 100644 --- a/crates/cdk/src/fees.rs +++ b/crates/cdk/src/fees.rs @@ -42,7 +42,7 @@ mod tests { use super::*; #[test] - fn test_calc_fee() -> anyhow::Result<()> { + fn test_calc_fee() { let keyset_id = Id::from_str("001711afb1de20cb").unwrap(); let fee = 2; @@ -54,34 +54,32 @@ mod tests { proofs_count.insert(keyset_id, 1); - let sum_fee = calculate_fee(&proofs_count, &keyset_fees)?; + let sum_fee = calculate_fee(&proofs_count, &keyset_fees).unwrap(); assert_eq!(sum_fee, 1.into()); proofs_count.insert(keyset_id, 500); - let sum_fee = calculate_fee(&proofs_count, &keyset_fees)?; + let sum_fee = calculate_fee(&proofs_count, &keyset_fees).unwrap(); assert_eq!(sum_fee, 1.into()); proofs_count.insert(keyset_id, 1000); - let sum_fee = calculate_fee(&proofs_count, &keyset_fees)?; + let sum_fee = calculate_fee(&proofs_count, &keyset_fees).unwrap(); assert_eq!(sum_fee, 2.into()); proofs_count.insert(keyset_id, 2000); - let sum_fee = calculate_fee(&proofs_count, &keyset_fees)?; + let sum_fee = calculate_fee(&proofs_count, &keyset_fees).unwrap(); assert_eq!(sum_fee, 4.into()); proofs_count.insert(keyset_id, 3500); - let sum_fee = calculate_fee(&proofs_count, &keyset_fees)?; + let sum_fee = calculate_fee(&proofs_count, &keyset_fees).unwrap(); assert_eq!(sum_fee, 7.into()); proofs_count.insert(keyset_id, 3501); - let sum_fee = calculate_fee(&proofs_count, &keyset_fees)?; + let sum_fee = calculate_fee(&proofs_count, &keyset_fees).unwrap(); assert_eq!(sum_fee, 8.into()); - - Ok(()) } } diff --git a/crates/cdk/src/mint/mod.rs b/crates/cdk/src/mint/mod.rs index 88fbbf0d..076b9f9c 100644 --- a/crates/cdk/src/mint/mod.rs +++ b/crates/cdk/src/mint/mod.rs @@ -764,7 +764,7 @@ mod tests { melt_requests: Vec<(MeltBolt11Request, PaymentProcessorKey)>, } - async fn create_mint(config: MintConfig<'_>) -> Result { + async fn create_mint(config: MintConfig<'_>) -> Mint { let localstore = Arc::new( new_with_state( config.active_keysets, @@ -788,14 +788,15 @@ mod tests { HashMap::new(), ) .await + .unwrap() } #[tokio::test] - async fn mint_mod_new_mint() -> Result<(), Error> { + async fn mint_mod_new_mint() { let config = MintConfig::<'_> { ..Default::default() }; - let mint = create_mint(config).await?; + let mint = create_mint(config).await; assert_eq!( mint.pubkeys().await.unwrap(), @@ -820,23 +821,22 @@ mod tests { mint.total_redeemed().await.unwrap(), HashMap::::new() ); - - Ok(()) } #[tokio::test] - async fn mint_mod_rotate_keyset() -> Result<(), Error> { + async fn mint_mod_rotate_keyset() { let config = MintConfig::<'_> { ..Default::default() }; - let mint = create_mint(config).await?; + let mint = create_mint(config).await; let keysets = mint.keysets().await.unwrap(); assert!(keysets.keysets.is_empty()); // generate the first keyset and set it to active mint.rotate_keyset(CurrencyUnit::default(), 0, 1, 1, &HashMap::new()) - .await?; + .await + .unwrap(); let keysets = mint.keysets().await.unwrap(); assert!(keysets.keysets.len().eq(&1)); @@ -845,7 +845,8 @@ mod tests { // set the first keyset to inactive and generate a new keyset mint.rotate_keyset(CurrencyUnit::default(), 1, 1, 1, &HashMap::new()) - .await?; + .await + .unwrap(); let keysets = mint.keysets().await.unwrap(); @@ -857,34 +858,29 @@ mod tests { assert!(keyset.active); } } - - Ok(()) } #[tokio::test] - async fn test_mint_keyset_gen() -> Result<(), Error> { + async fn test_mint_keyset_gen() { let seed = bip39::Mnemonic::from_str( "dismiss price public alone audit gallery ignore process swap dance crane furnace", ) .unwrap(); - println!("{}", seed); - let config = MintConfig::<'_> { seed: &seed.to_seed_normalized(""), ..Default::default() }; - let mint = create_mint(config).await?; + let mint = create_mint(config).await; mint.rotate_keyset(CurrencyUnit::default(), 0, 32, 1, &HashMap::new()) - .await?; + .await + .unwrap(); let keys = mint.keysets.read().await.clone(); let expected_keys = r#"{"005f6e8c540c9e61":{"id":"005f6e8c540c9e61","unit":"sat","keys":{"1":{"public_key":"03e8aded7525acee36e3394e28f2dcbc012533ef2a2b085a55fc291d311afee3ef","secret_key":"32ee9fc0723772aed4c7b8ac0a02ffe390e54a4e0b037ec6035c2afa10ebd873"},"2":{"public_key":"02628c0919e5cb8ce9aed1f81ce313f40e1ab0b33439d5be2abc69d9bb574902e0","secret_key":"48384bf901bbe8f937d601001d067e73b28b435819c009589350c664f9ba872c"},"4":{"public_key":"039e7c7f274e1e8a90c61669e961c944944e6154c0794fccf8084af90252d2848f","secret_key":"1f039c1e54e9e65faae8ecf69492f810b4bb2292beb3734059f2bb4d564786d0"},"8":{"public_key":"02ca0e563ae941700aefcb16a7fb820afbb3258ae924ab520210cb730227a76ca3","secret_key":"ea3c2641d847c9b15c5f32c150b5c9c04d0666af0549e54f51f941cf584442be"},"16":{"public_key":"031dbab0e4f7fb4fb0030f0e1a1dc80668eadd0b1046df3337bb13a7b9c982d392","secret_key":"5b244f8552077e68b30b534e85bd0e8e29ae0108ff47f5cd92522aa524d3288f"},"32":{"public_key":"037241f7ad421374eb764a48e7769b5e2473582316844fda000d6eef28eea8ffb8","secret_key":"95608f61dd690aef34e6a2d4cbef3ad8fddb4537a14480a17512778058e4f5bd"},"64":{"public_key":"02bc9767b4abf88becdac47a59e67ee9a9a80b9864ef57d16084575273ac63c0e7","secret_key":"2e9cd067fafa342f3118bc1e62fbb8e53acdb0f96d51ce8a1e1037e43fad0dce"},"128":{"public_key":"0351e33a076f415c2cadc945bc9bcb75bf4a774b28df8a0605dea1557e5897fed8","secret_key":"7014f27be5e2b77e4951a81c18ae3585d0b037899d8a37b774970427b13d8f65"},"256":{"public_key":"0314b9f4300367c7e64fa85770da90839d2fc2f57d63660f08bb3ebbf90ed76840","secret_key":"1a545bd9c40fc6cf2ab281710e279967e9f4b86cd07761c741da94bc8042c8fb"},"512":{"public_key":"030d95abc7e881d173f4207a3349f4ee442b9e51cc461602d3eb9665b9237e8db3","secret_key":"622984ef16d1cb28e9adc7a7cfea1808d85b4bdabd015977f0320c9f573858b4"},"1024":{"public_key":"0351a68a667c5fc21d66c187baecefa1d65529d06b7ae13112d432b6bca16b0e8c","secret_key":"6a8badfa26129499b60edb96cda4cbcf08f8007589eb558a9d0307bdc56e0ff6"},"2048":{"public_key":"0376166d8dcf97d8b0e9f11867ff0dafd439c90255b36a25be01e37e14741b9c6a","secret_key":"48fe41181636716ce202b3a3303c2475e6d511991930868d907441e1bcbf8566"},"4096":{"public_key":"03d40f47b4e5c4d72f2a977fab5c66b54d945b2836eb888049b1dd9334d1d70304","secret_key":"66a25bf144a3b40c015dd1f630aa4ba81d2242f5aee845e4f378246777b21676"},"8192":{"public_key":"03be18afaf35a29d7bcd5dfd1936d82c1c14691a63f8aa6ece258e16b0c043049b","secret_key":"4ddac662e82f6028888c11bdefd07229d7c1b56987395f106cc9ea5b301695f6"},"16384":{"public_key":"028e9c6ce70f34cd29aad48656bf8345bb5ba2cb4f31fdd978686c37c93f0ab411","secret_key":"83676bd7d047655476baecad2864519f0ffd8e60f779956d2faebcc727caa7bd"},"32768":{"public_key":"0253e34bab4eec93e235c33994e01bf851d5caca4559f07d37b5a5c266de7cf840","secret_key":"d5be522906223f5d92975e2a77f7e166aa121bf93d5fe442d6d132bf67166b04"},"65536":{"public_key":"02684ede207f9ace309b796b5259fc81ef0d4492b4fb5d66cf866b0b4a6f27bec9","secret_key":"20d859b7052d768e007bf285ee11dc0b98a4abfe272a551852b0cce9fb6d5ad4"},"131072":{"public_key":"027cdf7be8b20a49ac7f2f065f7c53764c8926799877858c6b00b888a8aa6741a5","secret_key":"f6eef28183344b32fc0a1fba00cd6cf967614e51d1c990f0bfce8f67c6d9746a"},"262144":{"public_key":"026939b8f766c3ebaf26408e7e54fc833805563e2ef14c8ee4d0435808b005ec4c","secret_key":"690f23e4eaa250c652afeac24d4efb583095a66abf6b87a7f3d17b1f42c5f896"},"524288":{"public_key":"03772542057493a46eed6513b40386e766eedada16560ffde2f776b65794e9f004","secret_key":"fe36e61bea74665f8796b4b62f9501ae6e0d5b16733d2c05c146cd39f89475a0"},"1048576":{"public_key":"02b016346e5a322d371c6e6164b28b31b4d93a51572351ca2f26cdc12e916d9ac3","secret_key":"b9269779e057ce715964caa6d6b5b65672f255e86746e994b6b8c4780cb9d728"},"2097152":{"public_key":"028f25283e36a11df7713934a5287267381f8304aca3c1eb1b89fddce973ef1436","secret_key":"41aec998b9624ddcff97eb7341daa6385b2a8714ed3f12969ef39649f4d641ab"},"4194304":{"public_key":"03e5841d310819a49ec42dfb24839c61f68bbfc93ac68f6dad37fd5b2d204cc535","secret_key":"e5aef2509c56236f004e2df4343beab6406816fb187c3532d4340a9674857c64"},"8388608":{"public_key":"0307ebfeb87b7bca9baa03fad00499e5cc999fa5179ef0b7ad4f555568bcb946f5","secret_key":"369e8dcabcc69a2eabb7363beb66178cafc29e53b02c46cd15374028c3110541"},"16777216":{"public_key":"02f2508e7df981c32f7b0008a273e2a1f19c23bb60a1561dba6b2a95ed1251eb90","secret_key":"f93965b96ed5428bcacd684eff2f43a9777d03adfde867fa0c6efb39c46a7550"},"33554432":{"public_key":"0381883a1517f8c9979a84fcd5f18437b1a2b0020376ecdd2e515dc8d5a157a318","secret_key":"7f5e77c7ed04dff952a7c15564ab551c769243eb65423adfebf46bf54360cd64"},"67108864":{"public_key":"02aa648d39c9a725ef5927db15af6895f0d43c17f0a31faff4406314fc80180086","secret_key":"d34eda86679bf872dfb6faa6449285741bba6c6d582cd9fe5a9152d5752596cc"},"134217728":{"public_key":"0380658e5163fcf274e1ace6c696d1feef4c6068e0d03083d676dc5ef21804f22d","secret_key":"3ad22e92d497309c5b08b2dc01cb5180de3e00d3d703229914906bc847183987"},"268435456":{"public_key":"031526f03de945c638acccb879de837ac3fabff8590057cfb8552ebcf51215f3aa","secret_key":"3a740771e29119b171ab8e79e97499771439e0ab6a082ec96e43baf06a546372"},"536870912":{"public_key":"035eb3e7262e126c5503e1b402db05f87de6556773ae709cb7aa1c3b0986b87566","secret_key":"9b77ee8cd879128c0ea6952dd188e63617fbaa9e66a3bca0244bcceb9b1f7f48"},"1073741824":{"public_key":"03f12e6a0903ed0db87485a296b1dca9d953a8a6919ff88732238fbc672d6bd125","secret_key":"f3947bca4df0f024eade569c81c5c53e167476e074eb81fa6b289e5e10dd4e42"},"2147483648":{"public_key":"02cece3fb38a54581e0646db4b29242b6d78e49313dda46764094f9d128c1059c1","secret_key":"582d54a894cd41441157849e0d16750e5349bd9310776306e7313b255866950b"}}}}"#; assert_eq!(expected_keys, serde_json::to_string(&keys.clone()).unwrap()); - - Ok(()) } } diff --git a/crates/cdk/src/wallet/proofs.rs b/crates/cdk/src/wallet/proofs.rs index ea02081a..dc0d0eb4 100644 --- a/crates/cdk/src/wallet/proofs.rs +++ b/crates/cdk/src/wallet/proofs.rs @@ -507,9 +507,9 @@ mod tests { Wallet::select_proofs(1024.into(), proofs, &vec![id()], &HashMap::new(), false) .unwrap(); assert_eq!(selected_proofs.len(), 1024); - for i in 0..1024 { - assert_eq!(selected_proofs[i].amount, 1.into()); - } + selected_proofs + .iter() + .for_each(|proof| assert_eq!(proof.amount, Amount::ONE)); } #[test] @@ -527,9 +527,11 @@ mod tests { .unwrap(); selected_proofs.sort(); assert_eq!(selected_proofs.len(), 32); - for i in 0..32 { - assert_eq!(selected_proofs[i].amount, (1 << i).into()); - } + + selected_proofs + .iter() + .enumerate() + .for_each(|(i, proof)| assert_eq!(proof.amount, (1 << i).into())); } #[test]