diff --git a/rust/src/api/wallet.rs b/rust/src/api/wallet.rs index 7374f47..db53f91 100644 --- a/rust/src/api/wallet.rs +++ b/rust/src/api/wallet.rs @@ -236,7 +236,8 @@ impl Wallet { mod tests { use std::{thread, time::Duration}; - + use elements::AssetId; + use lwk_wollet::bitcoin::Address; use super::*; #[test] fn testable_wallets() { @@ -443,4 +444,41 @@ mod tests { // // TODO: more cases // } + + #[test] + fn test_unblinded_detection() { + let network = Network::Testnet; + let mnemonic = ""; + let descriptor = Descriptor::new_confidential(network, mnemonic.to_string()).expect("Failed to create descriptor"); + let wallet = Wallet::init(network, "/tmp/lwk_test".to_string(), descriptor).expect(""); + + let confidential_address = wallet.address_last_unused().unwrap(); + println!("The confidential address is {}", confidential_address); + + //Write code to halt for the payment to be made. maybe we can add a timer? or take an input from user that confirms that he did the pyment or not. + + let electrum_url = "les.bullbitcoin.com:995".to_string(); + wallet.sync(electrum_url.clone()).unwrap(); + + let balance_bef = wallet.balances().unwrap(); + let txs_bef = wallet.txs().unwrap(); + + assert!(balance.get(0), >0); + assert!(!txs_bef.is_empty()); + + let add = elements::Address::from_str(&confidential_address).unwrap(); + let unblinded_address = add.to_unconfidential(); + + println!("The unblinded address is {}", unblinded_address); + println!("Fund the unblinded address"); + + wallet.sync(electrum_url.clone()).unwrap(); + + let balance = wallet.balances().unwrap(); + let txs = wallet.txs().unwrap(); + + assert!(balance.get(0), "{}", balance_bef.get(0)); + println!("Payment to unblinded address not detected"); + } + }