newnode test

pull/195/head
ak 6 years ago
parent 367589232d
commit ff9f0c68b3
  1. 9
      internal/newnode/newnode.go
  2. 23
      internal/newnode/newnode_test.go

@ -1,6 +1,7 @@
package newnode
import (
"errors"
"fmt"
"os"
"strconv"
@ -55,9 +56,9 @@ type registerResponseRandomNumber struct {
}
// ContactBeaconChain starts a newservice in the candidate node
func (node *NewNode) ContactBeaconChain(BCPeer p2p.Peer) {
func (node *NewNode) ContactBeaconChain(BCPeer p2p.Peer) error {
go node.host.BindHandlerAndServe(node.NodeHandler)
node.requestBeaconChain(BCPeer)
return node.requestBeaconChain(BCPeer)
}
func (node NewNode) String() string {
@ -65,7 +66,7 @@ func (node NewNode) String() string {
}
// RequestBeaconChain requests beacon chain for identity data
func (node *NewNode) requestBeaconChain(BCPeer p2p.Peer) {
func (node *NewNode) requestBeaconChain(BCPeer p2p.Peer) (err error) {
node.log.Info("connecting to beacon chain now ...")
pubk, err := node.PubK.MarshalBinary()
if err != nil {
@ -94,9 +95,11 @@ checkLoop:
}
}
if !gotShardInfo {
err = errors.New("could not create connection")
node.log.Crit("Could not get sharding info after 5 minutes")
os.Exit(1)
}
return
}
// ProcessShardInfo

@ -1,6 +1,11 @@
package newnode
import "testing"
import (
"testing"
beaconchain "github.com/harmony-one/harmony/internal/beaconchain/libs"
"github.com/harmony-one/harmony/p2p"
)
func TestNewNode(t *testing.T) {
var ip, port string
@ -16,3 +21,19 @@ func TestNewNode(t *testing.T) {
t.Error("new node setinfo initialized to true! (should be false)")
}
}
func TestBeaconChainConnect(t *testing.T) {
var ip, beaconport, nodeport string
ip = "127.0.0.1"
beaconport = "8080"
nodeport = "8081"
nnode := New(ip, nodeport)
bc := beaconchain.New(1, ip, beaconport)
go bc.StartServer()
BCPeer := p2p.Peer{IP: ip, Port: beaconport}
err := nnode.ContactBeaconChain(BCPeer)
if err != nil {
t.Error("could not read from connection")
}
}

Loading…
Cancel
Save