2020-09-27 10:43:20 +00:00
|
|
|
# Integration tests, can be run without internet access.
|
2020-01-12 19:52:40 +00:00
|
|
|
|
2021-03-22 12:19:48 +00:00
|
|
|
let
|
|
|
|
nixpkgs = (import ../pkgs/nixpkgs-pinned.nix).nixpkgs;
|
|
|
|
in
|
2020-07-16 14:48:41 +00:00
|
|
|
|
2021-03-22 12:19:48 +00:00
|
|
|
{ extraScenarios ? { ... }: {}
|
|
|
|
, pkgs ? import nixpkgs { config = {}; overlays = []; }
|
|
|
|
}:
|
|
|
|
with pkgs.lib;
|
|
|
|
let
|
|
|
|
globalPkgs = pkgs;
|
2020-01-12 19:52:40 +00:00
|
|
|
|
2021-03-22 12:19:48 +00:00
|
|
|
baseConfig = { pkgs, config, ... }: let
|
|
|
|
cfg = config.services;
|
|
|
|
mkIfTest = test: mkIf (config.tests.${test} or false);
|
|
|
|
in {
|
2020-01-12 19:52:40 +00:00
|
|
|
imports = [
|
2020-09-27 10:43:20 +00:00
|
|
|
./lib/test-lib.nix
|
|
|
|
../modules/modules.nix
|
2020-09-28 11:09:04 +00:00
|
|
|
{
|
|
|
|
# Features required by the Python test suite
|
|
|
|
nix-bitcoin.secretsDir = "/secrets";
|
2021-03-10 13:08:34 +00:00
|
|
|
nix-bitcoin.generateSecrets = true;
|
2020-09-28 11:09:04 +00:00
|
|
|
nix-bitcoin.operator.enable = true;
|
|
|
|
environment.systemPackages = with pkgs; [ jq ];
|
|
|
|
}
|
2020-01-12 19:52:40 +00:00
|
|
|
];
|
|
|
|
|
2020-11-19 02:01:45 +00:00
|
|
|
options.test.features = {
|
|
|
|
clightningPlugins = mkEnableOption "all clightning plugins";
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [{
|
2021-03-22 12:19:48 +00:00
|
|
|
# Share the same pkgs instance among tests
|
|
|
|
nixpkgs.pkgs = mkDefault globalPkgs;
|
|
|
|
|
2020-09-27 10:43:20 +00:00
|
|
|
tests.bitcoind = cfg.bitcoind.enable;
|
|
|
|
services.bitcoind = {
|
|
|
|
enable = true;
|
2020-09-27 10:43:21 +00:00
|
|
|
extraConfig = mkIf config.test.noConnections "connect=0";
|
2020-09-27 10:43:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
tests.clightning = cfg.clightning.enable;
|
2020-09-28 11:09:08 +00:00
|
|
|
# When WAN is disabled, DNS bootstrapping slows down service startup by ~15 s.
|
|
|
|
services.clightning.extraConfig = mkIf config.test.noConnections "disable-dns";
|
2020-11-19 02:01:45 +00:00
|
|
|
test.data.clightning-plugins = let
|
|
|
|
plugins = config.services.clightning.plugins;
|
|
|
|
enabled = builtins.filter (plugin: plugins.${plugin}.enable) (builtins.attrNames plugins);
|
|
|
|
pluginPkgs = config.nix-bitcoin.pkgs.clightning-plugins;
|
|
|
|
in map (plugin: pluginPkgs.${plugin}.path) enabled;
|
2020-09-27 10:43:20 +00:00
|
|
|
|
|
|
|
tests.spark-wallet = cfg.spark-wallet.enable;
|
|
|
|
|
|
|
|
tests.lnd = cfg.lnd.enable;
|
2021-01-14 12:24:03 +00:00
|
|
|
services.lnd.port = 9736;
|
2020-06-18 10:22:44 +00:00
|
|
|
|
2021-02-03 21:44:43 +00:00
|
|
|
tests.lnd-rest-onion-service = cfg.lnd.restOnionService.enable;
|
|
|
|
|
2020-09-27 10:43:20 +00:00
|
|
|
tests.lightning-loop = cfg.lightning-loop.enable;
|
2020-01-12 19:52:40 +00:00
|
|
|
|
2021-03-01 09:59:23 +00:00
|
|
|
tests.lightning-pool = cfg.lightning-pool.enable;
|
|
|
|
nix-bitcoin.onionServices.lnd.public = true;
|
|
|
|
|
2020-09-27 10:43:20 +00:00
|
|
|
tests.electrs = cfg.electrs.enable;
|
2020-01-12 19:52:40 +00:00
|
|
|
|
2020-09-27 10:43:20 +00:00
|
|
|
tests.liquidd = cfg.liquidd.enable;
|
2020-09-27 10:43:21 +00:00
|
|
|
services.liquidd.extraConfig = mkIf config.test.noConnections "connect=0";
|
2020-01-12 19:52:40 +00:00
|
|
|
|
2020-09-27 10:43:20 +00:00
|
|
|
tests.btcpayserver = cfg.btcpayserver.enable;
|
|
|
|
services.btcpayserver.lightningBackend = "lnd";
|
|
|
|
# Needed to test macaroon creation
|
|
|
|
environment.systemPackages = mkIfTest "btcpayserver" (with pkgs; [ openssl xxd ]);
|
|
|
|
|
|
|
|
tests.joinmarket = cfg.joinmarket.enable;
|
2020-10-16 15:43:17 +00:00
|
|
|
tests.joinmarket-yieldgenerator = cfg.joinmarket.yieldgenerator.enable;
|
2021-01-17 12:24:57 +00:00
|
|
|
tests.joinmarket-ob-watcher = cfg.joinmarket-ob-watcher.enable;
|
2020-09-27 10:43:20 +00:00
|
|
|
services.joinmarket.yieldgenerator = {
|
|
|
|
enable = config.services.joinmarket.enable;
|
2021-02-10 14:02:05 +00:00
|
|
|
# Test a smattering of custom parameters
|
|
|
|
ordertype = "absoffer";
|
|
|
|
cjfee_a = 300;
|
|
|
|
cjfee_r = 0.00003;
|
|
|
|
txfee = 200;
|
2020-09-27 10:43:20 +00:00
|
|
|
};
|
|
|
|
|
2021-01-14 12:24:26 +00:00
|
|
|
tests.nodeinfo = config.nix-bitcoin.nodeinfo.enable;
|
|
|
|
|
2020-09-27 10:43:20 +00:00
|
|
|
tests.backups = cfg.backups.enable;
|
|
|
|
|
|
|
|
# To test that unused secrets are made inaccessible by 'setup-secrets'
|
2021-03-10 13:08:34 +00:00
|
|
|
systemd.services.setup-secrets.preStart = mkIfTest "security" ''
|
|
|
|
install -D -o nobody -g nogroup -m777 <(:) /secrets/dummy
|
2020-09-27 10:43:20 +00:00
|
|
|
'';
|
2020-11-19 02:01:45 +00:00
|
|
|
}
|
|
|
|
(mkIf config.test.features.clightningPlugins {
|
|
|
|
services.clightning.plugins = {
|
2020-12-22 09:53:39 +00:00
|
|
|
# TODO: add clboss when https://github.com/ZmnSCPxj/clboss/issues/49 is closed
|
2020-11-19 02:01:45 +00:00
|
|
|
helpme.enable = true;
|
|
|
|
monitor.enable = true;
|
|
|
|
prometheus.enable = true;
|
|
|
|
rebalance.enable = true;
|
|
|
|
summary.enable = true;
|
|
|
|
zmq = let tcpEndpoint = "tcp://127.0.0.1:5501"; in {
|
|
|
|
enable = true;
|
|
|
|
channel-opened = tcpEndpoint;
|
|
|
|
connect = tcpEndpoint;
|
|
|
|
disconnect = tcpEndpoint;
|
|
|
|
invoice-payment = tcpEndpoint;
|
|
|
|
warning = tcpEndpoint;
|
|
|
|
forward-event = tcpEndpoint;
|
|
|
|
sendpay-success = tcpEndpoint;
|
|
|
|
sendpay-failure = tcpEndpoint;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
2020-09-27 10:43:20 +00:00
|
|
|
};
|
2020-01-12 19:52:40 +00:00
|
|
|
|
2020-09-27 10:43:20 +00:00
|
|
|
scenarios = {
|
|
|
|
base = baseConfig; # Included in all scenarios
|
|
|
|
|
|
|
|
default = scenarios.secureNode;
|
|
|
|
|
|
|
|
# All available basic services and tests
|
|
|
|
full = {
|
|
|
|
tests.security = true;
|
|
|
|
|
|
|
|
services.clightning.enable = true;
|
2020-11-19 02:01:45 +00:00
|
|
|
test.features.clightningPlugins = true;
|
2020-09-27 10:43:20 +00:00
|
|
|
services.spark-wallet.enable = true;
|
|
|
|
services.lnd.enable = true;
|
2021-02-03 21:44:43 +00:00
|
|
|
services.lnd.restOnionService.enable = true;
|
2020-09-27 10:43:20 +00:00
|
|
|
services.lightning-loop.enable = true;
|
2021-03-01 09:59:23 +00:00
|
|
|
services.lightning-pool.enable = true;
|
2020-09-27 10:43:20 +00:00
|
|
|
services.electrs.enable = true;
|
|
|
|
services.liquidd.enable = true;
|
|
|
|
services.btcpayserver.enable = true;
|
|
|
|
services.joinmarket.enable = true;
|
2021-01-17 12:24:57 +00:00
|
|
|
services.joinmarket-ob-watcher.enable = true;
|
2020-09-27 10:43:20 +00:00
|
|
|
services.backups.enable = true;
|
|
|
|
|
2021-01-14 12:24:26 +00:00
|
|
|
nix-bitcoin.nodeinfo.enable = true;
|
|
|
|
|
2020-09-27 10:43:20 +00:00
|
|
|
services.hardware-wallets = {
|
|
|
|
trezor = true;
|
|
|
|
ledger = true;
|
|
|
|
};
|
2020-01-12 19:52:40 +00:00
|
|
|
};
|
|
|
|
|
2020-09-27 10:43:20 +00:00
|
|
|
secureNode = {
|
|
|
|
imports = [
|
|
|
|
scenarios.full
|
|
|
|
../modules/presets/secure-node.nix
|
|
|
|
];
|
|
|
|
tests.secure-node = true;
|
|
|
|
tests.banlist-and-restart = true;
|
2020-10-16 15:43:18 +00:00
|
|
|
|
|
|
|
# Stop electrs from spamming the test log with 'WARN - wait until IBD is over' messages
|
|
|
|
tests.stop-electrs = true;
|
2020-09-27 10:43:20 +00:00
|
|
|
};
|
2020-01-12 19:52:40 +00:00
|
|
|
|
2020-09-27 10:43:20 +00:00
|
|
|
netns = {
|
2020-10-29 20:20:28 +00:00
|
|
|
imports = with scenarios; [ netnsBase secureNode ];
|
2020-09-27 10:43:29 +00:00
|
|
|
# This test is rather slow and unaffected by netns settings
|
|
|
|
tests.backups = mkForce false;
|
2020-01-12 19:52:40 +00:00
|
|
|
};
|
|
|
|
|
2020-10-16 15:43:19 +00:00
|
|
|
# All regtest-enabled services
|
|
|
|
regtest = {
|
|
|
|
imports = [ scenarios.regtestBase ];
|
|
|
|
services.clightning.enable = true;
|
2020-11-19 02:01:45 +00:00
|
|
|
test.features.clightningPlugins = true;
|
2020-10-16 15:43:19 +00:00
|
|
|
services.spark-wallet.enable = true;
|
|
|
|
services.lnd.enable = true;
|
|
|
|
services.lightning-loop.enable = true;
|
2021-03-01 09:59:23 +00:00
|
|
|
services.lightning-pool.enable = true;
|
2020-10-16 15:43:19 +00:00
|
|
|
services.electrs.enable = true;
|
|
|
|
services.btcpayserver.enable = true;
|
|
|
|
services.joinmarket.enable = true;
|
|
|
|
};
|
|
|
|
|
2020-10-29 20:20:28 +00:00
|
|
|
# netns and regtest, without secure-node.nix
|
|
|
|
netnsRegtest = {
|
|
|
|
imports = with scenarios; [ netnsBase regtest ];
|
|
|
|
};
|
|
|
|
|
2020-12-18 12:27:20 +00:00
|
|
|
hardened = {
|
|
|
|
imports = [
|
|
|
|
scenarios.secureNode
|
|
|
|
../modules/presets/hardened.nix
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2021-03-22 12:19:48 +00:00
|
|
|
netnsBase = { config, pkgs, ... }: {
|
2020-10-29 20:20:28 +00:00
|
|
|
nix-bitcoin.netns-isolation.enable = true;
|
|
|
|
test.data.netns = config.nix-bitcoin.netns-isolation.netns;
|
|
|
|
tests.netns-isolation = true;
|
|
|
|
environment.systemPackages = [ pkgs.fping ];
|
|
|
|
};
|
|
|
|
|
2021-03-22 12:19:48 +00:00
|
|
|
regtestBase = { config, ... }: {
|
2020-10-16 15:43:19 +00:00
|
|
|
tests.regtest = true;
|
|
|
|
|
|
|
|
services.bitcoind.regtest = true;
|
|
|
|
systemd.services.bitcoind.postStart = mkAfter ''
|
2020-10-29 20:20:29 +00:00
|
|
|
cli=${config.services.bitcoind.cli}/bin/bitcoin-cli
|
2021-01-30 09:47:03 +00:00
|
|
|
$cli createwallet "test"
|
2020-10-16 15:43:19 +00:00
|
|
|
address=$($cli getnewaddress)
|
|
|
|
$cli generatetoaddress 10 $address
|
|
|
|
'';
|
|
|
|
|
|
|
|
# lightning-loop contains no builtin swap server for regtest.
|
|
|
|
# Add a dummy definition.
|
|
|
|
services.lightning-loop.extraConfig = ''
|
|
|
|
server.host=localhost
|
|
|
|
'';
|
|
|
|
|
2021-03-01 09:59:23 +00:00
|
|
|
# lightning-pool contains no builtin auction server for regtest.
|
|
|
|
# Add a dummy definition
|
|
|
|
services.lightning-pool.extraConfig = ''
|
|
|
|
auctionserver=localhost
|
|
|
|
'';
|
|
|
|
|
2020-10-16 15:43:19 +00:00
|
|
|
# Needs wallet support which is unavailable for regtest
|
|
|
|
services.joinmarket.yieldgenerator.enable = mkForce false;
|
|
|
|
};
|
|
|
|
|
2020-09-27 10:43:20 +00:00
|
|
|
## Examples / debug helper
|
|
|
|
|
|
|
|
# Run a selection of tests in scenario 'netns'
|
|
|
|
selectedTests = {
|
|
|
|
imports = [ scenarios.netns ];
|
|
|
|
tests = mkForce {
|
|
|
|
btcpayserver = true;
|
|
|
|
netns-isolation = true;
|
|
|
|
};
|
2020-05-18 09:51:18 +00:00
|
|
|
};
|
2020-08-12 14:16:22 +00:00
|
|
|
|
2020-09-27 10:43:28 +00:00
|
|
|
# Container-specific features
|
|
|
|
containerFeatures = {
|
|
|
|
# Container has WAN access and bitcoind connects to external nodes
|
|
|
|
test.container.enableWAN = true;
|
|
|
|
# See ./lib/test-lib.nix for a description
|
|
|
|
test.container.exposeLocalhost = true;
|
|
|
|
};
|
|
|
|
|
2020-09-27 10:43:20 +00:00
|
|
|
adhoc = {
|
|
|
|
# <Add your config here>
|
|
|
|
# You can also set the env var `scenarioOverridesFile` (used below) to define custom scenarios.
|
|
|
|
};
|
2020-01-12 19:52:40 +00:00
|
|
|
};
|
2021-03-22 12:19:48 +00:00
|
|
|
|
|
|
|
overrides = builtins.getEnv "scenarioOverridesFile";
|
|
|
|
extraScenarios' = (if (overrides != "") then import overrides else extraScenarios) {
|
|
|
|
inherit scenarios pkgs;
|
|
|
|
inherit (pkgs) lib;
|
|
|
|
};
|
|
|
|
allScenarios = scenarios // extraScenarios';
|
|
|
|
|
|
|
|
makeTest = name: config:
|
|
|
|
makeTest' name {
|
|
|
|
imports = [
|
|
|
|
allScenarios.base
|
|
|
|
config
|
|
|
|
];
|
2020-09-27 10:43:20 +00:00
|
|
|
};
|
2021-03-22 12:19:48 +00:00
|
|
|
makeTest' = import ./lib/make-test.nix pkgs;
|
|
|
|
|
|
|
|
tests = builtins.mapAttrs makeTest allScenarios;
|
|
|
|
|
|
|
|
getTest = name: tests.${name} or (makeTest name {
|
|
|
|
services.${name}.enable = true;
|
|
|
|
});
|
|
|
|
in
|
|
|
|
tests // {
|
|
|
|
inherit getTest;
|
2020-09-27 10:43:20 +00:00
|
|
|
}
|