2020-08-13 20:27:42 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
2023-10-23 15:49:28 +00:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
2020-08-13 20:27:42 +00:00
|
|
|
)
|
|
|
|
|
2023-10-23 15:49:28 +00:00
|
|
|
func TestServer_InitializeRoutes(t *testing.T) {
|
|
|
|
s := Server{
|
|
|
|
router: mux.NewRouter(),
|
|
|
|
}
|
|
|
|
err := s.InitializeRoutes()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
wantRouteList := map[string][]string{
|
2023-11-02 15:51:21 +00:00
|
|
|
"/eth/v1/keystores": {http.MethodGet, http.MethodPost, http.MethodDelete},
|
|
|
|
"/eth/v1/remotekeys": {http.MethodGet, http.MethodPost, http.MethodDelete},
|
|
|
|
"/eth/v1/validator/{pubkey}/gas_limit": {http.MethodGet, http.MethodPost, http.MethodDelete},
|
|
|
|
"/eth/v1/validator/{pubkey}/feerecipient": {http.MethodGet, http.MethodPost, http.MethodDelete},
|
|
|
|
"/eth/v1/validator/{pubkey}/voluntary_exit": {http.MethodPost},
|
|
|
|
"/v2/validator/health/version": {http.MethodGet},
|
|
|
|
"/v2/validator/health/logs/validator/stream": {http.MethodGet},
|
|
|
|
"/v2/validator/health/logs/beacon/stream": {http.MethodGet},
|
2023-11-15 19:40:14 +00:00
|
|
|
"/v2/validator/wallet": {http.MethodGet},
|
|
|
|
"/v2/validator/wallet/create": {http.MethodPost},
|
|
|
|
"/v2/validator/wallet/keystores/validate": {http.MethodPost},
|
|
|
|
"/v2/validator/wallet/recover": {http.MethodPost},
|
2023-11-15 17:35:22 +00:00
|
|
|
"/v2/validator/slashing-protection/export": {http.MethodGet},
|
|
|
|
"/v2/validator/slashing-protection/import": {http.MethodPost},
|
2023-12-01 20:40:09 +00:00
|
|
|
"/v2/validator/accounts": {http.MethodGet},
|
|
|
|
"/v2/validator/accounts/backup": {http.MethodPost},
|
|
|
|
"/v2/validator/accounts/voluntary-exit": {http.MethodPost},
|
|
|
|
"/v2/validator/beacon/balances": {http.MethodGet},
|
|
|
|
"/v2/validator/beacon/peers": {http.MethodGet},
|
|
|
|
"/v2/validator/beacon/status": {http.MethodGet},
|
|
|
|
"/v2/validator/beacon/summary": {http.MethodGet},
|
|
|
|
"/v2/validator/beacon/validators": {http.MethodGet},
|
|
|
|
"/v2/validator/initialize": {http.MethodGet},
|
2023-10-23 15:49:28 +00:00
|
|
|
}
|
|
|
|
gotRouteList := make(map[string][]string)
|
|
|
|
err = s.router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
|
|
|
|
tpl, err1 := route.GetPathTemplate()
|
|
|
|
require.NoError(t, err1)
|
|
|
|
met, err2 := route.GetMethods()
|
|
|
|
require.NoError(t, err2)
|
|
|
|
methods, ok := gotRouteList[tpl]
|
|
|
|
if !ok {
|
|
|
|
gotRouteList[tpl] = []string{met[0]}
|
|
|
|
} else {
|
|
|
|
gotRouteList[tpl] = append(methods, met[0])
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.DeepEqual(t, wantRouteList, gotRouteList)
|
|
|
|
}
|