Skip to content

Commit 1ca0dab

Browse files
committed
Add e2e coverage for CLI config loading
Exercise the CLI against the server-generated config file so e2e tests cover client-side parsing of daemon config sections. Rebuild the e2e CLI binary when the client crate changes so this path cannot use stale code.
1 parent 6f50646 commit 1ca0dab

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

e2e-tests/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ fn main() {
5454
println!("cargo:rerun-if-changed=../ldk-server/Cargo.toml");
5555
println!("cargo:rerun-if-changed=../ldk-server-cli/src");
5656
println!("cargo:rerun-if-changed=../ldk-server-cli/Cargo.toml");
57+
println!("cargo:rerun-if-changed=../ldk-server-client/src");
58+
println!("cargo:rerun-if-changed=../ldk-server-client/Cargo.toml");
5759
println!("cargo:rerun-if-changed=../ldk-server-grpc/src");
5860
println!("cargo:rerun-if-changed=../ldk-server-grpc/Cargo.toml");
5961
println!("cargo:rerun-if-changed=../ldk-server-mcp/src");

e2e-tests/src/lib.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub struct LdkServerHandle {
9191
pub grpc_port: u16,
9292
pub p2p_port: u16,
9393
pub storage_dir: PathBuf,
94+
pub config_path: PathBuf,
9495
pub api_key: String,
9596
pub tls_cert_path: PathBuf,
9697
pub node_id: String,
@@ -214,6 +215,7 @@ poll_metrics_interval = 1
214215
grpc_port,
215216
p2p_port,
216217
storage_dir,
218+
config_path,
217219
api_key,
218220
tls_cert_path,
219221
node_id: String::new(),
@@ -381,13 +383,42 @@ pub fn run_cli_raw(handle: &LdkServerHandle, args: &[&str]) -> String {
381383
String::from_utf8(output.stdout).unwrap()
382384
}
383385

386+
/// Run a CLI command using the server's config file for connection details.
387+
pub fn run_cli_with_config_raw(handle: &LdkServerHandle, args: &[&str]) -> String {
388+
let cli_path = cli_binary_path();
389+
let output = Command::new(&cli_path)
390+
.arg("--config")
391+
.arg(handle.config_path.to_str().unwrap())
392+
.args(args)
393+
.output()
394+
.unwrap_or_else(|e| panic!("Failed to run CLI at {:?}: {}", cli_path, e));
395+
396+
if !output.status.success() {
397+
let stderr = String::from_utf8_lossy(&output.stderr);
398+
let stdout = String::from_utf8_lossy(&output.stdout);
399+
panic!(
400+
"CLI command {:?} failed with status {}\nstdout: {}\nstderr: {}",
401+
args, output.status, stdout, stderr
402+
);
403+
}
404+
405+
String::from_utf8(output.stdout).unwrap()
406+
}
407+
384408
/// Run a CLI command against the given server handle and return parsed JSON output.
385409
pub fn run_cli(handle: &LdkServerHandle, args: &[&str]) -> serde_json::Value {
386410
let stdout = run_cli_raw(handle, args);
387411
serde_json::from_str(&stdout)
388412
.unwrap_or_else(|e| panic!("Failed to parse CLI output as JSON: {e}\nOutput: {stdout}"))
389413
}
390414

415+
/// Run a CLI command using the server's config file and return parsed JSON output.
416+
pub fn run_cli_with_config(handle: &LdkServerHandle, args: &[&str]) -> serde_json::Value {
417+
let stdout = run_cli_with_config_raw(handle, args);
418+
serde_json::from_str(&stdout)
419+
.unwrap_or_else(|e| panic!("Failed to parse CLI output as JSON: {e}\nOutput: {stdout}"))
420+
}
421+
391422
/// Mine blocks and wait for all servers to sync to the new chain tip.
392423
pub async fn mine_and_sync(
393424
bitcoind: &TestBitcoind, servers: &[&LdkServerHandle], block_count: u64,

e2e-tests/tests/e2e.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use std::str::FromStr;
1111
use std::time::Duration;
1212

1313
use e2e_tests::{
14-
find_available_port, mine_and_sync, run_cli, run_cli_raw, setup_funded_channel,
15-
wait_for_onchain_balance, wait_for_usable_channel, LdkServerConfig, LdkServerHandle,
16-
TestBitcoind,
14+
find_available_port, mine_and_sync, run_cli, run_cli_raw, run_cli_with_config,
15+
setup_funded_channel, wait_for_onchain_balance, wait_for_usable_channel, LdkServerConfig,
16+
LdkServerHandle, TestBitcoind,
1717
};
1818
use hex_conservative::{DisplayHex, FromHex};
1919
use ldk_node::bitcoin::hashes::{sha256, Hash};
@@ -57,6 +57,15 @@ async fn test_cli_get_node_info() {
5757
assert_eq!(output["node_id"], server.node_id());
5858
}
5959

60+
#[tokio::test]
61+
async fn test_cli_get_node_info_with_server_config() {
62+
let bitcoind = TestBitcoind::new();
63+
let server = LdkServerHandle::start(&bitcoind).await;
64+
65+
let output = run_cli_with_config(&server, &["get-node-info"]);
66+
assert_eq!(output["node_id"], server.node_id());
67+
}
68+
6069
#[tokio::test]
6170
async fn test_cli_onchain_receive() {
6271
let bitcoind = TestBitcoind::new();

0 commit comments

Comments
 (0)