prysm-pulse/beacon-chain/db/kv/backup_test.go
Preston Van Loon 9be8a456eb
Use stateutil.BlockRoot everywhere (#5739)
* Sweeping replace of ssz.HashTreeRoot(block) to stateutil.BlockRoot, minor tweaks to critical path of proposeBlock
* imports
* Merge branch 'master' into better-block-htr
* Add --enable-custom-block-htr to e2e flags
* Merge branch 'better-block-htr' of github.com:prysmaticlabs/prysm into better-block-htr
2020-05-05 04:30:24 +00:00

47 lines
957 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"
)
func TestStore_Backup(t *testing.T) {
db := setupDB(t)
ctx := context.Background()
head := &eth.SignedBeaconBlock{Block: &eth.BeaconBlock{Slot: 5000}}
if err := db.SaveBlock(ctx, head); err != nil {
t.Fatal(err)
}
root, err := stateutil.BlockRoot(head.Block)
if err != nil {
t.Fatal(err)
}
st := testutil.NewBeaconState()
if err := db.SaveState(ctx, st, root); err != nil {
t.Fatal(err)
}
if err := db.SaveHeadBlockRoot(ctx, root); err != nil {
t.Fatal(err)
}
if err := db.Backup(ctx); err != nil {
t.Fatal(err)
}
files, err := ioutil.ReadDir(path.Join(db.databasePath, backupsDirectoryName))
if err != nil {
t.Fatal(err)
}
if len(files) == 0 {
t.Fatal("No backups created.")
}
}