removed /latest endpoints and checks

This commit is contained in:
Fabian
2018-03-17 22:14:19 +01:00
committed by Ethan Buchman
parent abfa409d37
commit e8e1e2899b
4 changed files with 40 additions and 30 deletions
+26 -16
View File
@@ -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)
}
+6 -6
View File
@@ -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)
+2 -2
View File
@@ -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")
}
+6 -6
View File
@@ -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)