Skip to content

Commit 7dfcbc5

Browse files
committed
Add test for insufficient liquidity in pay_for_offer
Adds the `fails_paying_offer_with_insufficient_liquidity` test to ensure that the `pay_for_offer` method correctly handles cases where the liquidity is insufficient. The test verifies that the method returns the `Bolt12RequestError::InsufficientLiquidity` error when the requested payment amount exceeds the available liquidity.
1 parent d38acd3 commit 7dfcbc5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lightning/src/ln/offers_tests.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,4 +2336,37 @@ fn no_double_pay_with_stale_channelmanager() {
23362336
// Alice and Bob is closed. Since no 2nd attempt should be made, check that no events are
23372337
// generated in response to the duplicate invoice.
23382338
assert!(nodes[0].node.get_and_clear_pending_events().is_empty());
2339+
}
2340+
2341+
#[test]
2342+
fn fails_paying_offer_with_insufficient_liquidity() {
2343+
let channel_mon_config = create_chanmon_cfgs(2);
2344+
let node_config = create_node_cfgs(2, &channel_mon_config);
2345+
let node_chanmgrs = create_node_chanmgrs(2, &node_config, &[None, None]);
2346+
let nodes = create_network(2, &node_config, &node_chanmgrs);
2347+
2348+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
2349+
2350+
let (alice, bob) = (&nodes[0], &nodes[1]);
2351+
let alice_id = alice.node.get_our_node_id();
2352+
2353+
let offer = alice.node
2354+
.create_offer_builder(None).unwrap()
2355+
.clear_paths()
2356+
.amount_msats(950_000_000)
2357+
.build().unwrap();
2358+
assert_eq!(offer.issuer_signing_pubkey(), Some(alice_id));
2359+
assert!(offer.paths().is_empty());
2360+
2361+
let payment_id = PaymentId([1; 32]);
2362+
2363+
let result = bob.node
2364+
.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None);
2365+
2366+
match result {
2367+
Ok(_) => panic!("Expected error with insufficient liquidity."),
2368+
Err(e) => {
2369+
assert_eq!(e, Bolt12RequestError::InsufficientLiquidity);
2370+
}
2371+
}
23392372
}

0 commit comments

Comments
 (0)