Skip to content

Commit 9d08ba6

Browse files
committed
Add test for insufficient liquidity
Added `fails_paying_offer_with_insufficient_liquidity` to verify error handling when there's insufficient liquidity when calling `pay_for_offer`.
1 parent 20b4b39 commit 9d08ba6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lightning/src/ln/offers_tests.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,4 +2065,35 @@ fn fails_paying_invoice_more_than_once() {
20652065

20662066
let invoice_error = extract_invoice_error(alice, &onion_message);
20672067
assert_eq!(invoice_error, InvoiceError::from_string("DuplicateInvoice".to_string()));
2068+
}
2069+
2070+
#[test]
2071+
fn fails_paying_offer_with_insufficient_liquidity() {
2072+
let channel_mon_config = create_chanmon_cfgs(2);
2073+
let node_config = create_node_cfgs(2, &channel_mon_config);
2074+
let node_chanmgrs = create_node_chanmgrs(2, &node_config, &[None, None]);
2075+
let nodes = create_network(2, &node_config, &node_chanmgrs);
2076+
2077+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
2078+
2079+
let (alice, bob) = (&nodes[0], &nodes[1]);
2080+
let alice_id = alice.node.get_our_node_id();
2081+
2082+
let offer = alice.node
2083+
.create_offer_builder(None).unwrap()
2084+
.clear_paths()
2085+
.amount_msats(1_000_000_001)
2086+
.build().unwrap();
2087+
assert_eq!(offer.signing_pubkey(), Some(alice_id));
2088+
assert!(offer.paths().is_empty());
2089+
2090+
let payment_id = PaymentId([1; 32]);
2091+
2092+
let result = bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None);
2093+
match result {
2094+
Ok(_) => panic!("Expected error with insufficient liquidity."),
2095+
Err(e) => {
2096+
assert_eq!(e, Bolt12CreationError::InsufficientLiquidity);
2097+
}
2098+
}
20682099
}

0 commit comments

Comments
 (0)