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) }