Skip to content

Commit 4d90c74

Browse files
committed
Add e2e tests for network graph API endpoints
Co-Authored-By: HAL 9000
1 parent 74a55bf commit 4d90c74

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

e2e-tests/tests/e2e.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,70 @@ async fn test_cli_splice_out() {
457457
assert!(address.starts_with("bcrt1"), "Expected regtest address, got: {}", address);
458458
}
459459

460+
#[tokio::test]
461+
async fn test_cli_graph_list_channels_empty() {
462+
let bitcoind = TestBitcoind::new();
463+
let server = LdkServerHandle::start(&bitcoind).await;
464+
465+
let output = run_cli(&server, &["graph-list-channels"]);
466+
assert!(output["short_channel_ids"].as_array().unwrap().is_empty());
467+
}
468+
469+
#[tokio::test]
470+
async fn test_cli_graph_list_nodes_empty() {
471+
let bitcoind = TestBitcoind::new();
472+
let server = LdkServerHandle::start(&bitcoind).await;
473+
474+
let output = run_cli(&server, &["graph-list-nodes"]);
475+
assert!(output["node_ids"].as_array().unwrap().is_empty());
476+
}
477+
478+
#[tokio::test]
479+
async fn test_cli_graph_with_channel() {
480+
let bitcoind = TestBitcoind::new();
481+
let server_a = LdkServerHandle::start(&bitcoind).await;
482+
let server_b = LdkServerHandle::start(&bitcoind).await;
483+
setup_funded_channel(&bitcoind, &server_a, &server_b, 100_000).await;
484+
485+
// Wait for the channel announcement to appear in the network graph.
486+
let scid = {
487+
let start = std::time::Instant::now();
488+
loop {
489+
let output = run_cli(&server_a, &["graph-list-channels"]);
490+
let scids = output["short_channel_ids"].as_array().unwrap();
491+
if !scids.is_empty() {
492+
break scids[0].as_u64().unwrap().to_string();
493+
}
494+
if start.elapsed() > Duration::from_secs(30) {
495+
panic!("Timed out waiting for channel to appear in network graph");
496+
}
497+
tokio::time::sleep(Duration::from_secs(1)).await;
498+
}
499+
};
500+
501+
// Test GraphGetChannel: should return channel info with both our nodes.
502+
let output = run_cli(&server_a, &["graph-get-channel", &scid]);
503+
let channel = &output["channel"];
504+
let node_one = channel["node_one"].as_str().unwrap();
505+
let node_two = channel["node_two"].as_str().unwrap();
506+
let nodes = [server_a.node_id(), server_b.node_id()];
507+
assert!(nodes.contains(&node_one), "node_one {} not one of our nodes", node_one);
508+
assert!(nodes.contains(&node_two), "node_two {} not one of our nodes", node_two);
509+
510+
// Test GraphListNodes: should contain both node IDs.
511+
let output = run_cli(&server_a, &["graph-list-nodes"]);
512+
let node_ids: Vec<&str> =
513+
output["node_ids"].as_array().unwrap().iter().map(|n| n.as_str().unwrap()).collect();
514+
assert!(node_ids.contains(&server_a.node_id()), "Expected server_a in graph nodes");
515+
assert!(node_ids.contains(&server_b.node_id()), "Expected server_b in graph nodes");
516+
517+
// Test GraphGetNode: should return node info with at least one channel.
518+
let output = run_cli(&server_a, &["graph-get-node", server_b.node_id()]);
519+
let node = &output["node"];
520+
let channels = node["channels"].as_array().unwrap();
521+
assert!(!channels.is_empty(), "Expected node to have at least one channel");
522+
}
523+
460524
#[tokio::test]
461525
async fn test_cli_completions() {
462526
let bitcoind = TestBitcoind::new();

0 commit comments

Comments
 (0)