"""Eligibility: one person, one vote — and only active citizens vote (Article 2).""" from __future__ import annotations from tests.helpers import citizen_id, eligible_voters, generate_keypair, load_registry, write_registry def _registry_with_statuses(tmp_path): citizens = [] for name, status in [ ("alice", "active"), ("bob", "active"), ("carol", "active"), ("mallory", "suspended"), ("trent", "exited"), ]: _, public_key = generate_keypair() citizens.append( { "id": f"cit-{name}", "name": name.capitalize(), "public_key": public_key, "status": status, "joined": "2025-01-01", } ) path = write_registry(tmp_path / "citizens" / "registry.yaml", citizens) return path, citizens def test_registry_loads(tmp_path): path, citizens = _registry_with_statuses(tmp_path) registry = load_registry(path) assert registry is not None def test_only_active_citizens_are_eligible(tmp_path): path, citizens = _registry_with_statuses(tmp_path) registry = load_registry(path) voters = eligible_voters(registry, path) ids = {citizen_id(v) for v in voters} assert ids == {"cit-alice", "cit-bob", "cit-carol"} def test_suspended_and_exited_are_excluded(tmp_path): path, _ = _registry_with_statuses(tmp_path) registry = load_registry(path) ids = {citizen_id(v) for v in eligible_voters(registry, path)} assert "cit-mallory" not in ids assert "cit-trent" not in ids def test_empty_registry_means_no_voters(tmp_path): path = write_registry(tmp_path / "citizens" / "registry.yaml", []) registry = load_registry(path) assert list(eligible_voters(registry, path)) == [] def test_eligibility_is_per_person_not_per_key(tmp_path): """Two citizens sharing one public key must still count as two ids — eligibility is per person; signature checks catch impersonation later.""" _, shared_key = generate_keypair() citizens = [ {"id": "cit-a", "name": "A", "public_key": shared_key, "status": "active", "joined": "2025-01-01"}, {"id": "cit-b", "name": "B", "public_key": shared_key, "status": "active", "joined": "2025-01-01"}, ] path = write_registry(tmp_path / "citizens" / "registry.yaml", citizens) registry = load_registry(path) ids = {citizen_id(v) for v in eligible_voters(registry, path)} assert ids == {"cit-a", "cit-b"}