Fix validation failures from loose-end sweep
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled

This commit is contained in:
AetherForge
2026-06-07 01:29:54 -07:00
parent 85376eac7c
commit f27cec887a
8 changed files with 33 additions and 13 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/http/httptest"
@@ -83,13 +84,22 @@ func fleetChiRoute(method, pattern string, handler http.HandlerFunc) http.Handle
return r
}
func testAgentClientIP(agentID string) string {
var sum int
for i, c := range agentID {
sum += int(c) * (i + 1)
}
return fmt.Sprintf("10.42.%d.%d", (sum%250)+1, ((sum/250)%250)+1)
}
func connectTestAgent(t *testing.T, hub *WSHub, agentID string) *websocket.Conn {
t.Helper()
srv := httptest.NewServer(http.HandlerFunc(hub.HandleAgentWS))
t.Cleanup(srv.Close)
wsURL := "ws" + strings.TrimPrefix(srv.URL, "http")
conn, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
hdr := http.Header{"X-Forwarded-For": {testAgentClientIP(agentID)}}
conn, _, err := websocket.DefaultDialer.Dial(wsURL, hdr)
if err != nil {
t.Fatalf("dial agent ws: %v", err)
}