diff --git a/Cargo.toml b/Cargo.toml index 2265bdc..31d5490 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,10 @@ suspicious = "deny" name = "lud06" required-features = ["client", "server"] +[[test]] +name = "lud11" +required-features = ["client", "server"] + [[test]] name = "lud12" required-features = ["client", "server"] diff --git a/tests/lud11.rs b/tests/lud11.rs new file mode 100644 index 0000000..9f28def --- /dev/null +++ b/tests/lud11.rs @@ -0,0 +1,62 @@ +#[tokio::test] +async fn test() { + let listener = tokio::net::TcpListener::bind("0.0.0.0:0") + .await + .expect("net"); + + let addr = listener.local_addr().expect("addr"); + + let query_url = format!("http://{addr}/lnurlp"); + let callback_url = url::Url::parse(&format!("http://{addr}/lnurlp/callback")).expect("url"); + + let router = lnurlkit::server::Server::default() + .pay_request( + move || { + let callback = callback_url.clone(); + async { + Ok(lnurlkit::core::pay_request::PayRequest { + callback, + short_description: String::new(), + long_description: None, + success_action: None, + jpeg: None, + png: None, + comment_size: 0, + min: 314, + max: 315, + }) + } + }, + move |(amount, _)| async move { + Ok(lnurlkit::core::pay_request::CallbackResponse { + pr: String::new(), + disposable: amount % 2 == 0, + }) + }, + ) + .build(); + + tokio::spawn(async move { + axum::serve(listener, router).await.expect("serve"); + }); + + let client = lnurlkit::client::Client::default(); + + let lnurl = bech32::encode( + "lnurl", + bech32::ToBase32::to_base32(&query_url), + bech32::Variant::Bech32, + ) + .expect("lnurl"); + + let queried = client.query(&lnurl).await.expect("query"); + let lnurlkit::client::Query::PayRequest(pr) = queried else { + panic!("not pay request"); + }; + + let invoice = pr.clone().callback("", 314).await.expect("callback"); + assert!(invoice.disposable); + + let invoice = pr.callback("", 315).await.expect("callback"); + assert!(!invoice.disposable); +} diff --git a/tests/lud12.rs b/tests/lud12.rs index c62ee57..48a9f3a 100644 --- a/tests/lud12.rs +++ b/tests/lud12.rs @@ -16,8 +16,8 @@ async fn test() { async { Ok(lnurlkit::core::pay_request::PayRequest { callback, - short_description: String::from("today i become death"), - long_description: Some(String::from("the destroyer of worlds")), + short_description: String::new(), + long_description: None, success_action: None, jpeg: None, png: None,