github.com/prysmaticlabs/prysm@v1.4.4/validator/db/testing/setup_db.go (about) 1 package testing 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/prysmaticlabs/prysm/validator/db/iface" 8 "github.com/prysmaticlabs/prysm/validator/db/kv" 9 ) 10 11 // SetupDB instantiates and returns a DB instance for the validator client. 12 func SetupDB(t testing.TB, pubkeys [][48]byte) iface.ValidatorDB { 13 db, err := kv.NewKVStore(context.Background(), t.TempDir(), &kv.Config{ 14 PubKeys: pubkeys, 15 }) 16 if err != nil { 17 t.Fatalf("Failed to instantiate DB: %v", err) 18 } 19 t.Cleanup(func() { 20 if err := db.Close(); err != nil { 21 t.Fatalf("Failed to close database: %v", err) 22 } 23 if err := db.ClearDB(); err != nil { 24 t.Fatalf("Failed to clear database: %v", err) 25 } 26 }) 27 return db 28 }