github.com/ethersphere/bee/v2@v2.2.0/pkg/file/testing/chunk.go (about) 1 // Copyright 2020 The Swarm Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package testing 6 7 import ( 8 "crypto/rand" 9 "encoding/binary" 10 11 "github.com/ethersphere/bee/v2/pkg/swarm" 12 ) 13 14 // GenerateTestRandomFileChunk generates one single chunk with arbitrary content and address 15 func GenerateTestRandomFileChunk(address swarm.Address, spanLength, dataSize int) swarm.Chunk { 16 data := make([]byte, dataSize+8) 17 binary.LittleEndian.PutUint64(data, uint64(spanLength)) 18 _, _ = rand.Read(data[8:]) 19 key := make([]byte, swarm.SectionSize) 20 if address.IsZero() { 21 _, _ = rand.Read(key) 22 } else { 23 copy(key, address.Bytes()) 24 } 25 return swarm.NewChunk(swarm.NewAddress(key), data) 26 }