From 4a97f541cd9cc898ef21b071e474febcb8b0efe3 Mon Sep 17 00:00:00 2001 From: Alok Kothari Date: Wed, 22 Aug 2018 16:38:20 -0700 Subject: [PATCH] identity chain is working fixed listen on port --- identitychain/identitychain.go | 4 ++-- identitychain/identitychain_test.go | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/identitychain/identitychain.go b/identitychain/identitychain.go index 16a5753fb..1ebf21238 100644 --- a/identitychain/identitychain.go +++ b/identitychain/identitychain.go @@ -93,13 +93,12 @@ func (IDC *IdentityChain) UpdateIdentityChain() { } func (IDC *IdentityChain) listenOnPort() { - fmt.Print(IDC.Peer.Port) listen, err := net.Listen("tcp4", ":"+IDC.Peer.Port) if err != nil { IDC.log.Crit("Socket listen port failed") os.Exit(1) } else { - IDC.log.Info("Identity chain is now listening..") + IDC.log.Info("Identity chain is now listening ..") } defer listen.Close() for { @@ -116,5 +115,6 @@ func (IDC *IdentityChain) listenOnPort() { func New(Peer p2p.Peer) *IdentityChain { IDC := IdentityChain{} IDC.Peer = Peer + IDC.log = log.New() return &IDC } diff --git a/identitychain/identitychain_test.go b/identitychain/identitychain_test.go index cd7333921..6628ad142 100644 --- a/identitychain/identitychain_test.go +++ b/identitychain/identitychain_test.go @@ -1,16 +1,18 @@ package identitychain import ( + "fmt" + "os" "testing" + + "github.com/simple-rules/harmony-benchmark/p2p" ) -func TestConnAlive(test *testing.T) { - // peer := p2p.Peer{Ip: "127.0.0.1", Port: "8080"} - // IDC := New(peer) - // IDC.listenOnPort() - // // conn, err := net.Dial("tcp", IDC.Peer.Ip+":"+IDC.Peer.Port) - // // if err != nil { - // // test.Fatal(err) - // // } - // // defer conn.Close() +func TestIDCFormed(test *testing.T) { + peer := p2p.Peer{Ip: "127.0.0.1", Port: "8080"} + IDC := New(peer) + if IDC == nil { + fmt.Println("IDC not formed.") + os.Exit(1) + } }