package kv import ( "crypto/rand" "fmt" "math/big" "os" "path" "testing" "github.com/prysmaticlabs/prysm/beacon-chain/cache" "github.com/prysmaticlabs/prysm/shared/testutil" "github.com/prysmaticlabs/prysm/shared/testutil/require" ) // setupDB instantiates and returns a Store instance. func setupDB(t testing.TB) *Store { randPath, err := rand.Int(rand.Reader, big.NewInt(1000000)) require.NoError(t, err, "Could not generate random file path") p := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath)) require.NoError(t, os.RemoveAll(p), "Failed to remove directory") db, err := NewKVStore(p, cache.NewStateSummaryCache()) require.NoError(t, err, "Failed to instantiate DB") t.Cleanup(func() { require.NoError(t, db.Close(), "Failed to close database") require.NoError(t, os.RemoveAll(db.DatabasePath()), "Failed to remove directory") }) return db }