diff --git a/crates/cashu/src/nuts/nut00/mod.rs b/crates/cashu/src/nuts/nut00/mod.rs index cbcbf061..48582934 100644 --- a/crates/cashu/src/nuts/nut00/mod.rs +++ b/crates/cashu/src/nuts/nut00/mod.rs @@ -985,4 +985,57 @@ mod tests { let deserialized: CurrencyUnit = serde_json::from_str(&serialized).unwrap(); assert_eq!(unit, deserialized) } + + #[test] + fn test_payment_method_parsing() { + // Test standard variants + assert_eq!( + PaymentMethod::from_str("bolt11").unwrap(), + PaymentMethod::Bolt11 + ); + assert_eq!( + PaymentMethod::from_str("BOLT11").unwrap(), + PaymentMethod::Bolt11 + ); + assert_eq!( + PaymentMethod::from_str("Bolt11").unwrap(), + PaymentMethod::Bolt11 + ); + + assert_eq!( + PaymentMethod::from_str("bolt12").unwrap(), + PaymentMethod::Bolt12 + ); + assert_eq!( + PaymentMethod::from_str("BOLT12").unwrap(), + PaymentMethod::Bolt12 + ); + assert_eq!( + PaymentMethod::from_str("Bolt12").unwrap(), + PaymentMethod::Bolt12 + ); + + // Test custom variants + assert_eq!( + PaymentMethod::from_str("custom").unwrap(), + PaymentMethod::Custom("custom".to_string()) + ); + assert_eq!( + PaymentMethod::from_str("CUSTOM").unwrap(), + PaymentMethod::Custom("custom".to_string()) + ); + + // Test serialization/deserialization consistency + let methods = vec![ + PaymentMethod::Bolt11, + PaymentMethod::Bolt12, + PaymentMethod::Custom("test".to_string()), + ]; + + for method in methods { + let serialized = serde_json::to_string(&method).unwrap(); + let deserialized: PaymentMethod = serde_json::from_str(&serialized).unwrap(); + assert_eq!(method, deserialized); + } + } } diff --git a/crates/cdk-sqlite/src/wallet/mod.rs b/crates/cdk-sqlite/src/wallet/mod.rs index 28252a9e..5166baeb 100644 --- a/crates/cdk-sqlite/src/wallet/mod.rs +++ b/crates/cdk-sqlite/src/wallet/mod.rs @@ -306,4 +306,59 @@ mod tests { assert_eq!(retrieved_dleq.s.to_string(), s.to_string()); assert_eq!(retrieved_dleq.r.to_string(), r.to_string()); } + + #[tokio::test] + async fn test_mint_quote_payment_method_read_and_write() { + use cdk_common::mint_url::MintUrl; + use cdk_common::nuts::{CurrencyUnit, MintQuoteState, PaymentMethod}; + use cdk_common::wallet::MintQuote; + use cdk_common::Amount; + + // Create a temporary database + let path = std::env::temp_dir().to_path_buf().join(format!( + "cdk-test-migration-{}.sqlite", + uuid::Uuid::new_v4() + )); + + #[cfg(feature = "sqlcipher")] + let db = WalletSqliteDatabase::new((path, "password".to_string())) + .await + .unwrap(); + + #[cfg(not(feature = "sqlcipher"))] + let db = WalletSqliteDatabase::new(path).await.unwrap(); + + // Test PaymentMethod variants + let mint_url = MintUrl::from_str("https://example.com").unwrap(); + let payment_methods = vec![ + PaymentMethod::Bolt11, + PaymentMethod::Bolt12, + PaymentMethod::Custom("custom".to_string()), + ]; + + for (i, payment_method) in payment_methods.iter().enumerate() { + let quote = MintQuote { + id: format!("test_quote_{}", i), + mint_url: mint_url.clone(), + amount: Some(Amount::from(100)), + unit: CurrencyUnit::Sat, + request: "test_request".to_string(), + state: MintQuoteState::Unpaid, + expiry: 1000000000, + secret_key: None, + payment_method: payment_method.clone(), + amount_issued: Amount::from(0), + amount_paid: Amount::from(0), + }; + + // Store the quote + db.add_mint_quote(quote.clone()).await.unwrap(); + + // Retrieve and verify + let retrieved = db.get_mint_quote("e.id).await.unwrap().unwrap(); + assert_eq!(retrieved.payment_method, *payment_method); + assert_eq!(retrieved.amount_issued, Amount::from(0)); + assert_eq!(retrieved.amount_paid, Amount::from(0)); + } + } }