parent
c43378352d
commit
0d0f1fd5c9
@ -0,0 +1,48 @@ |
||||
package downloader |
||||
|
||||
import ( |
||||
"context" |
||||
"fmt" |
||||
"log" |
||||
"time" |
||||
|
||||
pb "github.com/harmony-one/harmony/syncing/downloader/proto" |
||||
"google.golang.org/grpc" |
||||
) |
||||
|
||||
// Client ...
|
||||
type Client struct { |
||||
dlClient pb.DownloaderClient |
||||
opts []grpc.DialOption |
||||
conn *grpc.ClientConn |
||||
} |
||||
|
||||
// GetHeaders ...
|
||||
func (client *Client) GetHeaders() { |
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
||||
defer cancel() |
||||
request := &pb.DownloaderRequest{Type: pb.DownloaderRequest_HEADER} |
||||
|
||||
result, err := client.dlClient.Query(ctx, request) |
||||
if err != nil { |
||||
log.Fatalf("%v.GetFeatures(_) = _, %v: ", client, err) |
||||
} |
||||
log.Println(result) |
||||
} |
||||
|
||||
// Close ...
|
||||
func (client *Client) Close() { |
||||
client.conn.Close() |
||||
} |
||||
|
||||
// ClientSetUp ...
|
||||
func ClientSetUp(ip, port string) *Client { |
||||
client := Client{} |
||||
var err error |
||||
client.conn, err = grpc.Dial(fmt.Sprintf("%s:%s", ip, port), client.opts...) |
||||
if err != nil { |
||||
log.Fatalf("fail to dial: %v", err) |
||||
} |
||||
client.dlClient = pb.NewDownloaderClient(client.conn) |
||||
return &client |
||||
} |
@ -0,0 +1,8 @@ |
||||
package downloader |
||||
|
||||
import "errors" |
||||
|
||||
// Errors ...
|
||||
var ( |
||||
ErrDownloaderWithNoNode = errors.New("no node attached") |
||||
) |
@ -0,0 +1,36 @@ |
||||
package downloader |
||||
|
||||
import ( |
||||
"testing" |
||||
|
||||
"github.com/harmony-one/harmony/blockchain" |
||||
"github.com/harmony-one/harmony/crypto/pki" |
||||
"github.com/harmony-one/harmony/node" |
||||
) |
||||
|
||||
const ( |
||||
serverPort = "9997" |
||||
serverIP = "127.0.0.1" |
||||
clientPort = "9999" |
||||
) |
||||
|
||||
var ( |
||||
PriIntOne = 111 |
||||
TestAddressOne = pki.GetAddressFromInt(PriIntOne) |
||||
) |
||||
|
||||
func setupServer() *Server { |
||||
bc := blockchain.CreateBlockchain(TestAddressOne, 0) |
||||
node := &node.Node{} |
||||
node.SetBlockchain(bc) |
||||
server := NewServer(node) |
||||
return server |
||||
} |
||||
|
||||
func TestGetBlockHashes(t *testing.T) { |
||||
server := setupServer() |
||||
server.Start(serverIP) |
||||
|
||||
// client := ClientSetUp(serverIP, serverPort)
|
||||
// client.GetHeaders()
|
||||
} |
Loading…
Reference in new issue