mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-17 15:28:45 +00:00
66991f0efe
* rem slasher proto * with cache * delete old code * moving to bytes.go fix traces * moving to bytes.go fix traces * raul feedback * raul feedback * add eviction test * ivan feedback * ivan feedback * some comment improvements * test included for bytes and bool * import * cleanup * tests pass * fill in all fields in test * gaz Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package kv
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"fmt"
|
|
"math/big"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/slasher/db/iface"
|
|
"github.com/prysmaticlabs/prysm/slasher/flags"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
func setupDB(t testing.TB, ctx *cli.Context) *Store {
|
|
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
|
|
if err != nil {
|
|
t.Fatalf("Could not generate random file path: %v", err)
|
|
}
|
|
p := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath))
|
|
if err := os.RemoveAll(p); err != nil {
|
|
t.Fatalf("Failed to remove directory: %v", err)
|
|
}
|
|
cfg := &Config{CacheItems: 0, MaxCacheSize: 0, SpanCacheEnabled: ctx.GlobalBool(flags.UseSpanCacheFlag.Name)}
|
|
db, err := NewKVStore(p, cfg)
|
|
if err != nil {
|
|
t.Fatalf("Failed to instantiate DB: %v", err)
|
|
}
|
|
return db
|
|
}
|
|
|
|
func setupDBDiffCacheSize(t testing.TB, cacheItems int64, maxCacheSize int64) *Store {
|
|
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
|
|
if err != nil {
|
|
t.Fatalf("Could not generate random file path: %v", err)
|
|
}
|
|
p := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath))
|
|
if err := os.RemoveAll(p); err != nil {
|
|
t.Fatalf("Failed to remove directory: %v", err)
|
|
}
|
|
cfg := &Config{CacheItems: cacheItems, MaxCacheSize: maxCacheSize, SpanCacheEnabled: true}
|
|
newDB, err := NewKVStore(p, cfg)
|
|
if err != nil {
|
|
t.Fatalf("Failed to instantiate DB: %v", err)
|
|
}
|
|
return newDB
|
|
}
|
|
|
|
func teardownDB(t testing.TB, db iface.Database) {
|
|
if err := db.Close(); err != nil {
|
|
t.Fatalf("Failed to close database: %v", err)
|
|
}
|
|
if err := os.RemoveAll(db.DatabasePath()); err != nil {
|
|
t.Fatalf("Failed to remove directory: %v", err)
|
|
}
|
|
}
|