Files
prysm/validator/db/testing/setup_db_test.go
Bastin 92bd211e4d upgrade v6 to v7 (#15989)
* upgrade v6 to v7

* changelog

* update-go-ssz
2025-11-06 16:16:23 +00:00

49 lines
1.4 KiB
Go

package testing
import (
"fmt"
"path/filepath"
"testing"
"github.com/OffchainLabs/prysm/v7/io/file"
"github.com/OffchainLabs/prysm/v7/testing/require"
"github.com/OffchainLabs/prysm/v7/validator/db/filesystem"
"github.com/OffchainLabs/prysm/v7/validator/db/iface"
"github.com/OffchainLabs/prysm/v7/validator/db/kv"
)
func TestClearDB(t *testing.T) {
for _, isSlashingProtectionMinimal := range []bool{false, true} {
t.Run(fmt.Sprintf("slashing protection minimal: %v", isSlashingProtectionMinimal), func(t *testing.T) {
// Setting up manually is required, since SetupDB() will also register a teardown procedure.
var (
testDB iface.ValidatorDB
err error
)
if isSlashingProtectionMinimal {
testDB, err = filesystem.NewStore(t.TempDir(), &filesystem.Config{
PubKeys: nil,
})
} else {
testDB, err = kv.NewKVStore(t.Context(), t.TempDir(), &kv.Config{
PubKeys: nil,
})
}
require.NoError(t, err, "Failed to instantiate DB")
require.NoError(t, testDB.ClearDB())
databaseName := kv.ProtectionDbFileName
if isSlashingProtectionMinimal {
databaseName = filesystem.DatabaseDirName
}
databasePath := filepath.Join(testDB.DatabasePath(), databaseName)
exists, err := file.Exists(databasePath, file.Regular)
require.NoError(t, err, "Failed to check if DB exists")
require.Equal(t, false, exists, "DB was not cleared")
})
}
}