Files
chains/graphvm/handler_mount_test.go
T
zeekayandHanzo Dev d94a393b60 aivm, graphvm: the handler answers at its mount, it does not route
CreateHandlers returns endpoint -> handler, and the node mounts each KEY as an
exact route, then delivers the request on the path it arrived on. A handler that
dispatches on r.URL.Path therefore never matches: it is asked for
/v1/bc/<chainID>/rpc and looks for /stats.

aivm returned one ServeMux under "/rpc" carrying twelve endpoints, and graphvm
switched on r.URL.Path behind a single mount. Both were mounted correctly and
both 404'd every request, so every endpoint either VM offers was unreachable by
construction — not misconfigured, unreachable.

The chains that serve do so because their handlers are path-blind: the gorilla/rpc
servers in keyvm, quantumvm and mpcvm read only the body, and bridgevm mounts bare
HandlerFuncs. That is the whole difference, and it is the contract: one map entry
per endpoint, and the key IS the route.

The old aivm test asserted the handler map contained "/rpc" — it locked in the
broken shape and never asked whether a request could reach it. The new test asks
for each endpoint at the path the node actually mounts, which is the only question
that distinguishes the two designs.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-20 19:28:26 -07:00

36 lines
1.1 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package graphvm
import (
"context"
"net/http"
"net/http/httptest"
"testing"
)
// The node mounts each CreateHandlers key at /v1/bc/<chainID>+key and matches
// that path EXACTLY, then hands the handler the request on the path it arrived
// on. A handler that dispatches on r.URL.Path is therefore unreachable.
func TestHandlersAnswerAtTheMountedPath(t *testing.T) {
const base = "/v1/bc/24C9zm36x43T7LqcaKF1ikHxSeuQeTXnstzi5Gwh2apo18rXNE"
handlers, err := (&VM{}).CreateHandlers(context.Background())
if err != nil {
t.Fatalf("CreateHandlers: %v", err)
}
if len(handlers) == 0 {
t.Fatal("CreateHandlers returned no handlers")
}
for endpoint, h := range handlers {
rec := httptest.NewRecorder()
h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, base+endpoint, nil))
if rec.Code == http.StatusNotFound {
t.Errorf("GET %s%s: 404 — the handler dispatches on the request path instead of answering at its mount",
base, endpoint)
}
}
}