-
Notifications
You must be signed in to change notification settings - Fork 51
Add e2e config startup tests #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| // This file is Copyright its original authors, visible in version control | ||
| // history. | ||
| // | ||
| // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE | ||
| // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
| // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. | ||
| // You may not use this file except in accordance with one or both of these | ||
| // licenses. | ||
|
|
||
| use e2e_tests::{ | ||
| default_test_config, start_expect_failure, test_config_with_chain_source, LdkServerHandle, | ||
| TestBitcoind, | ||
| }; | ||
| use ldk_server_grpc::api::GetNodeInfoRequest; | ||
|
|
||
| fn remove_config_line(config: &str, key: &str) -> String { | ||
| config.lines().filter(|line| !line.trim_start().starts_with(key)).collect::<Vec<_>>().join("\n") | ||
| } | ||
|
|
||
| fn replace_config_line(config: &str, key: &str, new_line: &str) -> String { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure about this mix of having a config builder, but then also surgically modifying it again. Might be a bit brittle too. Any way to make this more consistent/robust? |
||
| config | ||
| .lines() | ||
| .map(|line| if line.trim_start().starts_with(key) { new_line } else { line }) | ||
| .collect::<Vec<_>>() | ||
| .join("\n") | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_config_no_alias() { | ||
| let bitcoind = TestBitcoind::new(); | ||
| let server = LdkServerHandle::start_with_config(&bitcoind, |params| { | ||
| remove_config_line(&default_test_config(params), "alias =") | ||
| }) | ||
| .await; | ||
| let info = server.client().get_node_info(GetNodeInfoRequest {}).await.unwrap(); | ||
| assert!(info.current_best_block.is_some()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_config_no_listening_addresses() { | ||
| let bitcoind = TestBitcoind::new(); | ||
| let server = LdkServerHandle::start_with_config(&bitcoind, |params| { | ||
| let config = remove_config_line(&default_test_config(params), "listening_addresses ="); | ||
| // Alias requires listening addresses for announcement, so remove it too | ||
| remove_config_line(&config, "alias =") | ||
| }) | ||
| .await; | ||
| let info = server.client().get_node_info(GetNodeInfoRequest {}).await.unwrap(); | ||
| assert!(info.current_best_block.is_some()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_config_multiple_listening_addresses() { | ||
| let bitcoind = TestBitcoind::new(); | ||
| let server = LdkServerHandle::start_with_config(&bitcoind, |params| { | ||
| let extra_port = e2e_tests::find_available_port(); | ||
| replace_config_line( | ||
| &default_test_config(params), | ||
| "listening_addresses =", | ||
| &format!( | ||
| "listening_addresses = [\"127.0.0.1:{}\", \"127.0.0.1:{}\"]", | ||
| params.p2p_port, extra_port | ||
| ), | ||
| ) | ||
| }) | ||
| .await; | ||
| let info = server.client().get_node_info(GetNodeInfoRequest {}).await.unwrap(); | ||
| assert!(info.current_best_block.is_some()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and above, perhaps assert a bit more, in particular the addresses? These tests do look quite similar to what's already in ldk-node, IIRC. Not sure if it adds much. |
||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_config_with_announcement_addresses() { | ||
| let bitcoind = TestBitcoind::new(); | ||
| let server = LdkServerHandle::start_with_config(&bitcoind, |params| { | ||
| let mut config = default_test_config(params); | ||
| // Insert announcement_addresses after alias line | ||
| config = config.replace( | ||
| "alias = \"e2e-test-node\"", | ||
| &format!( | ||
| "alias = \"e2e-test-node\"\nannouncement_addresses = [\"127.0.0.1:{}\"]", | ||
| params.p2p_port | ||
| ), | ||
| ); | ||
| config | ||
| }) | ||
| .await; | ||
| let info = server.client().get_node_info(GetNodeInfoRequest {}).await.unwrap(); | ||
| assert!(info.current_best_block.is_some()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_config_with_log_file() { | ||
| let bitcoind = TestBitcoind::new(); | ||
| let server = LdkServerHandle::start_with_config(&bitcoind, |params| { | ||
| let log_path = format!("{}/ldk-server.log", params.storage_dir.display()); | ||
| let mut config = default_test_config(params); | ||
| config.push_str(&format!("\n[log]\nlevel = \"Debug\"\nfile = \"{}\"\n", log_path)); | ||
| config | ||
| }) | ||
| .await; | ||
| let info = server.client().get_node_info(GetNodeInfoRequest {}).await.unwrap(); | ||
| assert!(info.current_best_block.is_some()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_config_with_tls_hosts() { | ||
| let bitcoind = TestBitcoind::new(); | ||
| let server = LdkServerHandle::start_with_config(&bitcoind, |params| { | ||
| let mut config = default_test_config(params); | ||
| config.push_str("\n[tls]\nhosts = [\"example.com\", \"ldk-server.local\"]\n"); | ||
| config | ||
| }) | ||
| .await; | ||
| let info = server.client().get_node_info(GetNodeInfoRequest {}).await.unwrap(); | ||
| assert!(info.current_best_block.is_some()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_config_fail_log_file_matches_storage_dir() { | ||
| let bitcoind = TestBitcoind::new(); | ||
| let stderr = start_expect_failure(&bitcoind, |params| { | ||
| let mut config = default_test_config(params); | ||
| config.push_str(&format!("\n[log]\nfile = \"{}\"\n", params.storage_dir.display())); | ||
| config | ||
| }); | ||
| assert!( | ||
| stderr.contains("Log file path cannot be the same as storage directory path"), | ||
| "Unexpected stderr: {stderr}" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_config_fail_log_file_matches_network_dir() { | ||
| let bitcoind = TestBitcoind::new(); | ||
| let stderr = start_expect_failure(&bitcoind, |params| { | ||
| let mut config = default_test_config(params); | ||
| let network_dir = params.storage_dir.join("regtest"); | ||
| config.push_str(&format!("\n[log]\nfile = \"{}\"\n", network_dir.display())); | ||
| config | ||
| }); | ||
| assert!( | ||
| stderr.contains("Log file path cannot be the same as storage directory path"), | ||
| "Unexpected stderr: {stderr}" | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_config_chain_source_bitcoind_localhost() { | ||
| let bitcoind = TestBitcoind::new(); | ||
| let server = LdkServerHandle::start_with_config(&bitcoind, |params| { | ||
| // Use "localhost:port" instead of "127.0.0.1:port" to test hostname RPC support | ||
| let rpc_address = params.rpc_address.replace("127.0.0.1", "localhost"); | ||
| test_config_with_chain_source( | ||
| params, | ||
| &format!( | ||
| "[bitcoind]\nrpc_address = \"{}\"\nrpc_user = \"{}\"\nrpc_password = \"{}\"", | ||
| rpc_address, params.rpc_user, params.rpc_password | ||
| ), | ||
| ) | ||
| }) | ||
| .await; | ||
| let info = server.client().get_node_info(GetNodeInfoRequest {}).await.unwrap(); | ||
| assert!(info.current_best_block.is_some()); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is duplicated in a few places, perhaps it can be a helper.