Files
allmende/nix/test.nix
T
nilsandClaude Sonnet 5.5 e7bec4fb63 Add bootstrap nodes, DNS-based discovery, a DHT per region and NAT traversal
- Bootstrap: built-in /dnsaddr/allmende.stinnesbeck.com (TXT records at
  _dnsaddr.<name>), resolved at every redial with the last good answer kept;
  --bootstrap takes /p2p/ or /dnsaddr/ entries, --no-default-bootstrap drops
  the built-in one. Stopping never waits for a stuck resolver.
- Remembered peers in peers.json (saved every 5 min and on shutdown, redialled
  at the next start)
- Private Kademlia DHT (/allmende prefix), advertised and looked up per region
  with quick first attempts and a backoff; --no-dht turns it off
- NAT traversal: port mapping, hole punching, AutoRelay through bootstrap nodes
- --public: DHT server and relay for a bootstrap node; prints the TXT records
- Docker, NixOS module (public, defaultBootstrap, QUIC/UDP) and docs updated
- e2e: bootstrap node scenario, seed cache restart, and polling that really polls

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

56 lines
2.3 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 stops promptly even though the VM has no DNS, and restarts"):
# The built-in bootstrap name cannot be resolved here; stopping must not wait for it.
machine.succeed("timeout 3 systemctl stop allmende")
machine.succeed("systemctl start allmende")
machine.wait_for_open_port(8080)
'';
}