Files
go-libp2p/core/test/peer.go
web3-bot 3a66ff89a1 sync: update CI config files (#2073)
* 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>
2023-02-12 01:18:10 -08:00

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
}