Skip to content

Commit

Permalink
f Refactor tests to seperate the two method
Browse files Browse the repository at this point in the history
  • Loading branch information
slanesuke committed Jun 5, 2024
1 parent b1a5b26 commit 8ba6166
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/payment/unified_qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ mod tests {
use crate::builder::NodeBuilder;
use crate::config::Config;
use bitcoin::Network;
use std::str::FromStr;
use std::sync::{Arc, RwLock};
use tokio::runtime::Runtime;

#[test]
fn test_encoding_and_decoding() {
fn test_encoding_uri() {
let mut config = Config::default();
config.network = Network::Testnet;

Expand Down Expand Up @@ -239,22 +240,33 @@ mod tests {
Ok(ref uri) => {
assert!(uri.contains("BITCOIN:"));
assert!(uri.contains("lightning="));
println!("Generated URI: {}", uri);
println!("Generated URI: {}\n", uri);
},
Err(e) => panic!("Failed to generate URI: {:?}", e),
}
}

#[test]
fn test_parse_uri() {
let uqr_payment = "BITCOIN:TB1QLFHP8GFLPKQ7WWELVH0SSV2ZS4NSU7A7VZEVCC?amount=0.01&message=Test%20message&lightning=lntb10m1pnxp4wydq523jhxapqd4jhxumpvajsnp4qtnck83suegr6wsqc8ufmas8r0r2udag0rdy2qmt0uuxpnzc8qc4spp5l4nuq48j2w9tvj6cr7n5tdcg00s2wl7qnw39nu7zqm2cdj6870kqsp5cmsn75tppsnqafng50f2rcc3r92rxv8fjsv2cgc9gmzgqwlvza2s9qyysgqcqpcxqrraq9yfse0va673ucnpwh45qdjxagl5mc6yxce7udeuw8nhsnch4m7lzrdxs8vm45rdnl3h2qylsdxhe52ej8tn7gulsj05kgkzgpawd38qqafv6wy";

let uri = uqr_payment.unwrap();
let uri = uqr_payment.to_string();

let parsed_uri: bip21::Uri<NetworkUnchecked, Extras> =
uri.parse().expect("Failed to parse URI");
let parsed_uri = parsed_uri.require_network(Network::Testnet).expect("Invalid network");

println!("\nParsed Bitcoin address: {}", parsed_uri.address);
assert_eq!(
parsed_uri.address,
bitcoin::Address::from_str("TB1QLFHP8GFLPKQ7WWELVH0SSV2ZS4NSU7A7VZEVCC")
.unwrap()
.require_network(Network::Testnet)
.unwrap()
);
if let Some(invoice) = parsed_uri.extras.bolt11_invoice {
println!("\nParsed Lightning invoice: {}", invoice);
assert_eq!(invoice, Bolt11Invoice::from_str("lntb10m1pnxp4wydq523jhxapqd4jhxumpvajsnp4qtnck83suegr6wsqc8ufmas8r0r2udag0rdy2qmt0uuxpnzc8qc4spp5l4nuq48j2w9tvj6cr7n5tdcg00s2wl7qnw39nu7zqm2cdj6870kqsp5cmsn75tppsnqafng50f2rcc3r92rxv8fjsv2cgc9gmzgqwlvza2s9qyysgqcqpcxqrraq9yfse0va673ucnpwh45qdjxagl5mc6yxce7udeuw8nhsnch4m7lzrdxs8vm45rdnl3h2qylsdxhe52ej8tn7gulsj05kgkzgpawd38qqafv6wy").unwrap());
} else {
println!("No Lightning invoice found");
panic!("No Lightning invoice found");
}
}
}

0 comments on commit 8ba6166

Please sign in to comment.