Skip to content

Commit

Permalink
chore: add test with real world payreq parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lsunsi committed Dec 5, 2023
1 parent 3c51e55 commit 2c62f61
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 0 deletions.
1 change: 1 addition & 0 deletions fixtures/alby-pay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"status":"OK","tag":"payRequest","commentAllowed":255,"callback":"https://getalby.com/lnurlp/lorenzo/callback","metadata":"[[\"text/identifier\",\"lorenzo@getalby.com\"],[\"text/plain\",\"Sats for lorenzo\"]]","minSendable":1000,"maxSendable":500000000,"payerData":{"name":{"mandatory":false},"email":{"mandatory":false},"pubkey":{"mandatory":false}},"nostrPubkey":"79f00d3f5a19ec806189fcab03c1be4ff81d18ee4f653c88fac41fe03570f432","allowsNostr":true}
1 change: 1 addition & 0 deletions fixtures/alby-pay.url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://getalby.com/.well-known/lnurlp/lorenzo
1 change: 1 addition & 0 deletions fixtures/bipa-pay.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions fixtures/bipa-pay.url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://bipa.app/.well-known/lnurlp/kenu
1 change: 1 addition & 0 deletions fixtures/blink-pay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"callback":"https://pay.mainnet.galoy.io/lnurlp/lorenzo/callback","minSendable":1000,"maxSendable":100000000000,"metadata":"[[\"text/plain\",\"Payment to lorenzo\"],[\"text/identifier\",\"lorenzo@blink.sv\"]]","commentAllowed":2000,"tag":"payRequest","allowsNostr":true,"nostrPubkey":"8fe53b37518e3dbe9bab26d912292001d8b882de9456b7b08b615f912dc8bf4a"}
1 change: 1 addition & 0 deletions fixtures/blink-pay.url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://blink.sv/.well-known/lnurlp/lorenzo
1 change: 1 addition & 0 deletions fixtures/pouch-pay.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions fixtures/pouch-pay.url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://app.pouch.ph/.well-known/lnurlp/ethan
1 change: 1 addition & 0 deletions fixtures/walletofsatoshi-pay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"callback":"https://livingroomofsatoshi.com/api/v1/lnurl/payreq/0e7f30e3-e74d-410d-bf86-50d101715e81","maxSendable":100000000000,"minSendable":1000,"metadata":"[[\"text/plain\",\"Pay to Wallet of Satoshi user: wailingcity51\"],[\"text/identifier\",\"wailingcity51@walletofsatoshi.com\"]]","commentAllowed":255,"tag":"payRequest","allowsNostr":true,"nostrPubkey":"be1d89794bf92de5dd64c1e60f6a2c70c140abac9932418fee30c5c637fe9479"}
1 change: 1 addition & 0 deletions fixtures/walletofsatoshi-pay.url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://walletofsatoshi.com/.well-known/lnurlp/wailingcity51
1 change: 1 addition & 0 deletions fixtures/zebedee-pay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"minSendable":1000,"maxSendable":500000000,"commentAllowed":150,"tag":"payRequest","metadata":"[[\"text/plain\",\"luhack - Welcome to my zbd.gg page!\"],[\"image/png;base64\",\"/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCABgAIADASIAAhEBAxEB/8QAHAAAAwEBAQEBAQAAAAAAAAAABAUGBwMCCAEA/8QAPBAAAgEDAwIEBAMHAgUFAAAAAQIDBAURABIhBjETQVFhBxQicTKBkRUjJEJSocFichYzsbLRU5LC8PH/xAAaAQACAwEBAAAAAAAAAAAAAAACAwABBAUG/8QAKhEAAgIBAwIDCQEAAAAAAAAAAQIAA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COYfqYjqGQTRbtc6G8/BmCCSVP2hbJECxsRv4bHA81KNj2xqDqY7eLPQiWkQieSZZGLAbQCuzaQMjudc+ooo7d1DcKXP7pZ3VD6oxyp/9pGhOmoae43Smir03QNmPCsQQfLn0yNaNMRkq3f8A3t+YFvIBHaLbj0541W5tVZFvjfa0ErYZD6bhwf7apumem62uq3guZZdkfiBlABk5wFye3rx3Gpz4nUsNq6mhe3F4zLTq7ncc7skf9ANNOgrzea+b5a3SxzSxI0hhnbAIGPwnyJzotilthHMHLAbh0gnW1qCmrrYkWNYas0oVWG1sJk8DzzznTLpHpmsnt1JWUa09wpIpVeZS4RlGcnOe400uL2q5xPb7zBU2uqEjSlC20eIwwWB7HI9dc7Dbq/pe4pU2isiqqFxtmp5zt3j19NNNKFtrAiLFpAyIL8QLVW/xd6jpXgCTFpAVALE9mLD8WS2M6qei6Gm+HPTFfdroFe6NACVPH1H8MI/PGfz9NUldR2690JgXaEYoylGDFCGDDj8sazn4/XIftSit8MgKgGpkA/qP0j/5az6qjwmAHSPrsL5Jn//Z\"]]","callback":"https://api.zebedee.io/v0/process-static-charges/8d648ac7-09f6-400c-8479-d05ac4d9d61d","payerData":{"name":{"mandatory":false},"identifier":{"mandatory":false}},"disposable":false,"allowsNostr":true,"nostrPubkey":"6a69b9a70c28857e14fd429efabea77cb65ab6dfee3ec79b32ab1c4e7c02a232"}
1 change: 1 addition & 0 deletions fixtures/zebedee-pay.url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://zbd.gg/.well-known/lnurlp/luhack
136 changes: 136 additions & 0 deletions tests/real.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
mod pay_request {
#[test]
fn alby() {
let Ok(lnurlkit::Query::Pay(pr)) =
include_str!("../fixtures/alby-pay.json").parse::<lnurlkit::Query>()
else {
panic!("parse");
};

assert_eq!(
pr.callback.to_string(),
"https://getalby.com/lnurlp/lorenzo/callback"
);
assert_eq!(pr.short_description, "Sats for lorenzo");
assert!(pr.long_description.is_none());

assert_eq!(pr.comment_size, 255);
assert_eq!(pr.max, 500000000);
assert_eq!(pr.min, 1000);

assert!(pr.jpeg.is_none());
assert!(pr.png.is_none());
}

#[test]
fn blink() {
let Ok(lnurlkit::Query::Pay(pr)) =
include_str!("../fixtures/blink-pay.json").parse::<lnurlkit::Query>()
else {
panic!("parse");
};

assert_eq!(
pr.callback.to_string(),
"https://pay.mainnet.galoy.io/lnurlp/lorenzo/callback"
);
assert_eq!(pr.short_description, "Payment to lorenzo");
assert!(pr.long_description.is_none());

assert_eq!(pr.comment_size, 2000);
assert_eq!(pr.max, 100000000000);
assert_eq!(pr.min, 1000);

assert!(pr.jpeg.is_none());
assert!(pr.png.is_none());
}

#[test]
fn bipa() {
let Ok(lnurlkit::Query::Pay(pr)) =
include_str!("../fixtures/bipa-pay.json").parse::<lnurlkit::Query>()
else {
panic!("parse");
};

assert_eq!(pr.callback.to_string(), "https://api.bipa.app/ln/request/invoice/kenu/1701784379/50n3BjOSWb1ZrxE9WmRcqlk2ylDzUJ1Q_GHN0pk_Q7Q/P6IMTO82jj6W21mUvXNgIlGmqGibx8MiaWfSjQ2wI88");
assert_eq!(pr.short_description, "$kenu ⚡ bipa.app");
assert!(pr.long_description.is_none());

assert_eq!(pr.comment_size, 140);
assert_eq!(pr.max, 1000000000);
assert_eq!(pr.min, 1000);

assert!(pr.jpeg.is_none());
assert_eq!(pr.png.unwrap().len(), 54697);
}

#[test]
fn pouch() {
let Ok(lnurlkit::Query::Pay(pr)) =
include_str!("../fixtures/pouch-pay.json").parse::<lnurlkit::Query>()
else {
panic!("parse");
};

assert_eq!(
pr.callback.to_string(),
"https://app.pouch.ph/api/v2/lnurl/pay/ethan"
);
assert_eq!(pr.short_description, "Lightning payment to ethan@pouch.ph");
assert!(pr.long_description.is_none());

assert_eq!(pr.comment_size, 150);
assert_eq!(pr.max, 10000000000);
assert_eq!(pr.min, 1000);

assert!(pr.jpeg.is_none());
assert!(pr.png.is_none());
}

#[test]
fn walletofsatoshi() {
let Ok(lnurlkit::Query::Pay(pr)) =
include_str!("../fixtures/walletofsatoshi-pay.json").parse::<lnurlkit::Query>()
else {
panic!("parse");
};

assert_eq!(pr.callback.to_string(), "https://livingroomofsatoshi.com/api/v1/lnurl/payreq/0e7f30e3-e74d-410d-bf86-50d101715e81");
assert_eq!(
pr.short_description,
"Pay to Wallet of Satoshi user: wailingcity51"
);
assert!(pr.long_description.is_none());

assert_eq!(pr.comment_size, 255);
assert_eq!(pr.max, 100000000000);
assert_eq!(pr.min, 1000);

assert!(pr.jpeg.is_none());
assert!(pr.png.is_none());
}

#[test]
fn zebedee() {
let Ok(lnurlkit::Query::Pay(pr)) =
include_str!("../fixtures/zebedee-pay.json").parse::<lnurlkit::Query>()
else {
panic!("parse");
};

assert_eq!(
pr.callback.to_string(),
"https://api.zebedee.io/v0/process-static-charges/8d648ac7-09f6-400c-8479-d05ac4d9d61d"
);
assert_eq!(pr.short_description, "luhack - Welcome to my zbd.gg page!");
assert!(pr.long_description.is_none());

assert_eq!(pr.comment_size, 150);
assert_eq!(pr.max, 500000000);
assert_eq!(pr.min, 1000);

assert!(pr.jpeg.is_none());
assert_eq!(pr.png.unwrap().len(), 3993);
}
}

0 comments on commit 2c62f61

Please sign in to comment.