mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 04:54:05 -05:00
* Update to Go 1.23 * Update bazel version * Update rules_go * Use toolchains_protoc * Update go_honnef_go_tools * Update golang.org/x/tools * Fix violations of SA3000 * Update errcheck by re-exporting the upstream repo * Remove problematic ginkgo and gomega test helpers. Rewrote tests without these test libraries. * Update go to 1.23.5 * gofmt with go1.23.5 * Revert Patch * Unclog * Update for go 1.23 support * Fix Lint Issues * Gazelle * Fix Build * Fix Lint * no lint * Fix lint * Fix lint * Disable intrange * Preston's review --------- Co-authored-by: Preston Van Loon <preston@pvl.dev>
64 lines
2.0 KiB
Go
64 lines
2.0 KiB
Go
package slasher
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/async/event"
|
|
mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
|
|
dbtest "github.com/prysmaticlabs/prysm/v5/beacon-chain/db/testing"
|
|
"github.com/prysmaticlabs/prysm/v5/beacon-chain/startup"
|
|
mockSync "github.com/prysmaticlabs/prysm/v5/beacon-chain/sync/initial-sync/testing"
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/util"
|
|
"github.com/prysmaticlabs/prysm/v5/time/slots"
|
|
"github.com/sirupsen/logrus"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
logrus.SetOutput(io.Discard)
|
|
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
func TestService_StartStop_ChainInitialized(t *testing.T) {
|
|
slasherDB := dbtest.SetupSlasherDB(t)
|
|
hook := logTest.NewGlobal()
|
|
beaconState, err := util.NewBeaconState()
|
|
require.NoError(t, err)
|
|
currentSlot := primitives.Slot(4)
|
|
require.NoError(t, beaconState.SetSlot(currentSlot))
|
|
mockChain := &mock.ChainService{
|
|
State: beaconState,
|
|
Slot: ¤tSlot,
|
|
}
|
|
gs := startup.NewClockSynchronizer()
|
|
srv, err := New(context.Background(), &ServiceConfig{
|
|
IndexedAttestationsFeed: new(event.Feed),
|
|
BeaconBlockHeadersFeed: new(event.Feed),
|
|
StateNotifier: &mock.MockStateNotifier{},
|
|
Database: slasherDB,
|
|
HeadStateFetcher: mockChain,
|
|
SyncChecker: &mockSync.Sync{IsSyncing: false},
|
|
ClockWaiter: gs,
|
|
})
|
|
require.NoError(t, err)
|
|
go srv.Start()
|
|
time.Sleep(time.Millisecond * 100)
|
|
var vr [32]byte
|
|
require.NoError(t, gs.SetClock(startup.NewClock(time.Now(), vr)))
|
|
time.Sleep(time.Millisecond * 100)
|
|
srv.attsSlotTicker = &slots.SlotTicker{}
|
|
srv.blocksSlotTicker = &slots.SlotTicker{}
|
|
srv.pruningSlotTicker = &slots.SlotTicker{}
|
|
require.NoError(t, srv.Stop())
|
|
require.NoError(t, srv.Status())
|
|
require.LogsContain(t, hook, "received chain initialization")
|
|
}
|