mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-04 16:54:28 +00:00
eb192049b8
* create a testing db method that can be used with the new database interface * lint * lint * PR feedback * Update setup_db.go
37 lines
966 B
Go
37 lines
966 B
Go
package db
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"fmt"
|
|
"math/big"
|
|
"os"
|
|
"path"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// SetupDB instantiates and returns a simulated backend BeaconDB instance.
|
|
// DEPRECATED: Use beacon-chain/db/testing.SetupDB
|
|
func SetupDB() (*BeaconDB, error) {
|
|
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not generate random file path")
|
|
}
|
|
path := path.Join(os.TempDir(), fmt.Sprintf("/%d", randPath))
|
|
if err := os.RemoveAll(path); err != nil {
|
|
return nil, errors.Wrap(err, "failed to remove directory")
|
|
}
|
|
return NewDBDeprecated(path)
|
|
}
|
|
|
|
// TeardownDB cleans up a simulated backend BeaconDB instance.
|
|
// DEPRECATED: Use beacon-chain/db/testing.TeardownDB
|
|
func TeardownDB(db *BeaconDB) {
|
|
if err := db.Close(); err != nil {
|
|
log.Fatalf("failed to close database: %v", err)
|
|
}
|
|
if err := os.RemoveAll(db.DatabasePath); err != nil {
|
|
log.Fatalf("could not remove tmp db dir: %v", err)
|
|
}
|
|
}
|