61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
"""US-035: tracker web dashboard — served from any tracker, embedded asset."""
|
|
|
|
import json
|
|
import urllib.request
|
|
|
|
from meshnet_contracts import LocalSolanaContracts
|
|
from meshnet_tracker.billing import BillingLedger
|
|
from meshnet_tracker.server import TrackerServer
|
|
|
|
PANELS = [
|
|
"Tracker hive", "Nodes & coverage", "Client balances",
|
|
"Node pending payouts", "Settlement history",
|
|
"Strikes / bans / forfeitures", "Model usage",
|
|
]
|
|
|
|
|
|
def test_dashboard_served_with_all_panels():
|
|
tracker = TrackerServer(billing=BillingLedger())
|
|
port = tracker.start()
|
|
try:
|
|
html = urllib.request.urlopen(
|
|
f"http://127.0.0.1:{port}/dashboard"
|
|
).read().decode()
|
|
for panel in PANELS:
|
|
assert panel in html
|
|
assert "<script>" in html # polling client embedded, no build step
|
|
finally:
|
|
tracker.stop()
|
|
|
|
|
|
def test_dashboard_served_by_follower():
|
|
"""A tracker that is not the leader (unreachable peers → never elected)
|
|
still serves the dashboard from its own replicated state."""
|
|
tracker = TrackerServer(
|
|
billing=BillingLedger(),
|
|
cluster_peers=["http://127.0.0.1:1", "http://127.0.0.1:2"],
|
|
)
|
|
port = tracker.start()
|
|
try:
|
|
response = urllib.request.urlopen(f"http://127.0.0.1:{port}/dashboard")
|
|
assert response.status == 200
|
|
assert "meshnet tracker" in response.read().decode()
|
|
finally:
|
|
tracker.stop()
|
|
|
|
|
|
def test_registry_wallets_endpoint():
|
|
contracts = LocalSolanaContracts()
|
|
contracts.registry.submit_stake("wallet-a", 100)
|
|
contracts.registry.record_strike("wallet-a")
|
|
tracker = TrackerServer(contracts=contracts)
|
|
port = tracker.start()
|
|
try:
|
|
data = json.loads(urllib.request.urlopen(
|
|
f"http://127.0.0.1:{port}/v1/registry/wallets"
|
|
).read())
|
|
assert data["wallets"]["wallet-a"]["strike_count"] == 1
|
|
assert data["wallets"]["wallet-a"]["banned"] is False
|
|
finally:
|
|
tracker.stop()
|