nix-bitcoin/test
Jonas Nick e2ca2e4967
Merge fort-nix/nix-bitcoin#795: CI: Switch from Cirrus to Github Actions
5516bcc43b ci: switch from Cirrus to Github Actions (Erik Arvstedt)
7d33e9d5e9 tests: extract fn `instantiateTestsFromStr` (Erik Arvstedt)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK 5516bcc43b

Tree-SHA512: 1aa23ffc52c8e9b7efd38fbf31be9bab7a7e187571c6bee8c1dbdb8eb14f90995b260d10f0d3d9968d6e9be1be452d22173d9775fd6d42a94a01f41ab3305d21
2025-07-03 08:16:40 +00:00
..
ci ci: switch from Cirrus to Github Actions 2025-06-26 23:26:57 +02:00
lib flake: update extra-container 2024-12-14 10:52:27 +01:00
nixos-search update nixpkgs 2025-06-29 15:10:42 +02:00
clightning-replication.nix modules: update to NixOS 24.11 2024-12-14 10:52:26 +01:00
README.md test/README: mention Flakes requirement 2025-01-22 20:48:12 +01:00
run-tests.sh tests: extract fn instantiateTestsFromStr 2025-06-26 23:23:51 +02:00
shellcheck.sh tests: add shellcheckServices 2022-09-12 21:00:00 +02:00
tests.nix tests: extract fn instantiateTestsFromStr 2025-06-26 23:23:51 +02:00
tests.py update nixpkgs 2025-03-11 19:36:26 +00:00
wireguard-lndconnect.nix lndconnect: add clnrest 2024-11-27 21:35:46 +01:00

The run-tests.sh command is the most convenient and versatile way to run tests.
It leave no traces (outside of /nix/store) on the host system.

run-tests.sh requires Nix with Flakes.

Summary

./run-tests.sh [--scenario|-s <scenario>] [build|vm|debug|container]

See the top of run-tests.sh for a complete documentation.
Test scenarios are defined in tests.nix and tests.py.

Tutorial

Running tests

# Run the basic set of tests. These tests are also run on the GitHub CI server.
./run-tests.sh

# Run the test for scenario `regtest`.
# The test is run via the Nix build system. Successful runs are cached.
./run-tests.sh -s regtest build
./run-tests.sh -s regtest # Shorthand, equivalent

# To test a single service, use its name as a scenario.
./run-tests.sh -s clightning

# When no scenario is specified, scenario `default` is used.
./run-tests.sh build

Debugging

# Start a shell inside a test VM. No tests are executed.
./run-tests.sh -s bitcoind vm
systemctl status bitcoind

# Run a Python NixOS test shell inside a VM.
# See https://nixos.org/manual/nixos/stable/#ssec-machine-objects for available commands.
./run-tests.sh debug
print(succeed("systemctl status bitcoind"))
run_test("bitcoind")

# Start a shell in a container node. Requires systemd and root privileges.
./run-tests.sh container

# In the container shell: Run command in container (with prefix `c`)
c systemctl status bitcoind

# Explore a single feature
./run-tests.sh -s electrs container

# Run a command in a container.
# The container is deleted afterwards.
./run-tests.sh -s clightning container --run c lightning-cli getinfo

# Define a custom scenario
./run-tests.sh --scenario '{
  services.clightning.enable = true;
  nix-bitcoin.nodeinfo.enable = true;
}' container --run c nodeinfo

Running tests with Flakes

Tests can also be accessed via the nix-bitcoin flake:

# Build test
nix build --no-link ..#tests.default

# Run a node in a VM. No tests are executed.
nix run ..#tests.default.vm

# Run a Python test shell inside a VM node
nix run ..#tests.default.run -- --debug

# Run a node in a container. Requires extra-container, systemd and root privileges
nix run ..#tests.default.container
nix run ..#tests.default.containerLegacy # For NixOS with `system.stateVersion` <22.05

# Run a command in a container
nix run ..#tests.default.container -- --run c nodeinfo
nix run ..#tests.default.containerLegacy -- --run c nodeinfo # For NixOS with `system.stateVersion` <22.05