Browse Source

address pr comments

pull/3993/head
Marko Baricevic 5 years ago
parent
commit
4f5faa5f31
No known key found for this signature in database GPG Key ID: 1C1A5B44A0E4674D
4 changed files with 10 additions and 20 deletions
  1. +5
    -1
      p2p/switch_test.go
  2. +3
    -19
      rpc/core/consensus.go
  3. +1
    -0
      rpc/lib/client/ws_client.go
  4. +1
    -0
      rpc/lib/server/handlers_test.go

+ 5
- 1
p2p/switch_test.go View File

@ -352,7 +352,11 @@ func TestSwitchStopPeerForError(t *testing.T) {
defer s.Close()
scrapeMetrics := func() string {
resp, _ := http.Get(s.URL)
resp, err := http.Get(s.URL)
if err != nil {
t.Errorf("error on GET request: %v", err)
}
defer resp.Body.Close()
buf, _ := ioutil.ReadAll(resp.Body)
return string(buf)
}


+ 3
- 19
rpc/core/consensus.go View File

@ -70,13 +70,6 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ct
if err != nil {
return nil, err
}
// page & perPage === 0 then all validators are returned, no pagination
if page == 0 && perPage == 0 {
return &ctypes.ResultValidators{
BlockHeight: height,
Validators: validators.Validators,
}, nil
}
totalCount := len(validators.Validators)
perPage = validatePerPage(perPage)
@ -84,23 +77,14 @@ func Validators(ctx *rpctypes.Context, heightPtr *int64, page, perPage int) (*ct
if err != nil {
return nil, err
}
skipCount := validateSkipCount(page, perPage)
apiResults := make([]*types.Validator, cmn.MinInt(perPage, totalCount-skipCount))
for i := 0; i < len(apiResults); i++ {
v := validators.Validators[skipCount+i]
skipCount := validateSkipCount(page, perPage)
apiResults[i] = &types.Validator{
Address: v.Address,
PubKey: v.PubKey,
VotingPower: v.VotingPower,
ProposerPriority: v.ProposerPriority,
}
}
v := validators.Validators[skipCount : skipCount+cmn.MinInt(perPage, totalCount-skipCount)]
return &ctypes.ResultValidators{
BlockHeight: height,
Validators: apiResults}, nil
Validators: v}, nil
}
// DumpConsensusState dumps consensus state.


+ 1
- 0
rpc/lib/client/ws_client.go View File

@ -253,6 +253,7 @@ func (c *WSClient) dial() error {
}
rHeader := http.Header{}
conn, _, err := dialer.Dial(c.protocol+"://"+c.Address+c.Endpoint, rHeader)
defer conn.Close()
if err != nil {
return err
}


+ 1
- 0
rpc/lib/server/handlers_test.go View File

@ -70,6 +70,7 @@ func TestRPCParams(t *testing.T) {
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, req)
res := rec.Result()
defer res.Body.Close()
// Always expecting back a JSONRPCResponse
assert.True(t, statusOK(res.StatusCode), "#%d: should always return 2XX", i)
blob, err := ioutil.ReadAll(res.Body)


Loading…
Cancel
Save