add very simple test

pull/97/head
Minh Doan 6 years ago committed by Minh Doan
parent 0fcc95d695
commit 7e575ba4f1
  1. 6
      syncing/downloader/client/client.go
  2. 8
      syncing/downloader/server/server.go
  3. 32
      syncing/downloader/server_test.go

@ -1,4 +1,4 @@
package main package downloader
import ( import (
"context" "context"
@ -49,7 +49,7 @@ func (client *Client) Close() {
} }
// GetHeaders ... // GetHeaders ...
func (client *Client) GetHeaders() { func (client *Client) GetHeaders() []byte {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()
request := &pb.DownloaderRequest{Type: pb.DownloaderRequest_HEADER} request := &pb.DownloaderRequest{Type: pb.DownloaderRequest_HEADER}
@ -57,7 +57,7 @@ func (client *Client) GetHeaders() {
if err != nil { if err != nil {
log.Fatalf("Error") log.Fatalf("Error")
} }
log.Println(response) return response.Payload[0]
} }
func main() { func main() {

@ -1,4 +1,4 @@
package main package downloader
import ( import (
"context" "context"
@ -25,7 +25,7 @@ func (s *Server) Query(ctx context.Context, request *pb.DownloaderRequest) (*pb.
} }
// Start ... // Start ...
func (s *Server) Start(ip, port string) error { func (s *Server) Start(ip, port string) (*grpc.Server, error) {
// if s.node == nil { // if s.node == nil {
// return ErrDownloaderWithNoNode // return ErrDownloaderWithNoNode
// } // }
@ -36,8 +36,8 @@ func (s *Server) Start(ip, port string) error {
var opts []grpc.ServerOption var opts []grpc.ServerOption
grpcServer := grpc.NewServer(opts...) grpcServer := grpc.NewServer(opts...)
pb.RegisterDownloaderServer(grpcServer, s) pb.RegisterDownloaderServer(grpcServer, s)
grpcServer.Serve(lis) go grpcServer.Serve(lis)
return nil return grpcServer, nil
} }
// NewServer ... // NewServer ...

@ -1,12 +1,11 @@
package downloader package downloader
import ( import (
"fmt"
"testing" "testing"
"github.com/harmony-one/harmony/blockchain"
"github.com/harmony-one/harmony/crypto/pki" "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 ( const (
@ -22,19 +21,20 @@ var (
TestAddressTwo = pki.GetAddressFromInt(PriIntTwo) 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) { func TestGetBlockHashes(t *testing.T) {
server := setupServer() s := server.NewServer(nil)
server.Start(serverIP) 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) defer client.Close()
// client.GetHeaders() client.GetHeaders()
} }

Loading…
Cancel
Save