Skip to content

Commit

Permalink
f Add test to parse new URIs in unified_qr.rs
Browse files Browse the repository at this point in the history
I added a new test for test_parse_uri in `unified_qr.rs` so
we could test real URIs from wallets. This one was a zeus URI
on testnet. I will be adding more in the future but I want to
push this commit to check if CI checks pass.

Also added docs on `uniffi_types.rs` to ensure contributers
add imports or re-exports so they're accessible in the bindings.
Rather then adding them in `lib.rs` like rustc recommends.
  • Loading branch information
slanesuke committed Jun 19, 2024
1 parent f85501c commit f273f70
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/payment/unified_qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ mod tests {
use super::*;
use crate::builder::NodeBuilder;
use crate::config::Config;
use crate::payment::unified_qr::Extras;
use bitcoin::Network;
use std::str::FromStr;
use std::sync::{Arc, RwLock};
Expand Down Expand Up @@ -294,13 +295,12 @@ mod tests {

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

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");
let uri_test1 = "BITCOIN:TB1QRSCD05XNY6QZ63TF9GJELGVK6D3UDJFEKK62VU?amount=1&message=Test%20message&lightning=LNTB1000M1PNXWM7MDQ523JHXAPQD4JHXUMPVAJSNP4QWP9QD2JFP8DUZ46JQG5LTKVDH04YG52G6UF2YAXP8H7YZPZM3DM5PP5KUP7YT429UP9Z4ACPA60R7WETSTL66549MG05P0JN0C4L2NCC40SSP5R0LH86DJCL0NK8HZHNZHX92VVUAAVNE48Z5RVKVY5DKTRQ0DMP7S9QYYSGQCQPCXQRRAQYR59FGN2VVC5R6DS0AZMETH493ZU56H0WSVMGYCW9LEPZ032PGQNZMQ6XKVEH90Z02C0NH3J5QGDAWCS2YC2ZNP22J0ZD0PPF78N4QQQEXTYS2";
let parsed_uri = uri_test1
.parse::<bip21::Uri<NetworkUnchecked, Extras>>()
.expect("Failed parsing")
.require_network(Network::Testnet)
.expect("Invalid Network");

assert_eq!(
parsed_uri.address,
Expand All @@ -309,10 +309,35 @@ mod tests {
.require_network(Network::Testnet)
.unwrap()
);

assert_eq!(Amount::from_sat(100000000), Amount::from(parsed_uri.amount.unwrap()));

if let Some(invoice) = parsed_uri.extras.bolt11_invoice {
assert_eq!(invoice, Bolt11Invoice::from_str("LNTB1000M1PNXWM7MDQ523JHXAPQD4JHXUMPVAJSNP4QWP9QD2JFP8DUZ46JQG5LTKVDH04YG52G6UF2YAXP8H7YZPZM3DM5PP5KUP7YT429UP9Z4ACPA60R7WETSTL66549MG05P0JN0C4L2NCC40SSP5R0LH86DJCL0NK8HZHNZHX92VVUAAVNE48Z5RVKVY5DKTRQ0DMP7S9QYYSGQCQPCXQRRAQYR59FGN2VVC5R6DS0AZMETH493ZU56H0WSVMGYCW9LEPZ032PGQNZMQ6XKVEH90Z02C0NH3J5QGDAWCS2YC2ZNP22J0ZD0PPF78N4QQQEXTYS2").unwrap());
} else {
panic!("No Lightning invoice found");
}

let zeus_test = "bitcoin:TB1QQ32G6LM2XKT0U2UGASH5DC4CFT3JTPEW65PZZ5?lightning=LNTB500U1PN89HH6PP5MA7K6DRM5SYVD05NTXMGSRNM728J7EHM8KV6VC96YNLKN7G7VDYQDQQCQZRCXQR8Q7SP5HU30L0EEXKYYPQSQYEZELZWUPT62HLJ0KV2662CALGPAML50QPXQ9QXPQYSGQDKTVFXEC8H2DG2GY3C95ETAJ0QKX50XAUCU304PPFV2SQVGFHZ6RMZWJV8MC3M0LXF3GW852C5VSK0DELK0JHLYUTYZDF7QKNAMT4PQQQN24WM&amount=0.0005";
let uri_test2 = zeus_test
.parse::<bip21::Uri<NetworkUnchecked, Extras>>()
.expect("Failed parsing")
.require_network(Network::Testnet)
.expect("Invalid Network");

assert_eq!(
uri_test2.address,
bitcoin::Address::from_str("TB1QQ32G6LM2XKT0U2UGASH5DC4CFT3JTPEW65PZZ5")
.unwrap()
.require_network(Network::Testnet)
.unwrap()
);

if let Some(invoice) = uri_test2.extras.bolt11_invoice {
assert_eq!(invoice, Bolt11Invoice::from_str("LNTB500U1PN89HH6PP5MA7K6DRM5SYVD05NTXMGSRNM728J7EHM8KV6VC96YNLKN7G7VDYQDQQCQZRCXQR8Q7SP5HU30L0EEXKYYPQSQYEZELZWUPT62HLJ0KV2662CALGPAML50QPXQ9QXPQYSGQDKTVFXEC8H2DG2GY3C95ETAJ0QKX50XAUCU304PPFV2SQVGFHZ6RMZWJV8MC3M0LXF3GW852C5VSK0DELK0JHLYUTYZDF7QKNAMT4PQQQN24WM").unwrap());
} else {
panic!("No offer found.");
}
assert_eq!(Amount::from_sat(50000), Amount::from(uri_test2.amount.unwrap()))
}
}
5 changes: 5 additions & 0 deletions src/uniffi_types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Importing these items ensures they are accessible in the uniffi bindings
// without introducing unused import warnings in lib.rs.
//
// Make sure to add any re-exported items that need to be used in uniffi below.

pub use crate::graph::{ChannelInfo, ChannelUpdateInfo, NodeAnnouncementInfo, NodeInfo};
pub use crate::payment::store::{LSPFeeLimits, PaymentDirection, PaymentKind, PaymentStatus};
pub use crate::payment::PaymentResult;
Expand Down

0 comments on commit f273f70

Please sign in to comment.