2020-06-26 19:37:43 -07:00
|
|
|
package testing
|
2020-01-08 13:16:17 -05:00
|
|
|
|
|
|
|
import (
|
2020-12-11 12:31:35 -06:00
|
|
|
"context"
|
2020-01-08 13:16:17 -05:00
|
|
|
"testing"
|
2020-06-26 17:58:47 +03:00
|
|
|
|
2023-03-17 11:52:56 -07:00
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/v4/config/fieldparams"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/validator/db/iface"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/validator/db/kv"
|
2020-01-08 13:16:17 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// SetupDB instantiates and returns a DB instance for the validator client.
|
2022-01-06 09:33:08 -08:00
|
|
|
func SetupDB(t testing.TB, pubkeys [][fieldparams.BLSPubkeyLength]byte) iface.ValidatorDB {
|
2021-02-15 14:29:47 -06:00
|
|
|
db, err := kv.NewKVStore(context.Background(), t.TempDir(), &kv.Config{
|
|
|
|
PubKeys: pubkeys,
|
|
|
|
})
|
2020-01-08 13:16:17 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to instantiate DB: %v", err)
|
|
|
|
}
|
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)
|
|
|
|
}
|
|
|
|
if err := db.ClearDB(); err != nil {
|
|
|
|
t.Fatalf("Failed to clear database: %v", err)
|
|
|
|
}
|
|
|
|
})
|
2020-01-08 13:16:17 -05:00
|
|
|
return db
|
|
|
|
}
|