mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
swarm/storage: NewRandomChunk method rather than FakeChunk
This commit is contained in:
parent
fa8acc90fb
commit
47cfe074f0
1 changed files with 30 additions and 5 deletions
|
|
@ -17,8 +17,11 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
|
|
@ -56,7 +59,7 @@ func TestMemStoreAndLDBStore(t *testing.T) {
|
|||
|
||||
tests := []struct {
|
||||
n int // number of chunks to push to memStore
|
||||
chunkSize int64 // size of chunk (by default in Swarm - 4096)
|
||||
chunkSize uint64 // size of chunk (by default in Swarm - 4096)
|
||||
}{
|
||||
{
|
||||
n: 1,
|
||||
|
|
@ -70,6 +73,10 @@ func TestMemStoreAndLDBStore(t *testing.T) {
|
|||
n: 9999,
|
||||
chunkSize: 4096,
|
||||
},
|
||||
{
|
||||
n: 20001,
|
||||
chunkSize: 4096,
|
||||
},
|
||||
{
|
||||
n: 80001,
|
||||
chunkSize: 4096,
|
||||
|
|
@ -80,11 +87,9 @@ func TestMemStoreAndLDBStore(t *testing.T) {
|
|||
var chunks []*Chunk
|
||||
|
||||
for i := 0; i < tt.n; i++ {
|
||||
chunks = append(chunks, NewChunk(nil, make(chan bool)))
|
||||
chunks = append(chunks, NewRandomChunk(tt.chunkSize))
|
||||
}
|
||||
|
||||
FakeChunk(tt.chunkSize, tt.n, chunks)
|
||||
|
||||
for i := 0; i < tt.n; i++ {
|
||||
go ldb.Put(chunks[i])
|
||||
memStore.Put(chunks[i])
|
||||
|
|
@ -110,3 +115,23 @@ func TestMemStoreAndLDBStore(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func NewRandomChunk(chunkSize uint64) *Chunk {
|
||||
c := &Chunk{
|
||||
Key: make([]byte, 32),
|
||||
ReqC: nil,
|
||||
SData: make([]byte, chunkSize),
|
||||
dbStoredC: make(chan bool),
|
||||
dbStoredMu: &sync.Mutex{},
|
||||
}
|
||||
|
||||
rand.Read(c.SData)
|
||||
|
||||
binary.LittleEndian.PutUint64(c.SData[:8], chunkSize)
|
||||
|
||||
hasher := MakeHashFunc(SHA3Hash)()
|
||||
hasher.Write(c.SData)
|
||||
copy(c.Key, hasher.Sum(nil))
|
||||
|
||||
return c
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue