diff --git a/metrics_test.go b/metrics_test.go index 40429f5..4d9bf25 100644 --- a/metrics_test.go +++ b/metrics_test.go @@ -7,7 +7,7 @@ import ( "time" peer "github.com/ipfs/go-libp2p-peer" - testutil "github.com/ipfs/go-libp2p/testutil" + testutil "github.com/ipfs/go-libp2p-peer/test" ) func TestLatencyEWMAFun(t *testing.T) { diff --git a/peer_test.go b/peer_test.go index 0ad4838..ffef1ee 100644 --- a/peer_test.go +++ b/peer_test.go @@ -9,7 +9,7 @@ import ( u "github.com/ipfs/go-ipfs-util" ic "github.com/ipfs/go-libp2p-crypto" . "github.com/ipfs/go-libp2p-peer" - tu "github.com/ipfs/go-libp2p/testutil" + tu "github.com/ipfs/go-libp2p-peer/test" b58 "github.com/jbenet/go-base58" ) diff --git a/test/utils.go b/test/utils.go new file mode 100644 index 0000000..c9ee61c --- /dev/null +++ b/test/utils.go @@ -0,0 +1,26 @@ +package testutil + +import ( + "io" + + u "github.com/ipfs/go-ipfs-util" + ci "github.com/ipfs/go-libp2p-crypto" + peer "github.com/ipfs/go-libp2p-peer" +) + +func RandPeerID() (peer.ID, error) { + buf := make([]byte, 16) + if _, err := io.ReadFull(u.NewTimeSeededRand(), buf); err != nil { + return "", err + } + h := u.Hash(buf) + return peer.ID(h), nil +} + +func RandTestKeyPair(bits int) (ci.PrivKey, ci.PubKey, error) { + return ci.GenerateKeyPairWithReader(ci.RSA, bits, u.NewTimeSeededRand()) +} + +func SeededTestKeyPair(seed int64) (ci.PrivKey, ci.PubKey, error) { + return ci.GenerateKeyPairWithReader(ci.RSA, 512, u.NewSeededRand(seed)) +}