nix-bitcoin/test
Jonas Nick b34bf78574
Merge fort-nix/nix-bitcoin#674: tests/hardened: fix test for slower hardware
98b16a1f6c tests/hardened: fix test for slower hardware (Erik Arvstedt)

Pull request description:

ACKs for top commit:
  jonasnick:
    utACK 98b16a1f6c

Tree-SHA512: 04d51dcf1aa01f861dff0da3bd2bb65bba0046d53ab6849f930455c579be7a80d6444f9f45e2d17bf6dd946ad7c6b5a2e0e2b65ed64a9892d20dfd83e6c503fb
2024-01-16 11:58:23 +00:00
..
ci tests: define tests via flake 2022-11-03 23:08:06 +01:00
lib examples/deploy-container.sh: add extra-container version check 2023-07-19 17:22:01 +02:00
nixos-search update to NixOS 23.11 2023-12-12 11:22:38 +01:00
clightning-replication.nix update nixpkgs 2023-09-16 13:40:27 +00:00
README.md test/README: fix typos 2024-01-15 23:27:18 +01:00
run-tests.sh trustedcoin: add regtest support, reenable test 2023-08-03 18:40:13 +02:00
shellcheck.sh tests: add shellcheckServices 2022-09-12 21:00:00 +02:00
tests.nix tests/hardened: fix test for slower hardware 2024-01-15 23:12:06 +01:00
tests.py tests/trustedcoin: fix 2023-11-28 18:33:27 +00:00
wireguard-lndconnect.nix add presets/wireguard.nix 2023-03-11 20:10:54 +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 >= 2.10.

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