2020-08-13 15:27:42 -05:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
2023-10-23 10:49:28 -05:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2024-02-14 21:46:47 -08:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
2020-08-13 15:27:42 -05:00
|
|
|
)
|
|
|
|
|
2023-10-23 10:49:28 -05: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 10:51:21 -05: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},
|
2024-03-18 10:03:08 -05:00
|
|
|
"/eth/v1/validator/{pubkey}/graffiti": {http.MethodGet, http.MethodPost, http.MethodDelete},
|
2023-11-02 10:51:21 -05:00
|
|
|
"/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 13:40:14 -06: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 11:35:22 -06:00
|
|
|
"/v2/validator/slashing-protection/export": {http.MethodGet},
|
|
|
|
"/v2/validator/slashing-protection/import": {http.MethodPost},
|
2023-12-01 14:40:09 -06: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 10:49:28 -05: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)
|
|
|
|
}
|