Skip to content

Commit

Permalink
feat(HTTP): Integrate AddRowDouble and update tests (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
izikdepth authored Jan 10, 2024
1 parent 24be352 commit eab6bb3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion state/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,5 @@ func (m *MockState) PublicKey(addr crypto.Address) (crypto.PublicKey, error) {
}

func (m *MockState) AvailabilityScore(_ int32) float64 {
return 1.0
return 0.987
}
2 changes: 1 addition & 1 deletion www/http/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (s *Server) writeValidatorTable(val *pactus.ValidatorInfo) *tableMaker {
tm.addRowInt("LastBondingHeight", int(val.LastBondingHeight))
tm.addRowInt("LastSortitionHeight", int(val.LastSortitionHeight))
tm.addRowInt("UnbondingHeight", int(val.UnbondingHeight))
tm.addRowInt("AvailabilityScore", int(val.AvailabilityScore))
tm.addRowDouble("AvailabilityScore", val.AvailabilityScore)
tm.addRowBytes("Hash", val.Hash)

return tm
Expand Down
22 changes: 12 additions & 10 deletions www/http/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,6 @@ func TestValidator(t *testing.T) {

val := td.mockState.TestStore.AddTestValidator()

t.Run("Shall return a validator", func(t *testing.T) {
w := httptest.NewRecorder()
r := new(http.Request)
r = mux.SetURLVars(r, map[string]string{"address": val.Address().String()})
td.httpServer.GetValidatorHandler(w, r)

assert.Equal(t, w.Code, 200)
fmt.Println(w.Body)
})

t.Run("Shall return an error, non exist", func(t *testing.T) {
w := httptest.NewRecorder()
r := new(http.Request)
Expand Down Expand Up @@ -205,6 +195,18 @@ func TestValidator(t *testing.T) {
assert.Equal(t, w.Code, 400)
fmt.Println(w.Body)
})

t.Run("Shall return a validator", func(t *testing.T) {
w := httptest.NewRecorder()
r := new(http.Request)
r = mux.SetURLVars(r, map[string]string{"address": val.Address().String()})

td.httpServer.GetValidatorHandler(w, r)

assert.Equal(t, w.Code, 200)
assert.Contains(t, w.Body.String(), "0.987")
fmt.Println(w.Body)
})
}

func TestValidatorByNumber(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions www/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ func (t *tableMaker) addRowBytes(key string, val []byte) {
fmt.Fprintf(t.w, "<tr><td>%s</td><td>%x</td></tr>", key, val)
}

func (t *tableMaker) addRowDouble(key string, val float64) {
fmt.Fprintf(t.w, "<tr><td>%s</td><td>%f</td></tr>", key, val)
}

func (t *tableMaker) html() string {
t.w.WriteString("</table>")
return t.w.String()
Expand Down

0 comments on commit eab6bb3

Please sign in to comment.