#integration-tests #process #environment #instance #connected #temp-dir #testing

lnd

Utility to run a regtest lnd process connected to a given bitcoind instance, useful in integration testing environment

4 releases

0.1.5 May 27, 2024
0.1.4 Mar 15, 2024
0.1.2 Jan 9, 2024
0.1.0 Dec 19, 2023

#21 in #connected

Download history 2/week @ 2024-02-13 14/week @ 2024-02-20 1/week @ 2024-02-27 4/week @ 2024-03-05 116/week @ 2024-03-12 35/week @ 2024-03-19 15/week @ 2024-03-26 43/week @ 2024-04-02 52/week @ 2024-04-09 29/week @ 2024-04-16 48/week @ 2024-04-23 9/week @ 2024-04-30 8/week @ 2024-05-07 91/week @ 2024-05-21 52/week @ 2024-05-28

153 downloads per month

MIT license

27KB
479 lines

Lnd Integration Test Utility

Crate Documentation

Mostly a copy of electrsd & bitcoind fit for LND.

Utility to run a regtest LND process connected to a given bitcoind instance, useful in integration testing environment.

// Create a bitcoind instance
let mut bitcoin_conf = bitcoind::Conf::default();
bitcoin_conf.enable_zmq = true;

let bitcoind = bitcoind::BitcoinD::with_conf("/usr/local/bin/bitcoind", &bitcoin_conf).unwrap();

// Pass the binary path, bitcoind, and ZMQ ports
let mut lnd = lnd::Lnd::new("<path to lnd>", &bitcoind);

let node = lnd.client.lightning().get_info(GetInfoRequest {}).await; 

assert!(node.is_ok());

Automatic binaries download

In your project Cargo.toml, activate the following features

lnd = { version = "*", features = ["download"] }

To use it:

let bitcoind_exe = bitcoind::downloaded_exe_path().expect("bitcoind version feature must be enabled");
let bitcoind = bitcoind::BitcoinD::new(bitcoind_exe).unwrap();
let lnd_exe = lnd::downloaded_exe_path().expect("lnd version feature must be enabled");
let lnd = lnd::Lnd::new(lnd_exe, bitcoind).unwrap();

When the LND_DOWNLOAD_ENDPOINT/BITCOIND_DOWNLOAD_ENDPOINT environment variables are set, lnd/bitcoind will try to download the binaries from the given endpoints.

When you don't use the auto-download feature you have the following options:

  • have lnd executable in the PATH
  • provide the lnd executable via the LND_EXEC env var
if let Ok(exe_path) = lnd::exe_path() {
  let lnd = lnd::Lnd::new(exe_path, &bitcoind).unwrap();
}

Features

  • lnd use a temporary directory as db dir
  • A free port is asked to the OS (a very low probability race condition is still possible)
  • The process is killed when the struct goes out of scope no matter how the test finishes

Thanks to these features every #[test] could easily run isolated with its own environment

Dependencies

~27–41MB
~708K SLoC