Run the tests
Run Liana's unit tests, its functional tests against Bitcoin Core on regtest, and its fuzz targets.
Run every command from the root of your clone of the Liana repository, with Rust and the system libraries of Build from source. The functional tests and the fuzz targets do not run on Windows.
Run the unit tests
cargo testThis tests every crate of the workspace except the fuzz targets. On Windows,
add --no-default-features, as CI does.
To test one crate, name it:
cargo test -p lianadRun the functional tests
The suite starts a new bitcoind on regtest for each test, and drives lianad
through its JSON-RPC socket.
Build lianad without optimizations
cargo build -p lianadThe suite runs target/debug/lianad, the output of a
debug build. To test
another binary, set LIANAD_PATH to its path, as CI does with a release build.
Install the Python dependencies
python3 -m venv venv
. venv/bin/activate
pip install -r tests/requirements.txttests/README.md lists these Ubuntu packages as ones you may also need:
sudo apt update
sudo apt install build-essential libssl-dev libffi-dev python3-dev autoconf automake libtoolPoint the suite at Bitcoin Core
Install Bitcoin Core 24.0.1 or later from
bitcoincore.org. The suite runs the
bitcoind on your PATH, or the one BITCOIND_PATH names:
export BITCOIND_PATH="$HOME/bitcoin-31.1/bin/bitcoind"With Bitcoin Core 24.0.1 or another 24.x release, also set
IS_NOT_BITCOIND_24=0. The suite then skips the two tests that need the
submit argument of generateblock, which Bitcoin Core added in 25.0.
Run the suite
pytest -n 8 tests/-n 8 spreads the tests over 8 processes, as CI does. A default run skips the
tests that need Taproot mode or OLD_LIANAD_PATH.
Run the functional tests on Taproot descriptors
With USE_TAPROOT=1, the suite builds Taproot (P2TR) descriptors, tr(...),
instead of SegWit (P2WSH) descriptors, wsh(...). This mode needs Bitcoin Core
26.0 or later.
The suite signs Taproot PSBTs with a helper program. Build it, then run the suite:
(cd tests/tools/taproot_signer && cargo build --release)
USE_TAPROOT=1 pytest -n 8 tests/Run the functional tests against an Electrum server
With BITCOIN_BACKEND_TYPE=electrs, the suite starts electrs on top of its
bitcoind. lianad then connects to electrs instead. Install electrs
0.10.6, the version CI uses. Set ELECTRS_PATH to the full path of electrs,
because the suite starts electrs with no PATH in its environment.
export ELECTRS_PATH="$HOME/electrs/target/release/electrs"
BITCOIN_BACKEND_TYPE=electrs pytest -n 8 tests/Set the other test variables
The suite also reads these variables, defined in
tests/test_framework/utils.py and tests/fixtures.py.
Prop
Type
Debug a failing test
Run the test alone, with its log printed live:
VERBOSE=1 pytest -vvv --log-cli-level=DEBUG tests/test_rpc.py::test_create_recoveryLeave out -n here, because pytest-xdist does not show the output of its
workers.
The suite keeps the folder of a failed test, inside its lianad-tests-* folder
in TEST_DIR. It saves the output of each daemon there, in a log file:
lianad/log, bitcoind/log, and electrs/log in electrs mode.
Fuzz the descriptor code
cargo-fuzz needs nightly Rust, a C++ compiler, and an x86-64 or AArch64 machine running a Unix-like system such as Linux or macOS.
Install nightly Rust and cargo-fuzz
rustup toolchain install nightly
cargo install cargo-fuzzrust-toolchain.toml pins Rust 1.88.0 in the repository. Add +nightly to
every cargo fuzz command to override it.
Pick a target
descriptor_parse: Parses its input as a Liana descriptor, then checks that the descriptor survives a round trip through its string form.descriptors: Builds Liana policies, SegWit (P2WSH) and Taproot (P2TR), then calls the descriptor and PSBT methods of thelianacrate on them.
This command prints the same two names:
cargo +nightly fuzz listRun the target
cargo +nightly fuzz run descriptor_parse -- -max_total_time=600libFuzzer stops at the first crash, or after 600 seconds.
cargo-fuzz saves a crashing input in fuzz/artifacts/descriptor_parse/. Pass
that file to replay the crash:
cargo +nightly fuzz run descriptor_parse fuzz/artifacts/descriptor_parse/crash-<sha1>CI does not build the fuzz targets. After a change to the liana crate, check
that they still compile:
cargo +nightly fuzz build