Skip to content

Commit 4aefb28

Browse files
offer: add a test with expiry info
While reviewing the code in [1], an interesting issue was discussed related to the expiry of the offer. The reported problem is as follows: > At least locally, if I set the expiry to 1 day (86400), it shows > the same expiry on decoding the offer as expected, but if I try to > pay it, it gives me an InvoiceRequestExpired error. However, if I > do the same with 1000 days, it works fine... This commit adds a test to ensure that we can pay an offer with an expiry of 1 day without encountering an InvoiceRequestExpired error. [1] getAlby/hub#1242 Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 5abb42f commit 4aefb28

File tree

1 file changed

+90
-2
lines changed

1 file changed

+90
-2
lines changed

tests/integration_tests_rust.rs

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use ldk_node::payment::{
2424
};
2525
use ldk_node::{Builder, Event, NodeError};
2626

27-
use lightning::ln::channelmanager::PaymentId;
27+
use lightning::{ln::channelmanager::PaymentId, offers::offer::Offer};
2828
use lightning::routing::gossip::{NodeAlias, NodeId};
2929
use lightning::util::persist::KVStore;
3030

@@ -35,7 +35,7 @@ use bitcoin::Amount;
3535
use lightning_invoice::{Bolt11InvoiceDescription, Description};
3636
use log::LevelFilter;
3737

38-
use std::sync::Arc;
38+
use std::{str::FromStr, sync::Arc};
3939

4040
#[test]
4141
fn channel_full_cycle() {
@@ -1275,3 +1275,91 @@ fn facade_logging() {
12751275
validate_log_entry(entry);
12761276
}
12771277
}
1278+
1279+
#[test]
1280+
fn simple_bolt12_pay_with_expiry() {
1281+
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
1282+
let chain_source = TestChainSource::Esplora(&electrsd);
1283+
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
1284+
1285+
let address_a = node_a.onchain_payment().new_address().unwrap();
1286+
let premine_amount_sat = 5_000_000;
1287+
premine_and_distribute_funds(
1288+
&bitcoind.client,
1289+
&electrsd.client,
1290+
vec![address_a],
1291+
Amount::from_sat(premine_amount_sat),
1292+
);
1293+
1294+
node_a.sync_wallets().unwrap();
1295+
open_channel(&node_a, &node_b, 4_000_000, true, &electrsd);
1296+
1297+
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6);
1298+
1299+
node_a.sync_wallets().unwrap();
1300+
node_b.sync_wallets().unwrap();
1301+
1302+
expect_channel_ready_event!(node_a, node_b.node_id());
1303+
expect_channel_ready_event!(node_b, node_a.node_id());
1304+
1305+
// Sleep until we broadcasted a node announcement.
1306+
while node_b.status().latest_node_announcement_broadcast_timestamp.is_none() {
1307+
std::thread::sleep(std::time::Duration::from_millis(10));
1308+
}
1309+
1310+
// Sleep one more sec to make sure the node announcement propagates.
1311+
std::thread::sleep(std::time::Duration::from_secs(1));
1312+
1313+
let expected_amount_msat = 100_000_000;
1314+
let offer =
1315+
node_b.bolt12_payment().receive(expected_amount_msat, "we should have time before expiry", Some(86400), None).unwrap();
1316+
1317+
// Make sure that we are able to parse it back!
1318+
let offer = Offer::from_str(&offer.to_string()).unwrap();
1319+
1320+
let payment_id = node_a
1321+
.bolt12_payment()
1322+
.send(&offer, None, None);
1323+
1324+
assert!(payment_id.is_ok(), "Payment should not fail: {:?}", payment_id);
1325+
1326+
let payment_id = payment_id.unwrap();
1327+
expect_payment_successful_event!(node_a, Some(payment_id), None);
1328+
let node_a_payments =
1329+
node_a.list_payments_with_filter(|p| matches!(p.kind, PaymentKind::Bolt12Offer { .. }));
1330+
assert_eq!(node_a_payments.len(), 1);
1331+
match node_a_payments.first().unwrap().kind {
1332+
PaymentKind::Bolt12Offer {
1333+
hash,
1334+
preimage,
1335+
secret: _,
1336+
offer_id,
1337+
..
1338+
} => {
1339+
assert!(hash.is_some());
1340+
assert!(preimage.is_some());
1341+
assert_eq!(offer_id, offer.id());
1342+
},
1343+
_ => {
1344+
panic!("Unexpected payment kind");
1345+
},
1346+
}
1347+
assert_eq!(node_a_payments.first().unwrap().amount_msat, Some(expected_amount_msat));
1348+
1349+
expect_payment_received_event!(node_b, expected_amount_msat);
1350+
let node_b_payments =
1351+
node_b.list_payments_with_filter(|p| matches!(p.kind, PaymentKind::Bolt12Offer { .. }));
1352+
assert_eq!(node_b_payments.len(), 1);
1353+
match node_b_payments.first().unwrap().kind {
1354+
PaymentKind::Bolt12Offer { hash, preimage, secret, offer_id, .. } => {
1355+
assert!(hash.is_some());
1356+
assert!(preimage.is_some());
1357+
assert!(secret.is_some());
1358+
assert_eq!(offer_id, offer.id());
1359+
},
1360+
_ => {
1361+
panic!("Unexpected payment kind");
1362+
},
1363+
}
1364+
assert_eq!(node_b_payments.first().unwrap().amount_msat, Some(expected_amount_msat));
1365+
}

0 commit comments

Comments
 (0)