mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
Former-commit-id: bbd5b46e7f64f762350d6fb496492207e70d7130 [formerly 43a37f7139b7d1d90f0c27a7406b63bdf390ad96] Former-commit-id: bb7a2ff0a7619f8de0bd38cd2c9eb0de7c189edb
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package blockchain
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/geth-sharding/beacon-chain/database"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestStartStop(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
ctx := context.Background()
|
|
tmp := fmt.Sprintf("%s/beacontest", os.TempDir())
|
|
config := &database.BeaconDBConfig{DataDir: tmp, Name: "beacontestdata", InMemory: false}
|
|
db, err := database.NewBeaconDB(config)
|
|
if err != nil {
|
|
t.Fatalf("could not setup beaconDB: %v", err)
|
|
}
|
|
db.Start()
|
|
chainService, err := NewChainService(ctx, db)
|
|
if err != nil {
|
|
t.Fatalf("unable to setup chain service: %v", err)
|
|
}
|
|
|
|
chainService.Start()
|
|
|
|
if err := chainService.Stop(); err != nil {
|
|
t.Fatalf("unable to stop chain service: %v", err)
|
|
}
|
|
|
|
msg := hook.AllEntries()[0].Message
|
|
want := "Starting beaconDB service"
|
|
if msg != want {
|
|
t.Errorf("incorrect log, expected %s, got %s", want, msg)
|
|
}
|
|
|
|
msg = hook.AllEntries()[1].Message
|
|
want = "Starting blockchain service"
|
|
if msg != want {
|
|
t.Errorf("incorrect log, expected %s, got %s", want, msg)
|
|
}
|
|
|
|
msg = hook.AllEntries()[2].Message
|
|
want = "No chainstate found on disk, initializing beacon from genesis"
|
|
if msg != want {
|
|
t.Errorf("incorrect log, expected %s, got %s", want, msg)
|
|
}
|
|
|
|
msg = hook.AllEntries()[3].Message
|
|
want = "Stopping blockchain service"
|
|
if msg != want {
|
|
t.Errorf("incorrect log, expected %s, got %s", want, msg)
|
|
}
|
|
|
|
// The context should have been canceled.
|
|
if chainService.ctx.Err() == nil {
|
|
t.Error("context was not canceled")
|
|
}
|
|
hook.Reset()
|
|
}
|