prysm-pulse/validator/db/kv/db_test.go
Shay Zluf acf201428e
Use new proposal protection format (#7518)
* Use new proposal protection format

* Update comments

* Split and merge with new db

* fix tests

* fix test

* optimize domain

* fix validation

* fix validation

* check import error

* fix e2e

* fix old propose tests add ign block test

* constant secret key

* static test for signing

* test domain

* fix testsplit

* gaz

* gaz

* tidy

* raul feedback

* fix tests

* tidy

* added info log for the migration

* gaz

* Update validator/client/propose_protect.go

Co-authored-by: Nishant Das <nishdas93@gmail.com>

* nishant feedback

* import fix

* fix

* remove propose protection flag

* fix block sign test

Co-authored-by: Nishant Das <nishdas93@gmail.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-10-15 19:35:31 +00:00

39 lines
1.1 KiB
Go

package kv
import (
"fmt"
"os"
"path/filepath"
"testing"
"github.com/prysmaticlabs/prysm/shared/rand"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
// setupDB instantiates and returns a DB instance for the validator client.
func setupDB(t testing.TB, pubkeys [][48]byte) *Store {
randPath := rand.NewDeterministicGenerator().Int()
p := filepath.Join(tempdir(), fmt.Sprintf("/%d", randPath))
require.NoError(t, os.RemoveAll(p), "Failed to remove directory")
db, err := NewKVStore(p, pubkeys)
require.NoError(t, err, "Failed to instantiate DB")
err = db.OldUpdatePublicKeysBuckets(pubkeys)
require.NoError(t, err, "Failed to create old buckets for public keys")
t.Cleanup(func() {
require.NoError(t, db.Close(), "Failed to close database")
require.NoError(t, db.ClearDB(), "Failed to clear database")
})
return db
}
// tempdir returns a directory path for temporary test storage.
func tempdir() string {
d := os.Getenv("TEST_TMPDIR")
// If the test is not run via bazel, the environment var won't be set.
if d == "" {
return os.TempDir()
}
return d
}