diff --git a/syncing/downloader/client/client.go b/syncing/downloader/client/client.go index d2f06d75a..61b1c7730 100644 --- a/syncing/downloader/client/client.go +++ b/syncing/downloader/client/client.go @@ -1,4 +1,4 @@ -package main +package downloader import ( "context" @@ -49,7 +49,7 @@ func (client *Client) Close() { } // GetHeaders ... -func (client *Client) GetHeaders() { +func (client *Client) GetHeaders() []byte { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() request := &pb.DownloaderRequest{Type: pb.DownloaderRequest_HEADER} @@ -57,7 +57,7 @@ func (client *Client) GetHeaders() { if err != nil { log.Fatalf("Error") } - log.Println(response) + return response.Payload[0] } func main() { diff --git a/syncing/downloader/server/server.go b/syncing/downloader/server/server.go index f788b8f26..dc139af13 100644 --- a/syncing/downloader/server/server.go +++ b/syncing/downloader/server/server.go @@ -1,4 +1,4 @@ -package main +package downloader import ( "context" @@ -25,7 +25,7 @@ func (s *Server) Query(ctx context.Context, request *pb.DownloaderRequest) (*pb. } // Start ... -func (s *Server) Start(ip, port string) error { +func (s *Server) Start(ip, port string) (*grpc.Server, error) { // if s.node == nil { // return ErrDownloaderWithNoNode // } @@ -36,8 +36,8 @@ func (s *Server) Start(ip, port string) error { var opts []grpc.ServerOption grpcServer := grpc.NewServer(opts...) pb.RegisterDownloaderServer(grpcServer, s) - grpcServer.Serve(lis) - return nil + go grpcServer.Serve(lis) + return grpcServer, nil } // NewServer ... diff --git a/syncing/downloader/server_test.go b/syncing/downloader/server_test.go index 1af1509a7..83a74ae5b 100644 --- a/syncing/downloader/server_test.go +++ b/syncing/downloader/server_test.go @@ -1,12 +1,11 @@ package downloader import ( - "fmt" "testing" - "github.com/harmony-one/harmony/blockchain" "github.com/harmony-one/harmony/crypto/pki" - "github.com/harmony-one/harmony/node" + client "github.com/harmony-one/harmony/syncing/downloader/client" + server "github.com/harmony-one/harmony/syncing/downloader/server" ) const ( @@ -22,19 +21,20 @@ var ( TestAddressTwo = pki.GetAddressFromInt(PriIntTwo) ) -func setupServer() *Server { - bc := blockchain.CreateBlockchainWithMoreBlocks([][20]byte{TestAddressOne, TestAddressTwo}, 0) - node := &node.Node{} - node.SetBlockchain(bc) - server := NewServer(node) - fmt.Println("minh ", len(bc.Blocks)) - return server -} - func TestGetBlockHashes(t *testing.T) { - server := setupServer() - server.Start(serverIP) + s := server.NewServer(nil) + grcpServer, err := s.Start(serverIP, serverPort) + if err != nil { + t.Error(err) + } + defer grcpServer.Stop() + + client := client.ClientSetup(serverIP, serverPort) + payload := client.GetHeaders() + if payload[2] != 2 { + t.Error("minh") + } - // client := ClientSetUp(serverIP, serverPort) - // client.GetHeaders() + defer client.Close() + client.GetHeaders() }