Merge pull request #280 from harmony-one/leochen_fix_peerstore_in_hostv2
fix peerstore in hostv2pull/286/head
commit
f7f4e800e8
@ -1,38 +1,59 @@ |
||||
package newnode |
||||
|
||||
import ( |
||||
"fmt" |
||||
"testing" |
||||
"time" |
||||
|
||||
beaconchain "github.com/harmony-one/harmony/internal/beaconchain/libs" |
||||
"github.com/harmony-one/harmony/p2p" |
||||
peerstore "github.com/libp2p/go-libp2p-peerstore" |
||||
multiaddr "github.com/multiformats/go-multiaddr" |
||||
) |
||||
|
||||
func TestNewNode(t *testing.T) { |
||||
var ip, port string |
||||
ip = "127.0.0.1" |
||||
port = "8080" |
||||
port = "8088" |
||||
nnode := New(ip, port) |
||||
|
||||
if nnode.PubK == nil { |
||||
t.Error("new node public key not initialized") |
||||
} |
||||
|
||||
if nnode.SetInfo { |
||||
t.Error("new node setinfo initialized to true! (should be false)") |
||||
} |
||||
} |
||||
|
||||
func TestBeaconChainConnect(t *testing.T) { |
||||
var ip, beaconport, nodeport string |
||||
var ip, beaconport, bcma, nodeport string |
||||
|
||||
ip = "127.0.0.1" |
||||
beaconport = "9080" |
||||
beaconport = "8081" |
||||
nodeport = "9081" |
||||
|
||||
nnode := New(ip, nodeport) |
||||
bc := beaconchain.New(1, ip, beaconport) |
||||
bcma = fmt.Sprintf("/ip4/%s/tcp/%s/ipfs/%s", bc.Self.IP, bc.Self.Port, bc.GetID().Pretty()) |
||||
|
||||
go bc.StartServer() |
||||
BCPeer := p2p.Peer{IP: ip, Port: beaconport} |
||||
err := nnode.ContactBeaconChain(BCPeer) |
||||
time.Sleep(3 * time.Second) |
||||
|
||||
maddr, err := multiaddr.NewMultiaddr(bcma) |
||||
if err != nil { |
||||
t.Error("could not read from connection") |
||||
t.Errorf("new multiaddr error: %v", err) |
||||
} |
||||
|
||||
// Extract the peer ID from the multiaddr.
|
||||
info, err2 := peerstore.InfoFromP2pAddr(maddr) |
||||
if err2 != nil { |
||||
t.Errorf("info from p2p addr error: %v", err2) |
||||
} |
||||
|
||||
BCPeer := &p2p.Peer{IP: ip, Port: beaconport, Addrs: info.Addrs, PeerID: info.ID} |
||||
|
||||
nnode.AddPeer(BCPeer) |
||||
|
||||
err3 := nnode.ContactBeaconChain(*BCPeer) |
||||
|
||||
if err3 != nil { |
||||
t.Errorf("could not read from connection: %v", err3) |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue