Skip to content

Commit

Permalink
Testutil to gen random CidV0
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Zander Mackie <[email protected]>
  • Loading branch information
zmackie committed Dec 17, 2016
1 parent 695c22a commit 058bfc3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions thirdparty/testutil/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 058bfc3

Please sign in to comment.