diff --git a/da/celestia/mock/server.go b/da/celestia/mock/server.go index 6bc088d6619..94ab2081111 100644 --- a/da/celestia/mock/server.go +++ b/da/celestia/mock/server.go @@ -84,7 +84,7 @@ func (s *Server) Start(listener net.Listener) error { } go func() { s.server = new(http.Server) - s.server.Handler = s.getHandler() + s.server.Handler = s.Handler() err := s.server.Serve(listener) s.logger.Debug("http server exited with", "error", err) }() @@ -98,7 +98,7 @@ func (s *Server) Stop() { _ = s.server.Shutdown(ctx) } -func (s *Server) getHandler() http.Handler { +func (s *Server) Handler() http.Handler { mux := mux2.NewRouter() mux.HandleFunc("/", s.rpc).Methods(http.MethodPost) diff --git a/da/test/da_test.go b/da/test/da_test.go index 34fac350fef..b61a48c8fa5 100644 --- a/da/test/da_test.go +++ b/da/test/da_test.go @@ -6,6 +6,7 @@ import ( "fmt" "math/rand" "net" + "net/http/httptest" "os" "strconv" "testing" @@ -119,12 +120,9 @@ func startMockGRPCServ() *grpc.Server { func startMockCelestiaNodeServer() *cmock.Server { httpSrv := cmock.NewServer(mockDaBlockTime, cmlog.NewTMLogger(os.Stdout)) - l, err := net.Listen("tcp4", "127.0.0.1:26658") - if err != nil { - fmt.Println("failed to create listener for mock celestia-node RPC server, error: %w", err) - return nil - } - err = httpSrv.Start(l) + ts := httptest.NewServer(httpSrv.Handler()) + testConfig.BaseURL = ts.URL + err := httpSrv.Start(ts.Listener) if err != nil { fmt.Println("can't start mock celestia-node RPC server") return nil