From e8e1e2899b40c92a3aba638e3d2d7e788ca6f437 Mon Sep 17 00:00:00 2001 From: Fabian Date: Sat, 10 Mar 2018 20:14:13 +0100 Subject: [PATCH] removed /latest endpoints and checks --- client/lcd/lcd_test.go | 42 +++++++++++++++++++++++++--------------- client/rpc/block.go | 12 ++++++------ client/rpc/root.go | 4 ++-- client/rpc/validators.go | 12 ++++++------ 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index b6948051f0..11d04f9cdb 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -150,7 +150,19 @@ func TestBlock(t *testing.T) { cdc := app.MakeCodec() r := initRouter(cdc) - res := request(t, r, "GET", "/blocks/latest", nil) + // res := request(t, r, "GET", "/blocks/latest", nil) + // require.Equal(t, http.StatusOK, res.Code, res.Body.String()) + + // var m ctypes.ResultBlock + // decoder := json.NewDecoder(res.Body) + // err := decoder.Decode(&m) + // require.Nil(t, err, "Couldn't parse block") + + // assert.NotEqual(t, ctypes.ResultBlock{}, m) + + // -- + + res := request(t, r, "GET", "/blocks/1", nil) require.Equal(t, http.StatusOK, res.Code, res.Body.String()) var m ctypes.ResultBlock @@ -162,13 +174,6 @@ func TestBlock(t *testing.T) { // -- - res = request(t, r, "GET", "/blocks/1", nil) - require.Equal(t, http.StatusOK, res.Code, res.Body.String()) - - assert.NotEqual(t, ctypes.ResultBlock{}, m) - - // -- - res = request(t, r, "GET", "/blocks/2", nil) require.Equal(t, http.StatusNotFound, res.Code, res.Body.String()) } @@ -180,7 +185,19 @@ func TestValidators(t *testing.T) { cdc := app.MakeCodec() r := initRouter(cdc) - res := request(t, r, "GET", "/validatorsets/latest", nil) + // res := request(t, r, "GET", "/validatorsets/latest", nil) + // require.Equal(t, http.StatusOK, res.Code, res.Body.String()) + + // var m ctypes.ResultValidators + // decoder := json.NewDecoder(res.Body) + // err := decoder.Decode(&m) + // require.Nil(t, err, "Couldn't parse validatorset") + + // assert.NotEqual(t, ctypes.ResultValidators{}, m) + + // -- + + res := request(t, r, "GET", "/validatorsets/1", nil) require.Equal(t, http.StatusOK, res.Code, res.Body.String()) var m ctypes.ResultValidators @@ -192,13 +209,6 @@ func TestValidators(t *testing.T) { // -- - res = request(t, r, "GET", "/validatorsets/1", nil) - require.Equal(t, http.StatusOK, res.Code, res.Body.String()) - - assert.NotEqual(t, ctypes.ResultValidators{}, m) - - // -- - res = request(t, r, "GET", "/validatorsets/2", nil) require.Equal(t, http.StatusNotFound, res.Code) } diff --git a/client/rpc/block.go b/client/rpc/block.go index 7f197051a9..12c18aa4c2 100644 --- a/client/rpc/block.go +++ b/client/rpc/block.go @@ -101,12 +101,12 @@ func BlockRequestHandler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("ERROR: Couldn't parse block height. Assumed format is '/block/{height}'.")) return } - chainHeight, err := GetChainHeight() - if height > chainHeight { - w.WriteHeader(404) - w.Write([]byte("ERROR: Requested block height is bigger then the chain length.")) - return - } + // chainHeight, err := GetChainHeight() + // if height > chainHeight { + // w.WriteHeader(404) + // w.Write([]byte("ERROR: Requested block height is bigger then the chain length.")) + // return + // } output, err := getBlock(&height) if err != nil { w.WriteHeader(500) diff --git a/client/rpc/root.go b/client/rpc/root.go index 8b04c044f4..03c964070e 100644 --- a/client/rpc/root.go +++ b/client/rpc/root.go @@ -47,8 +47,8 @@ func initClientCommand() *cobra.Command { func RegisterRoutes(r *mux.Router) { r.HandleFunc("/node_info", NodeInfoRequestHandler).Methods("GET") r.HandleFunc("/syncing", NodeSyncingRequestHandler).Methods("GET") - r.HandleFunc("/blocks/latest", LatestBlockRequestHandler).Methods("GET") + // r.HandleFunc("/blocks/latest", LatestBlockRequestHandler).Methods("GET") r.HandleFunc("/blocks/{height}", BlockRequestHandler).Methods("GET") - r.HandleFunc("/validatorsets/latest", LatestValidatorsetRequestHandler).Methods("GET") + // r.HandleFunc("/validatorsets/latest", LatestValidatorsetRequestHandler).Methods("GET") r.HandleFunc("/validatorsets/{height}", ValidatorsetRequestHandler).Methods("GET") } diff --git a/client/rpc/validators.go b/client/rpc/validators.go index 32c7680ec6..c7beeaa4e8 100644 --- a/client/rpc/validators.go +++ b/client/rpc/validators.go @@ -78,12 +78,12 @@ func ValidatorsetRequestHandler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("ERROR: Couldn't parse block height. Assumed format is '/validatorsets/{height}'.")) return } - chainHeight, err := GetChainHeight() - if height > chainHeight { - w.WriteHeader(404) - w.Write([]byte("ERROR: Requested block height is bigger then the chain length.")) - return - } + // chainHeight, err := GetChainHeight() + // if height > chainHeight { + // w.WriteHeader(404) + // w.Write([]byte("ERROR: Requested block height is bigger then the chain length.")) + // return + // } output, err := getValidators(&height) if err != nil { w.WriteHeader(500)