Fix validator export failing when validator.db is in nested directory (#15351)

* files changed

* added changelog file

* added tests and formatting changes

* fixed bugs

* fixed formatting
This commit is contained in:
Rose Jethani
2025-05-30 20:23:19 +05:30
committed by GitHub
parent 711984d942
commit 3300866572
12 changed files with 162 additions and 115 deletions

View File

@@ -26,7 +26,7 @@ func TestMigrateUp_NoDBFound(t *testing.T) {
// This, it is tested only for complete slashing protection database.
func TestMigrateUp_OK(t *testing.T) {
isSlashingProtectionMinimal := false
validatorDB := dbtest.SetupDB(t, nil, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), nil, isSlashingProtectionMinimal)
dbPath := validatorDB.DatabasePath()
require.NoError(t, validatorDB.Close())
app := cli.App{}
@@ -52,7 +52,7 @@ func TestMigrateDown_NoDBFound(t *testing.T) {
// This, it is tested only for complete slashing protection database.
func TestMigrateDown_OK(t *testing.T) {
isSlashingProtectionMinimal := false
validatorDB := dbtest.SetupDB(t, nil, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), nil, isSlashingProtectionMinimal)
dbPath := validatorDB.DatabasePath()
require.NoError(t, validatorDB.Close())
app := cli.App{}

View File

@@ -13,7 +13,7 @@ import (
// SetupDB instantiates and returns a DB instance for the validator client.
// The `minimal` flag indicates whether the DB should be instantiated with minimal, filesystem
// slashing protection database.
func SetupDB(t testing.TB, pubkeys [][fieldparams.BLSPubkeyLength]byte, minimal bool) iface.ValidatorDB {
func SetupDB(t testing.TB, dataPath string, pubkeys [][fieldparams.BLSPubkeyLength]byte, minimal bool) iface.ValidatorDB {
var (
db iface.ValidatorDB
err error
@@ -22,10 +22,10 @@ func SetupDB(t testing.TB, pubkeys [][fieldparams.BLSPubkeyLength]byte, minimal
// Create a new DB instance.
if minimal {
config := &filesystem.Config{PubKeys: pubkeys}
db, err = filesystem.NewStore(t.TempDir(), config)
db, err = filesystem.NewStore(dataPath, config)
} else {
config := &kv.Config{PubKeys: pubkeys}
db, err = kv.NewKVStore(context.Background(), t.TempDir(), config)
db, err = kv.NewKVStore(context.Background(), dataPath, config)
}
if err != nil {