mirror of
https://github.com/libp2p/go-libp2p.git
synced 2025-10-25 09:10:23 +08:00
* bump go.mod to Go 1.19 and run go fix * stop using the deprecated io/ioutil package * bump go.mod to Go 1.19 and run go fix * bump go.mod to Go 1.19 and run go fix * bump go.mod to Go 1.19 and run go fix * stop using the deprecated io/ioutil package * bump go.mod to Go 1.19 and run go fix * stop using the deprecated io/ioutil package * update .github/workflows/go-test.yml * update .github/workflows/go-check.yml * update .github/workflows/release-check.yml * various fixes * stop using deprecated math/rand.Read --------- Co-authored-by: web3-bot <web3-bot@users.noreply.github.com> Co-authored-by: Marten Seemann <martenseemann@gmail.com>
26 lines
397 B
Go
26 lines
397 B
Go
package test
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"testing"
|
|
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
|
|
|
mh "github.com/multiformats/go-multihash"
|
|
)
|
|
|
|
func RandPeerID() (peer.ID, error) {
|
|
buf := make([]byte, 16)
|
|
rand.Read(buf)
|
|
h, _ := mh.Sum(buf, mh.SHA2_256, -1)
|
|
return peer.ID(h), nil
|
|
}
|
|
|
|
func RandPeerIDFatal(t testing.TB) peer.ID {
|
|
p, err := RandPeerID()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return p
|
|
}
|