|
| 1 | +{ |
| 2 | + pkgs, |
| 3 | + cardano-node-linux, |
| 4 | + ... |
| 5 | +}: let |
| 6 | + inherit (builtins) attrNames fromJSON readFile toString; |
| 7 | + inherit (cardanoLib) environments; |
| 8 | + inherit (cardanoNodePackages) cardano-cli; |
| 9 | + inherit (lib) getAttrs getExe foldl' makeBinPath recursiveUpdate; |
| 10 | + inherit (pkgs) cardanoLib cardanoNodePackages gnutar gzip jq lib; |
| 11 | + |
| 12 | + # NixosTest script fns supporting a timeout have a default of 900 seconds. |
| 13 | + timeout = toString 30; |
| 14 | + |
| 15 | + environments' = getAttrs ["mainnet" "preprod" "preview"] environments; |
| 16 | + envs = attrNames environments'; |
| 17 | + getMagic = env: toString (fromJSON (readFile environments.${env}.nodeConfig.ShelleyGenesisFile)).networkMagic; |
| 18 | + |
| 19 | + mkSvcTest = env: { |
| 20 | + "cardano-node-${env}" = { |
| 21 | + serviceConfig = { |
| 22 | + WorkingDirectory = "/var/lib/cardano-node-${env}"; |
| 23 | + StateDirectory = "cardano-node-${env}"; |
| 24 | + }; |
| 25 | + |
| 26 | + preStart = '' |
| 27 | + mkdir config |
| 28 | + cp -v /opt/cardano-node-linux/share/${env}/* ./ |
| 29 | + ''; |
| 30 | + |
| 31 | + script = '' |
| 32 | + /opt/cardano-node-linux/bin/cardano-node run \ |
| 33 | + --config config.json \ |
| 34 | + --topology topology.json \ |
| 35 | + --database-path db \ |
| 36 | + --socket-path node.socket \ |
| 37 | + --port 3001 |
| 38 | + ''; |
| 39 | + }; |
| 40 | + }; |
| 41 | + |
| 42 | + mkScriptTest = env: '' |
| 43 | + machine.systemctl("start cardano-node-${env}") |
| 44 | + machine.wait_until_succeeds("[ -S /var/lib/cardano-node-${env}/node.socket ]", timeout=${timeout}) |
| 45 | + machine.wait_until_succeeds("nc -z localhost 12798", timeout=${timeout}) |
| 46 | + machine.wait_until_succeeds("nc -z localhost 3001", timeout=${timeout}) |
| 47 | + out = machine.succeed( |
| 48 | + "${getExe cardano-cli} ping -h 127.0.0.1 -c 1 -m ${getMagic env} -q --json | ${getExe jq} -c" |
| 49 | + ) |
| 50 | + print("ping ${env}:", out) |
| 51 | + machine.succeed("systemctl status cardano-node-${env}") |
| 52 | + machine.succeed("systemctl stop cardano-node-${env}") |
| 53 | + machine.wait_until_fails("nc -z localhost 12798", timeout=${timeout}) |
| 54 | + machine.wait_until_fails("nc -z localhost 3001", timeout=${timeout}) |
| 55 | + ''; |
| 56 | +in { |
| 57 | + name = "cardano-node-artifact-test"; |
| 58 | + nodes = { |
| 59 | + machine = {config, ...}: { |
| 60 | + nixpkgs.pkgs = pkgs; |
| 61 | + |
| 62 | + system.activationScripts.prepTest.text = let |
| 63 | + binPath = makeBinPath [gnutar gzip]; |
| 64 | + in '' |
| 65 | + export PATH=${binPath}:$PATH |
| 66 | + mkdir -p /opt/cardano-node-linux |
| 67 | + cp -v ${cardano-node-linux}/cardano-node-*-linux.tar.gz /opt/cardano-node-linux.tar.gz |
| 68 | + tar -zxvf /opt/cardano-node-linux.tar.gz -C /opt/cardano-node-linux |
| 69 | + ''; |
| 70 | + |
| 71 | + systemd.services = foldl' (acc: env: recursiveUpdate acc (mkSvcTest env)) {} envs; |
| 72 | + }; |
| 73 | + }; |
| 74 | + |
| 75 | + testScript = |
| 76 | + '' |
| 77 | + start_all() |
| 78 | + '' |
| 79 | + + lib.concatMapStringsSep "\n" mkScriptTest envs; |
| 80 | +} |
0 commit comments