Skip to content
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

tests: move test lnd logs to a more permanent location #65

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ jobs:
with:
command: test
args: --all-targets --benches -- --test-threads=1
- name: Archive lnd logs
uses: actions/upload-artifact@v3
with:
name: lnd-logs
path: |
/tmp/lnd_logs
- name: Archive ldk logs
uses: actions/upload-artifact@v3
with:
name: ldk-logs
path: |
/tmp/ldk_logs
- uses: actions-rs/cargo@v1
name: cargo fmt
with:
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ bytes = "1.4.0"
[dev-dependencies]
bitcoincore-rpc = { package="core-rpc", version = "0.17.0" }
bitcoind = { version = "0.30.0", features = [ "22_0" ] }
chrono = { version = "0.4.26" }
electrsd = { version = "0.22.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_23_0"] }
flate2 = "1.0.25"
ldk-node = "0.1.0"
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node", rev = "3a31209" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's quickly get in some of the other bug fixes :)

Suggested change
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node", rev = "3a31209" }
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node", rev = "77acd3b" }

minreq = { version = "2.7.0", features = [ "https" ] }
mockall = "0.11.3"
tar = "0.4.38"
Expand Down
56 changes: 46 additions & 10 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use bitcoincore_rpc::{bitcoin::Network, json, RpcApi};
use bitcoind::{BitcoinD, Conf, ConnectParams};
use chrono::Utc;
orbitalturtle marked this conversation as resolved.
Show resolved Hide resolved
use electrsd::ElectrsD;
use flate2::read::GzDecoder;
use ldk_node::bitcoin::Network as LdkNetwork;
use ldk_node::io::SqliteStore;
use ldk_node::{Builder as LdkBuilder, NetAddress, Node};
use std::env;
use std::fs::File;
use std::process::{Child, Command, Stdio};
use std::str::FromStr;
use std::thread;
Expand All @@ -16,10 +18,16 @@ use tonic_lnd::Client;

const LND_VERSION: &str = "0.16.2";

// setup_test_infrastructure spins up all of the infrastructure we need to test LNDK, including a bitcoind node, an LND
// node, an electrsd instance (required for now for LDK to run), and a LDK node. LNDK can then use this test
// environment to run.
pub async fn setup_test_infrastructure() -> (
// setup_test_infrastructure spins up all of the infrastructure we need to test LNDK, including a bitcoind node and two
// LND nodes. LNDK can then use this test environment to run.
//
// Notes for developers looking for associated logs:
// - Logs for LND and LDK for the integration tests live in /tmp (or whatever the temporary directory is in the
// corresponding OS).
// - The "test_name" parameter is required to distinguish the logs coming from different integration tests.
pub async fn setup_test_infrastructure(
test_name: String,
) -> (
BitcoinD,
LndNode,
TempDir,
Expand All @@ -30,14 +38,14 @@ pub async fn setup_test_infrastructure() -> (
let (bitcoind, bitcoind_dir) = setup_bitcoind().await;
let lnd_exe_dir = download_lnd().await;

let mut lnd_node = LndNode::new(bitcoind.params.clone(), lnd_exe_dir);
let mut lnd_node = LndNode::new(bitcoind.params.clone(), lnd_exe_dir, test_name.clone());
lnd_node.setup_client().await;

// We also need to set up electrs, because that's the way ldk-node (currently) communicates with bitcoind to get
// bitcoin blocks and transactions.
let electrsd = setup_electrs().await;
let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap());
let (ldk_node, ldk_dir) = setup_ldk(esplora_url).await;
let (ldk_node, ldk_dir) = setup_ldk(esplora_url, test_name).await;

return (
bitcoind,
Expand Down Expand Up @@ -165,19 +173,32 @@ pub struct LndNode {
}

impl LndNode {
fn new(bitcoind_connect_params: ConnectParams, lnd_exe_dir: TempDir) -> LndNode {
fn new(
bitcoind_connect_params: ConnectParams,
lnd_exe_dir: TempDir,
test_name: String,
) -> LndNode {
env::set_current_dir(lnd_exe_dir.path().join("lnd-linux-amd64-v0.16.2-beta"))
.expect("couldn't set current directory");

let lnd_dir_binding = Builder::new().prefix("lnd").tempdir().unwrap();
let lnd_dir = lnd_dir_binding.path();

let cert_path = lnd_dir.join("tls.cert").to_str().unwrap().to_string();
let now_timestamp = Utc::now();
let timestamp = now_timestamp.format("%d-%m-%Y-%H-%M");
let lnd_log_dir = env::temp_dir().join(format!("lnd_logs"));
let log_dir_path_buf = lnd_log_dir.join(format!("lnd-logs-{test_name}-{timestamp}"));
let log_dir = log_dir_path_buf.as_path();
let data_dir = lnd_dir.join("data").to_str().unwrap().to_string();
let cert_path = lnd_dir.to_str().unwrap().to_string() + "/tls.cert";
let key_path = lnd_dir.to_str().unwrap().to_string() + "/tls.key";
let config_path = lnd_dir.to_str().unwrap().to_string() + "/lnd.conf";
let macaroon_path = lnd_dir
.join("data/chain/bitcoin/regtest/admin.macaroon")
.to_str()
.unwrap()
.to_string();
let _file = File::create(config_path.clone()).unwrap();

// Have node run on a randomly assigned grpc port. That way, if we run more than one lnd node, they won't
// clash.
Expand All @@ -191,7 +212,11 @@ impl LndNode {
format!("--bitcoin.active"),
format!("--bitcoin.node=bitcoind"),
format!("--bitcoin.regtest"),
format!("--lnddir={}", lnd_dir.display()),
format!("--datadir={}", data_dir),
format!("--tlscertpath={}", cert_path),
format!("--tlskeypath={}", key_path),
format!("--configfile={}", config_path),
format!("--logdir={}", log_dir.display()),
format!(
"--bitcoind.rpccookie={}",
bitcoind_connect_params.cookie_file.display()
Expand Down Expand Up @@ -261,14 +286,25 @@ impl LndNode {
}

// setup_ldk sets up an ldk node.
async fn setup_ldk(esplora_url: String) -> (Node<SqliteStore>, TempDir) {
async fn setup_ldk(esplora_url: String, test_name: String) -> (Node<SqliteStore>, TempDir) {
let mut builder = LdkBuilder::new();
builder.set_network(LdkNetwork::Regtest);
builder.set_esplora_server(esplora_url);

let ldk_dir = tempdir().unwrap();
let ldk_dir_path = ldk_dir.path().to_str().unwrap().to_string();

let now_timestamp = Utc::now();
let timestamp = now_timestamp.format("%d-%m-%Y-%H-%M");
let ldk_log_dir = env::temp_dir().join(format!("ldk_logs"));
let ldk_log_dir_path = ldk_log_dir
.join(format!("ldk-logs-{test_name}-{timestamp}"))
.into_os_string()
.into_string()
.unwrap();

builder.set_storage_dir_path(ldk_dir_path);
builder.set_log_dir_path(ldk_log_dir_path);

let open_port = bitcoind::get_available_port().unwrap();
let listening_addr = NetAddress::from_str(&format!("127.0.0.1:{open_port}")).unwrap();
Expand Down
4 changes: 3 additions & 1 deletion tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ mod common;

#[tokio::test]
async fn test_setup() {
let test_name = String::from("test_setup");

// Spin up a bitcoind and lnd node, which are required for our tests.
let (_bitcoind, _lnd, _bitcoind_dir, _electrsd, _ldk_node, _ldk_dir) =
common::setup_test_infrastructure().await;
common::setup_test_infrastructure(test_name).await;
}
Loading