mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package db
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/types"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func startInMemoryBeaconDB(t *testing.T) *BeaconDB {
|
|
config := Config{Path: "", Name: "", InMemory: true}
|
|
db, err := NewDB(config)
|
|
if err != nil {
|
|
t.Fatalf("unable to setup db: %v", err)
|
|
}
|
|
|
|
return db
|
|
}
|
|
|
|
func TestNewDB(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
beaconDB := startInMemoryBeaconDB(t)
|
|
defer beaconDB.Close()
|
|
|
|
msg := hook.LastEntry().Message
|
|
want := "No chainstate found on disk, initializing beacon from genesis"
|
|
if msg != want {
|
|
t.Errorf("incorrect log, expected %s, got %s", want, msg)
|
|
}
|
|
|
|
hook.Reset()
|
|
aState := types.NewGenesisActiveState()
|
|
cState, err := types.NewGenesisCrystallizedState("")
|
|
if err != nil {
|
|
t.Errorf("Creating new genesis state failed %v", err)
|
|
}
|
|
|
|
if !proto.Equal(beaconDB.GetActiveState().Proto(), aState.Proto()) {
|
|
t.Errorf("active states not equal. received: %v, wanted: %v", beaconDB.GetActiveState(), aState)
|
|
}
|
|
|
|
if !proto.Equal(beaconDB.GetCrystallizedState().Proto(), cState.Proto()) {
|
|
t.Errorf("crystallized states not equal. received: %v, wanted: %v", beaconDB.GetCrystallizedState(), cState)
|
|
}
|
|
}
|