2020-06-27 02:37:43 +00:00
|
|
|
package testing
|
2020-01-08 18:16:17 +00:00
|
|
|
|
|
|
|
import (
|
2020-12-11 18:31:35 +00:00
|
|
|
"context"
|
2020-01-08 18:16:17 +00:00
|
|
|
"testing"
|
2020-06-26 14:58:47 +00:00
|
|
|
|
2021-01-18 19:32:17 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/db/iface"
|
2020-06-27 02:37:43 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/db/kv"
|
2020-01-08 18:16:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SetupDB instantiates and returns a DB instance for the validator client.
|
2021-01-18 19:32:17 +00:00
|
|
|
func SetupDB(t testing.TB, pubkeys [][48]byte) iface.ValidatorDB {
|
2020-12-11 18:31:35 +00:00
|
|
|
db, err := kv.NewKVStore(context.Background(), t.TempDir(), pubkeys)
|
2020-01-08 18:16:17 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to instantiate DB: %v", err)
|
|
|
|
}
|
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)
|
|
|
|
}
|
|
|
|
if err := db.ClearDB(); err != nil {
|
|
|
|
t.Fatalf("Failed to clear database: %v", err)
|
|
|
|
}
|
|
|
|
})
|
2020-01-08 18:16:17 +00:00
|
|
|
return db
|
|
|
|
}
|