Skip to content

Commit a160cbf

Browse files
committed
test wip
1 parent 0bdd5b4 commit a160cbf

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1466,10 +1466,18 @@ impl Node {
14661466
/// Sets the [`BlindedMessagePath`]s that we will use as an async recipient to interactively build [`Offer`]s with a
14671467
/// static invoice server, so the server can serve [`StaticInvoice`]s to payers on our behalf when we're offline.
14681468
pub fn set_paths_to_static_invoice_server(
1469-
&mut self, paths: Vec<BlindedMessagePath>,
1469+
&self, paths: Vec<BlindedMessagePath>,
14701470
) -> Result<(), ()> {
14711471
self.channel_manager.set_paths_to_static_invoice_server(paths)
14721472
}
1473+
1474+
/// [`BlindedMessagePath`]s for an async recipient to communicate with this node and interactively
1475+
/// build [`Offer`]s and [`StaticInvoice`]s for receiving async payments.
1476+
pub fn blinded_paths_for_async_recipient(
1477+
&self, recipient_id: Vec<u8>, relative_expiry: Option<Duration>,
1478+
) -> Result<Vec<BlindedMessagePath>, ()> {
1479+
self.channel_manager.blinded_paths_for_async_recipient(recipient_id, relative_expiry)
1480+
}
14731481
}
14741482

14751483
impl Drop for Node {

tests/common/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,13 @@ pub(crate) fn setup_two_nodes(
288288
) -> (TestNode, TestNode) {
289289
println!("== Node A ==");
290290
let config_a = random_config(anchor_channels);
291+
println!("Node A storage path: {}", config_a.node_config.storage_dir_path.clone());
292+
291293
let node_a = setup_node(chain_source, config_a, None);
292294

293295
println!("\n== Node B ==");
294296
let mut config_b = random_config(anchor_channels);
297+
println!("Node B storage path: {}", config_b.node_config.storage_dir_path.clone());
295298
if allow_0conf {
296299
config_b.node_config.trusted_peers_0conf.push(node_a.node_id());
297300
}

tests/integration_tests_rust.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,58 @@ fn simple_bolt12_send_receive() {
11301130
assert_eq!(node_a_payments.first().unwrap().amount_msat, Some(overpaid_amount));
11311131
}
11321132

1133+
#[test]
1134+
fn static_invoice_server() {
1135+
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
1136+
let chain_source = TestChainSource::Esplora(&electrsd);
1137+
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
1138+
1139+
let address_a = node_a.onchain_payment().new_address().unwrap();
1140+
let premine_amount_sat = 5_000_000;
1141+
premine_and_distribute_funds(
1142+
&bitcoind.client,
1143+
&electrsd.client,
1144+
vec![address_a],
1145+
Amount::from_sat(premine_amount_sat),
1146+
);
1147+
1148+
node_a.sync_wallets().unwrap();
1149+
open_channel(&node_a, &node_b, 4_000_000, true, &electrsd);
1150+
1151+
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6);
1152+
1153+
node_a.sync_wallets().unwrap();
1154+
node_b.sync_wallets().unwrap();
1155+
1156+
expect_channel_ready_event!(node_a, node_b.node_id());
1157+
expect_channel_ready_event!(node_b, node_a.node_id());
1158+
1159+
// Sleep until we broadcasted a node announcement.
1160+
while node_b.status().latest_node_announcement_broadcast_timestamp.is_none() {
1161+
std::thread::sleep(std::time::Duration::from_millis(10));
1162+
}
1163+
1164+
// Sleep one more sec to make sure the node announcement propagates.
1165+
std::thread::sleep(std::time::Duration::from_secs(1));
1166+
1167+
let recipient_id = vec![1, 2, 3];
1168+
let blinded_paths = node_a.blinded_paths_for_async_recipient(recipient_id, None).unwrap();
1169+
node_b.set_paths_to_static_invoice_server(blinded_paths).unwrap();
1170+
1171+
// Sleep to get the cache filled.
1172+
std::thread::sleep(std::time::Duration::from_secs(1));
1173+
1174+
let mut iter = 0;
1175+
while node_b.bolt12_payment().get_async_receive_offer().is_err() {
1176+
std::thread::sleep(std::time::Duration::from_millis(1000));
1177+
1178+
iter += 1;
1179+
if iter > 10 {
1180+
assert!(false, "Failed to fetch static invoice offer");
1181+
}
1182+
}
1183+
}
1184+
11331185
#[test]
11341186
fn test_node_announcement_propagation() {
11351187
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();

0 commit comments

Comments
 (0)