From 8a5929314558e83a79b2b16305a79333b49093e3 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 29 Sep 2023 15:27:59 +0800 Subject: [PATCH] test(prover): update tests --- prover/server/api_test.go | 20 ++++++++++---------- prover/server/server_test.go | 18 +++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/prover/server/api_test.go b/prover/server/api_test.go index 785bbea85..29bb3cbe8 100644 --- a/prover/server/api_test.go +++ b/prover/server/api_test.go @@ -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)) } @@ -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") } diff --git a/prover/server/server_test.go b/prover/server/server_test.go index 74a513faa..e992e91b5 100644 --- a/prover/server/server_test.go +++ b/prover/server/server_test.go @@ -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() { @@ -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() { @@ -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) } }() @@ -99,11 +99,11 @@ 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) { @@ -111,7 +111,7 @@ func TestProverServerTestSuite(t *testing.T) { } 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 }