Skip to content

Commit

Permalink
Add disposable test
Browse files Browse the repository at this point in the history
  • Loading branch information
lsunsi committed Dec 4, 2023
1 parent eacbc3b commit ed3dcb5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
62 changes: 62 additions & 0 deletions tests/lud11.rs
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 2 additions & 2 deletions tests/lud12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ed3dcb5

Please sign in to comment.