This document is a guide for the different testing options available in Floresta. We have an extensive suite of Rust tests, as well as a functional tests Python framework, found in the tests directory. For fuzzing tests refer to this document.
The tests in floresta-cli depend on the compiled florestad binary. Make sure to build the entire project first by running:
cargo buildThe functional tests also need some dependencies, we use python for writing them and uv to manage its dependencies.
The functional tests will build Bitcoin Core, Utreexo and Floresta in order to make integration testing. To do so it will use some dependencies.
The following guide is a compilation taken from Bitcoin and Utreexo. It considers the user running the tests already has the required dependencies for building Floresta.
sudo apt-get install build-essential cmake pkgconf python3 libevent-dev libboost-dev golangsudo dnf install gcc-c++ cmake make python3 libevent-devel boost-devel golangbrew install cmake boost pkgconf libevent coreutils goUV is an extremely fast Python package and project manager, written in Rust.
# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | shThere's a set of unit and integration Rust tests that you can run with:
cargo testFor the full test suite, including long-running tests, use:
cargo test --releaseNext sections will cover the Python functional tests.
We provide three way for running functional tests:
- from
justtool that abstracts what is necessary to run the tests before doing a commit; - from helper scripts — prepare.sh and run.sh — to automatically build and run the tests;
- from python utility directly: the most laborious, but you can run a specific test suite.
It abstracts all things that will be explained in the next sections, and for that reason, we recommend to use it before doing a commit when changes only the functional tests.
just test-functionalFurthermore, you can only specific tests, rather than all at once.
# runs all tests in 'floresta-cli' suite
just test-functional-run "--test-suite floresta-cli"
# same as above
just test-functional-run "-t floresta-cli"
# run the stop and ping tests in the floresta-cli suite
just test-functional-run "--test-suite floresta-cli --test-name stop --test-name ping"
# same as above
just test-functional-run "-t floresta-cli -k stop -k ping"
# run many tests that start with the word `getblock` (getblockhash, getblockheader, etc...)
just test-functional-run "-t floresta-cli -k getblock"We provide two helper scripts to support our functional tests in this process and guarantee isolation and reproducibility.
-
prepare.sh checks for build dependencies for both
utreexodandflorestad, builds them, and sets the$FLORESTA_TEMP_DIRenvironment variable. This variable points to where our functional tests will look for the binaries — specifically at$FLORESTA_TEMP_DIR/binaries. -
run.sh adds the binaries found at
$FLORESTA_TEMP_DIR/binariesto your$PATHand runs the tests in that environment.
So a basic usage would be:
./tests/prepare.sh && ./tests/run.shBy default, the tool will build utreexod on its latest release.
If you want to build a specific release, you can set the UTREEXO_REVISION environment variable before running the script.
It must be a valid tag without the v prefix. For example:
UTREEXO_REVISION=0.1.0 ./tests/prepare.sh && ./tests/run.shBy default, the prepare.sh script will obtain a runnable bitcoind binary in one of three exclusive ways. The default Bitcoin Core version is 30.2, but you can override this by setting the BITCOIN_REVISION environment variable. The three methods are:
- Using a user-provided binary: If the
BITCOIND_EXEenvironment variable is set and points to an executable, that exact binary is used. No download or build is attempted, and anyBITCOIN_REVISIONor build-parallelism settings are ignored.
BITCOIND_EXE=/path/to/bitcoind ./tests/prepare.sh- Downloading a prebuilt binary: If
BITCOIND_EXEis not set, the script will try to download a prebuilt Bitcoin Core tarball for the specifiedBITCOIN_REVISION. Prebuilt binaries are available for all platforms and operating systems supported by Bitcoin Core. The supported versions are30.2,29.2,28.3and27.2.
BITCOIN_REVISION=28.3 ./tests/prepare.sh- Building from source: If no prebuilt binary is available for the platform, operating system, or specified version, the script will clone the Bitcoin Core repository and build
bitcoindfrom the specifiedBITCOIN_REVISION. This can be a version tag (e.g.,29.1) or a branch(e.g.,master) from the remote repository.
BITCOIN_REVISION=master ./tests/prepare.shAdditionally, you can use some arguments in those scripts:
./tests/prepare.sh --build --release && ./tests/run.sh --preserve-data-dirThe --build argument will force the script to fetch the bitcoind binary again and to build the utreexod.
The --release argument will build the florestad binary in release mode, which is optimized for production use. If this flag is not provided, the binary will be built in debug mode by default.
The --preserve-data-dir argument will keep the data and logs directories after running the tests
(this is useful if you want to keep the data for debugging purposes).
Furthermore, you can run a set of specific tests, rather than all at once.
# runs all tests in 'floresta-cli' suite
./tests/run.sh --test-suite floresta-cli
# same as above
./tests/run.sh -t floresta-cli
# run the stop and ping tests in the floresta-cli suite
./tests/run.sh --test-suite floresta-cli --test-name stop --test-name ping
# same as above
./tests/run.sh -t floresta-cli -k stop -k ping
# run many tests that start with the word `getblock` (getblockhash, getblockheader, etc...)
./tests/run.sh -t floresta-cli -k getblockAdditional functional tests are available (minimum python version: 3.12).
It's not recommended to run them directly, since you will need to manually
build the binaries yourself and place them at $FLORESTA_TEMP_DIR/binaries.
The advantage is that you can run a specific test suite. For this you'll need to:
- Setup
floresta/utreexodenvironment; - Setup python utility;
- Run tests from python utility directly;
- Clean up the environment.
After build the floresta and utreexod binaries, you'll need to define
a FLORESTA_TEMP_DIR environment variable. This variable points to where
our functional tests will look for the binaries.
-
Recommended: install uv: a rust-based python package and project manager.
-
Configure an isolated environment:
# create a virtual environment
# (it's good to not mess up with your os)
uv venv
# Alternatively, you can specify a python version (e.g, 3.12),
uv venv --python 3.12
# activate the python virtual environment
source .venv/bin/activate
# check if the python path was modified
which python- Install module dependencies:
# installs dependencies listed in pyproject.toml.
# in local development environment
# it do not remove existing packages.
uv pip install -r pyproject.toml
# if you're a old-school pythonist,
# install from requirements.txt
# without remove existing packages.
uv pip install -r tests/requirements.txt
# Alternatively, you can synchronize it
# uses the uv.lock file to enforce
# reproducible installations.
uv sync- Format code
uv run black ./tests
# if you want to just check
uv run black --check --verbose ./tests- Lint code
uv run pylint ./testsOur tests are separated by "test suites". Suites are folders located in ./tests/<suite> and the tests are the ./tests/<suite>/*-test.py files. To run all suites, type:
FLORESTA_TEMP_DIR=<your_bin_dir> uv run tests/test_runner.pyYou can list all suites with:
FLORESTA_TEMP_DIR=<your_bin_dir> uv run tests/test_runner.py --list-suitesTo run a specific suite:
FLORESTA_TEMP_DIR=<your_bin_dir> uv run tests/test_runner.py --test-suite <suite>You can even add more:
FLORESTA_TEMP_DIR=<your_bin_dir> uv run tests/test_runner.py --test-suite <suite_A> --test-suite <suite_B>If you tests fails it will be necessary to cleanup the data
folder created by the tests (some tests use it to retain
information about tested nodes, like the addnode command).
You can do this by running:
rm -rf FLORESTA_TEMP_DIR/dataIf you have nix, you can run the tests following the instructions here.