prysm-pulse/beacon-chain/db/kv/backup_test.go
Victor Farazdagi fecbec2342
Applies assertion funcs to beacon-chain/db tests (#6938)
* part1
* go tidy
* Merge branch 'go-tidy' into apply-testutils-assertions-to-beaconchain-db
* updated beacon-chain/db/kv tests
* Merge branch 'master' into apply-testutils-assertions-to-beaconchain-db
* Merge refs/heads/master into apply-testutils-assertions-to-beaconchain-db
* Merge refs/heads/master into apply-testutils-assertions-to-beaconchain-db
2020-08-08 18:39:01 +00:00

34 lines
907 B
Go

package kv
import (
"context"
"io/ioutil"
"path"
"testing"
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestStore_Backup(t *testing.T) {
db := setupDB(t)
ctx := context.Background()
head := &eth.SignedBeaconBlock{Block: &eth.BeaconBlock{Slot: 5000}}
require.NoError(t, db.SaveBlock(ctx, head))
root, err := stateutil.BlockRoot(head.Block)
require.NoError(t, err)
st := testutil.NewBeaconState()
require.NoError(t, db.SaveState(ctx, st, root))
require.NoError(t, db.SaveHeadBlockRoot(ctx, root))
require.NoError(t, db.Backup(ctx))
files, err := ioutil.ReadDir(path.Join(db.databasePath, backupsDirectoryName))
require.NoError(t, err)
require.NotEqual(t, 0, len(files), "No backups created")
}