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 (
"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() {

@ -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 ...

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

Loading…
Cancel
Save