Files
allmende/nix/test.nix
T
nilsandClaude Sonnet 5.5 20ea9b32f7 Add e2e script to the repo, Dockerfile, and a Nix flake with a NixOS module
- scripts/e2e.sh (+ scripts/e2e/*.ts): the two-node end-to-end test, now
  self-contained and cleaning up after itself; `make e2e`, part of `make check`
- Dockerfile/.dockerignore: static Go build in a non-root alpine image, data in
  /data, defaults to region u1j; `make docker`
- flake.nix, nix/: package (buildGoModule), dev shell, NixOS module
  services.allmende (hardened systemd unit that waits for `allmende-admin init`),
  and a NixOS VM test run by `nix flake check`
- README: running a node with Docker and NixOS

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 21:21:21 +01:00

54 lines
2.1 KiB
Nix

{ pkgs, module }:
pkgs.testers.runNixOSTest {
name = "allmende";
nodes.machine = {
imports = [ module ];
services.allmende = {
enable = true;
regions = [ "u1j" ];
openFirewall = true;
};
};
testScript = ''
machine.wait_for_unit("multi-user.target")
with subtest("the service waits for setup instead of failing"):
machine.succeed("systemctl show allmende -p ActiveState | grep -q inactive")
machine.fail("systemctl is-failed allmende")
with subtest("init creates the identity, as the service's own user"):
# The VM's shell is a terminal, where init would wait for the phrase to be
# typed back; empty input makes it skip that check, as in a script.
out = machine.succeed("allmende-admin init </dev/null")
assert "recovery phrase" in out.lower(), out
machine.succeed("test $(stat -c %U /var/lib/allmende/admin.token) = allmende")
machine.succeed("test $(stat -c %a /var/lib/allmende/admin.token) = 600")
machine.fail("allmende-admin init </dev/null") # a second init must refuse
with subtest("the node starts and serves the UI and API"):
machine.succeed("systemctl start allmende")
machine.wait_for_open_port(8080)
machine.wait_for_open_port(4001)
status = machine.succeed("curl -sf http://127.0.0.1:8080/api/v1/status")
assert '"regions":["u1j"]' in status, status
machine.succeed("curl -sf http://127.0.0.1:8080/ | grep -qi '<html'")
with subtest("the owner API needs the admin token"):
machine.succeed("test $(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8080/api/v1/mine) = 401")
machine.succeed(
"curl -sf -H \"Authorization: Bearer $(cat /var/lib/allmende/admin.token)\" http://127.0.0.1:8080/api/v1/mine"
)
with subtest("the web port stays on loopback, the peer port is open"):
machine.succeed("ss -ltn | grep -q '127.0.0.1:8080'")
machine.fail("ss -ltn | grep -q '0.0.0.0:8080'")
with subtest("it survives a restart"):
machine.succeed("systemctl restart allmende")
machine.wait_for_open_port(8080)
'';
}