mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-02 03:28:25 +08:00
Testutil to gen random CidV0
License: MIT Signed-off-by: Zander Mackie <zmackie@gmail.com>
This commit is contained in:
9
thirdparty/testutil/gen.go
vendored
9
thirdparty/testutil/gen.go
vendored
@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
u "gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
|
||||
cid "gx/ipfs/QmcTcsTvfaeEBRFo1TkFgT8sRmgi1n1LTZpecfVP8fzpGD/go-cid"
|
||||
peer "gx/ipfs/QmfMmLGoKzCHDN7cGgk64PJr4iipzidDRME8HABSJqvmhC/go-libp2p-peer"
|
||||
ci "gx/ipfs/QmfWDLQjGjVe4fr5CoztYW2DYYjRysMJrFe1RCsXLPTf46/go-libp2p-crypto"
|
||||
|
||||
@ -50,6 +51,14 @@ func RandPeerID() (peer.ID, error) {
|
||||
return peer.ID(h), nil
|
||||
}
|
||||
|
||||
func RandCidV0() (*cid.Cid, error) {
|
||||
buf := make([]byte, 16)
|
||||
if _, err := io.ReadFull(u.NewTimeSeededRand(), buf); err != nil {
|
||||
return &cid.Cid{}, err
|
||||
}
|
||||
return cid.NewCidV0(buf), nil
|
||||
}
|
||||
|
||||
func RandPeerIDFatal(t testing.TB) peer.ID {
|
||||
p, err := RandPeerID()
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user