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