Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #135 from ipfs/fix/blocks-generator
Browse files Browse the repository at this point in the history
testutil: fix block generator
  • Loading branch information
hannahhoward authored Jun 3, 2019
2 parents 1b921d2 + 1298633 commit 10e93ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ var prioritySeq int
// GenerateBlocksOfSize generates a series of blocks of the given byte size
func GenerateBlocksOfSize(n int, size int64) []blocks.Block {
generatedBlocks := make([]blocks.Block, 0, n)
buf := make([]byte, size)
for i := 0; i < n; i++ {
// rand.Read never errors
buf := make([]byte, size)
rand.Read(buf)
b := blocks.NewBlock(buf)
generatedBlocks = append(generatedBlocks, b)
Expand Down
16 changes: 16 additions & 0 deletions testutil/testutil_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package testutil

import (
"testing"

blocks "github.com/ipfs/go-block-format"
)

func TestGenerateBlocksOfSize(t *testing.T) {
for _, b1 := range GenerateBlocksOfSize(10, 100) {
b2 := blocks.NewBlock(b1.RawData())
if b2.Cid() != b1.Cid() {
t.Fatal("block CIDs mismatch")
}
}
}

0 comments on commit 10e93ab

Please sign in to comment.