prysm-pulse/beacon-chain/internal/db_test_util.go
Raul Jordan f89fce9bd7
Implement Basic LMD Ghost Fork Choice Skeleton + Helper Funcs (#1310)
* add fork choice helpers

* LMD GHOST basic implementation

* add todos

* add in the initial test and finalize rest of functions

* added tests

* more simulation, adding trivial case with only one option for a head

* panics

* begin helper function tests

* more helper tests

* higher vote wins

* LMD Ghost full test

* comment

* add types

* optimize

* prepared

* deposits for chain

* lint

* use the hash beacon block util

* rem unnecessary db methods

* comments

* setup works
2019-01-19 10:57:51 +08:00

40 lines
934 B
Go

package internal
import (
"crypto/rand"
"fmt"
"math/big"
"os"
"path"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
)
// SetupDB instantiates and returns a BeaconDB instance.
func SetupDB(t testing.TB) *db.BeaconDB {
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
if err != nil {
t.Fatalf("Could not generate random file path: %v", err)
}
path := path.Join(os.TempDir(), fmt.Sprintf("/%d", randPath))
if err := os.RemoveAll(path); err != nil {
t.Fatalf("Failed to remove directory: %v", err)
}
db, err := db.NewDB(path)
if err != nil {
t.Fatalf("Could not setup DB: %v", err)
}
return db
}
// TeardownDB cleans up a BeaconDB instance.
func TeardownDB(t testing.TB, db *db.BeaconDB) {
if err := db.Close(); err != nil {
t.Fatalf("Failed to close database: %v", err)
}
if err := os.RemoveAll(db.DatabasePath); err != nil {
t.Fatalf("Could not remove tmp db dir: %v", err)
}
}