From 7cf6d40ad61ba4c6a8d6c3af22daecd3f9b92003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Mon, 18 Nov 2024 16:13:22 +0100 Subject: [PATCH] chore: fix linter errors --- cmd/dummy/main.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++ test/dummy.go | 1 + 2 files changed, 60 insertions(+) create mode 100644 cmd/dummy/main.go diff --git a/cmd/dummy/main.go b/cmd/dummy/main.go new file mode 100644 index 0000000..e218223 --- /dev/null +++ b/cmd/dummy/main.go @@ -0,0 +1,59 @@ +package main + +import ( + "errors" + "log" + "net" + "os" + "sync" + "time" + + "google.golang.org/grpc" + + grpcproxy "github.com/rollkit/go-execution/proxy/grpc" + "github.com/rollkit/go-execution/test" + pb "github.com/rollkit/go-execution/types/pb/execution" +) + +const bufSize = 1024 * 1024 + +func main() { + dummy := test.NewDummyExecutor() + config := &grpcproxy.Config{ + DefaultTimeout: 5 * time.Second, + MaxRequestSize: bufSize, + } + + listenAddress := "127.0.0.1:40041" + if len(os.Args) == 2 { + listenAddress = os.Args[1] + } + + listener, err := net.Listen("tcp4", listenAddress) + if err != nil { + log.Fatalf("error while creating listener: %v\n", err) + } + defer func() { + _ = listener.Close() + }() + + log.Println("Starting server...") + server := grpcproxy.NewServer(dummy, config) + s := grpc.NewServer() + pb.RegisterExecutionServiceServer(s, server) + + wg := sync.WaitGroup{} + wg.Add(1) + + go func() { + log.Println("Serving...") + if err := s.Serve(listener); err != nil && !errors.Is(err, grpc.ErrServerStopped) { + log.Fatalf("Server exited with error: %v\n", err) + } + wg.Done() + }() + defer s.Stop() + + wg.Wait() + log.Println("Server stopped") +} diff --git a/test/dummy.go b/test/dummy.go index 2a52bed..f978cee 100644 --- a/test/dummy.go +++ b/test/dummy.go @@ -41,6 +41,7 @@ func (e *DummyExecutor) GetTxs(context.Context) ([]types.Tx, error) { return txs, nil } +// InjectTx adds a transaction to the internal list of injected transactions in the DummyExecutor instance. func (e *DummyExecutor) InjectTx(tx types.Tx) { e.injectedTxs = append(e.injectedTxs, tx) }