mirror of https://github.com/libp2p/go-libp2p.git
Jamie Steiner
7 years ago
2 changed files with 49 additions and 1 deletions
@ -0,0 +1,34 @@ |
|||
package libp2p |
|||
|
|||
import ( |
|||
"context" |
|||
"fmt" |
|||
"testing" |
|||
|
|||
crypto "github.com/libp2p/go-libp2p-crypto" |
|||
host "github.com/libp2p/go-libp2p-host" |
|||
) |
|||
|
|||
func TestNewHost(t *testing.T) { |
|||
_, err := makeRandomHost(t, 9000) |
|||
if err != nil { |
|||
t.Fatal(err) |
|||
} |
|||
} |
|||
|
|||
func makeRandomHost(t *testing.T, port int) (host.Host, error) { |
|||
ctx := context.Background() |
|||
priv, _, err := crypto.GenerateKeyPair(crypto.RSA, 2048) |
|||
if err != nil { |
|||
t.Fatal(err) |
|||
} |
|||
|
|||
opts := []Option{ |
|||
ListenAddrStrings(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", port)), |
|||
Identity(priv), |
|||
Muxer(DefaultMuxer()), |
|||
NATPortMap(), |
|||
} |
|||
|
|||
return New(ctx, opts...) |
|||
} |
Loading…
Reference in new issue