2020-04-29 21:32:39 +00:00
|
|
|
// Package testing defines useful helper functions for unit tests with
|
|
|
|
// the slasher database.
|
2020-02-13 16:19:46 +00:00
|
|
|
package testing
|
2019-09-26 16:29:10 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2020-01-22 05:39:21 +00:00
|
|
|
|
2020-02-13 16:19:46 +00:00
|
|
|
slasherDB "github.com/prysmaticlabs/prysm/slasher/db"
|
|
|
|
"github.com/prysmaticlabs/prysm/slasher/db/kv"
|
2019-09-26 16:29:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SetupSlasherDB instantiates and returns a SlasherDB instance.
|
2020-02-27 17:22:39 +00:00
|
|
|
func SetupSlasherDB(t testing.TB, spanCacheEnabled bool) *kv.Store {
|
2020-04-22 15:53:09 +00:00
|
|
|
cfg := &kv.Config{}
|
2020-11-10 22:45:17 +00:00
|
|
|
db, err := slasherDB.NewDB(t.TempDir(), cfg)
|
2020-01-22 05:39:21 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to instantiate DB: %v", err)
|
|
|
|
}
|
2020-05-29 12:09:04 +00:00
|
|
|
db.EnableSpanCache(spanCacheEnabled)
|
2020-05-04 01:14:34 +00:00
|
|
|
t.Cleanup(func() {
|
|
|
|
if err := db.Close(); err != nil {
|
|
|
|
t.Fatalf("Failed to close database: %v", err)
|
|
|
|
}
|
|
|
|
})
|
2020-01-22 05:39:21 +00:00
|
|
|
return db
|
|
|
|
}
|