Skip to content

Commit 4e98b8b

Browse files
committed
Add test for insufficient liquidity
Added `test_insufficient_liquidity_for_bolt12_offer`  to verify error handling when there's insufficient liquidity when calling `pay_for_offer`.   Also updated `fails_creating_invoice_request_without_blinded_reply_path`  and `fails_creating_or_paying_for_offer_without_connected_peers` tests because after disconnecting peers, channel liquidity drops to 0. So the expected error  should be `InsufficientLiquidity` instead of `MissingPaths`
1 parent e2c1c99 commit 4e98b8b

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use crate::ln::wire::Encode;
6464
use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice};
6565
use crate::offers::invoice_error::InvoiceError;
6666
use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequestBuilder};
67-
use crate::offers::offer::{Offer, OfferBuilder, Amount};
67+
use crate::offers::offer::{Amount, Offer, OfferBuilder};
6868
use crate::offers::parse::Bolt12SemanticError;
6969
use crate::offers::refund::{Refund, RefundBuilder};
7070
use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler};

lightning/src/ln/offers_tests.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ fn fails_creating_or_paying_for_offer_without_connected_peers() {
12751275

12761276
match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
12771277
Ok(_) => panic!("Expected error"),
1278-
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
1278+
Err(e) => assert_eq!(e, Bolt12SemanticError::InsufficientLiquidity),
12791279
}
12801280

12811281
assert!(nodes[0].node.list_recent_payments().is_empty());
@@ -1438,7 +1438,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
14381438

14391439
match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
14401440
Ok(_) => panic!("Expected error"),
1441-
Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
1441+
Err(e) => assert_eq!(e, Bolt12SemanticError::InsufficientLiquidity),
14421442
}
14431443

14441444
assert!(nodes[0].node.list_recent_payments().is_empty());
@@ -1724,3 +1724,34 @@ fn fails_paying_invoice_more_than_once() {
17241724
let invoice_error = extract_invoice_error(alice, &onion_message);
17251725
assert_eq!(invoice_error, InvoiceError::from_string("DuplicateInvoice".to_string()));
17261726
}
1727+
1728+
#[test]
1729+
fn test_insufficient_liquidity_for_bolt12_offer() {
1730+
let channel_mon_config = create_chanmon_cfgs(2);
1731+
let node_config = create_node_cfgs(2, &channel_mon_config);
1732+
let node_chanmgrs = create_node_chanmgrs(2, &node_config, &[None, None]);
1733+
let nodes = create_network(2, &node_config, &node_chanmgrs);
1734+
1735+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1736+
1737+
let (alice, bob) = (&nodes[0], &nodes[1]);
1738+
let alice_id = alice.node.get_our_node_id();
1739+
1740+
let offer = alice.node
1741+
.create_offer_builder(None).unwrap()
1742+
.clear_paths()
1743+
.amount_msats(1_000_000_001)
1744+
.build().unwrap();
1745+
assert_eq!(offer.signing_pubkey(), Some(alice_id));
1746+
assert!(offer.paths().is_empty());
1747+
1748+
let payment_id = PaymentId([1; 32]);
1749+
1750+
let result = bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None);
1751+
match result {
1752+
Ok(_) => panic!("Expected error with insufficient liquidity."),
1753+
Err(e) => {
1754+
assert_eq!(e, Bolt12SemanticError::InsufficientLiquidity);
1755+
}
1756+
}
1757+
}

0 commit comments

Comments
 (0)