Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
test(prover): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Sep 29, 2023
1 parent 11fa6f6 commit 8a59293
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
20 changes: 10 additions & 10 deletions prover/server/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import (
)

func (s *ProverServerTestSuite) TestGetStatusSuccess() {
resp := s.sendReq("/status")
s.Equal(http.StatusOK, resp.StatusCode)
res := s.sendReq("/status")
s.Equal(http.StatusOK, res.StatusCode)

status := new(Status)

defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
defer res.Body.Close()
b, err := io.ReadAll(res.Body)
s.Nil(err)
s.Nil(json.Unmarshal(b, &status))

s.Equal(s.ps.minProofFee.Uint64(), status.MinProofFee)
s.Equal(uint64(s.ps.maxExpiry.Seconds()), status.MaxExpiry)
s.Equal(s.s.minProofFee.Uint64(), status.MinProofFee)
s.Equal(uint64(s.s.maxExpiry.Seconds()), status.MaxExpiry)
s.Greater(status.CurrentCapacity, uint64(0))
}

Expand All @@ -36,11 +36,11 @@ func (s *ProverServerTestSuite) TestProposeBlockSuccess() {
TxListHash: common.BigToHash(common.Big1),
})
s.Nil(err)
resp, err := http.Post(s.ws.URL+"/assignment", "application/json", strings.NewReader(string(data)))
res, err := http.Post(s.testServer.URL+"/assignment", "application/json", strings.NewReader(string(data)))
s.Nil(err)
s.Equal(http.StatusOK, resp.StatusCode)
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
s.Equal(http.StatusOK, res.StatusCode)
defer res.Body.Close()
b, err := io.ReadAll(res.Body)
s.Nil(err)
s.Contains(string(b), "signedPayload")
}
Expand Down
18 changes: 9 additions & 9 deletions prover/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (

type ProverServerTestSuite struct {
suite.Suite
ps *ProverServer
ws *httptest.Server // web server
s *ProverServer
testServer *httptest.Server
}

func (s *ProverServerTestSuite) SetupTest() {
Expand Down Expand Up @@ -61,8 +61,8 @@ func (s *ProverServerTestSuite) SetupTest() {
p.echo.HideBanner = true
p.configureMiddleware()
p.configureRoutes()
s.ps = p
s.ws = httptest.NewServer(p.echo)
s.s = p
s.testServer = httptest.NewServer(p.echo)
}

func (s *ProverServerTestSuite) TestHealth() {
Expand All @@ -81,7 +81,7 @@ func (s *ProverServerTestSuite) TestStartShutdown() {
s.Nil(err)

go func() {
if err := s.ps.Start(fmt.Sprintf(":%v", port)); err != nil {
if err := s.s.Start(fmt.Sprintf(":%v", port)); err != nil {
log.Error("Failed to start prover server", "error", err)
}
}()
Expand All @@ -99,19 +99,19 @@ func (s *ProverServerTestSuite) TestStartShutdown() {
return nil
}, backoff.NewExponentialBackOff()))

s.Nil(s.ps.Shutdown(context.Background()))
s.Nil(s.s.Shutdown(context.Background()))
}

func (s *ProverServerTestSuite) TearDownTest() {
s.ws.Close()
s.testServer.Close()
}

func TestProverServerTestSuite(t *testing.T) {
suite.Run(t, new(ProverServerTestSuite))
}

func (s *ProverServerTestSuite) sendReq(path string) *http.Response {
resp, err := http.Get(s.ws.URL + path)
res, err := http.Get(s.testServer.URL + path)
s.Nil(err)
return resp
return res
}

0 comments on commit 8a59293

Please sign in to comment.