prysm-pulse/beacon-chain/db/kv/backup_test.go
Victor Farazdagi b5c4dc2a75
Refactor db teardown to testing.TB.Cleanup (#5725)
* init-sync updates
* slasher/db/kv tests
* beacon-chain/rpc/beacon tests
* update kv_test
* beacon-chain/rpc-validator tests updated
* slasher/db/kv - remove teardown method
* beacon-chain/sync tests updated
* beacon-chain/db/kv tests updated
* beacon-chain/blockchain tests updated
* beacon-chain/state/stategen tests updated
* beacon-chain/powchain updates
* updates rest of slasher tests
* validator/db tests
* rest of the tests
* minor comments update
* gazelle
* Merge refs/heads/master into teardowndb-to-cleanup
2020-05-04 01:14:34 +00:00

47 lines
926 B
Go

package kv
import (
"context"
"io/ioutil"
"path"
"testing"
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
"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 := ssz.HashTreeRoot(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.")
}
}