mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-05 09:14:28 +00:00
3edfa8cb88
* Use ValidtorIndex across Prysm. Build ok * First take at fixing tests * Clean up e2e, fuzz... etc * Fix new lines * Update beacon-chain/cache/proposer_indices_test.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update beacon-chain/core/helpers/rewards_penalties.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update beacon-chain/core/helpers/shuffle.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update validator/graffiti/parse_graffiti_test.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Raul's feedback * Fix downcast int -> uint64 * Victor's feedback Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestStore_Backup(t *testing.T) {
|
|
db := setupDB(t)
|
|
ctx := context.Background()
|
|
pubKey := []byte("hello")
|
|
require.NoError(t, db.SavePubKey(ctx, types.ValidatorIndex(1), pubKey))
|
|
require.NoError(t, db.Backup(ctx, ""))
|
|
|
|
backupsPath := filepath.Join(db.databasePath, backupsDirectoryName)
|
|
files, err := ioutil.ReadDir(backupsPath)
|
|
require.NoError(t, err)
|
|
require.NotEqual(t, 0, len(files), "No backups created")
|
|
|
|
oldFilePath := filepath.Join(backupsPath, files[0].Name())
|
|
newFilePath := filepath.Join(backupsPath, DatabaseFileName)
|
|
// We rename the file to match the database file name
|
|
// our NewKVStore function expects when opening a database.
|
|
require.NoError(t, os.Rename(oldFilePath, newFilePath))
|
|
|
|
backedDB, err := NewKVStore(backupsPath, &Config{})
|
|
require.NoError(t, err, "Failed to instantiate DB")
|
|
t.Cleanup(func() {
|
|
require.NoError(t, backedDB.Close(), "Failed to close database")
|
|
})
|
|
received, err := backedDB.ValidatorPubKey(ctx, types.ValidatorIndex(1))
|
|
require.NoError(t, err)
|
|
require.DeepEqual(t, pubKey, received)
|
|
}
|