2021-09-29 18:17:37 +00:00
|
|
|
package slasher
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-04-18 20:42:07 +00:00
|
|
|
"io"
|
2021-09-29 18:17:37 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/async/event"
|
|
|
|
mock "github.com/prysmaticlabs/prysm/v4/beacon-chain/blockchain/testing"
|
|
|
|
dbtest "github.com/prysmaticlabs/prysm/v4/beacon-chain/db/testing"
|
|
|
|
mockslasher "github.com/prysmaticlabs/prysm/v4/beacon-chain/slasher/mock"
|
2023-05-03 04:34:01 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/startup"
|
2023-03-17 18:52:56 +00:00
|
|
|
mockSync "github.com/prysmaticlabs/prysm/v4/beacon-chain/sync/initial-sync/testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/util"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/time/slots"
|
2021-09-29 18:17:37 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = SlashingChecker(&Service{})
|
2022-01-26 14:48:20 +00:00
|
|
|
var _ = SlashingChecker(&mockslasher.MockSlashingChecker{})
|
2021-09-29 18:17:37 +00:00
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
2022-04-18 20:42:07 +00:00
|
|
|
logrus.SetOutput(io.Discard)
|
2021-09-29 18:17:37 +00:00
|
|
|
|
|
|
|
m.Run()
|
|
|
|
}
|
|
|
|
|
2021-12-06 21:45:38 +00:00
|
|
|
func TestService_StartStop_ChainInitialized(t *testing.T) {
|
2021-09-29 18:17:37 +00:00
|
|
|
slasherDB := dbtest.SetupSlasherDB(t)
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
beaconState, err := util.NewBeaconState()
|
|
|
|
require.NoError(t, err)
|
2023-01-26 14:40:12 +00:00
|
|
|
currentSlot := primitives.Slot(4)
|
2021-09-29 18:17:37 +00:00
|
|
|
require.NoError(t, beaconState.SetSlot(currentSlot))
|
|
|
|
mockChain := &mock.ChainService{
|
|
|
|
State: beaconState,
|
|
|
|
Slot: ¤tSlot,
|
|
|
|
}
|
2023-05-03 04:34:01 +00:00
|
|
|
gs := startup.NewClockSynchronizer()
|
2021-09-29 18:17:37 +00:00
|
|
|
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},
|
2023-05-03 04:34:01 +00:00
|
|
|
ClockWaiter: gs,
|
2021-09-29 18:17:37 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
go srv.Start()
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
2023-05-03 04:34:01 +00:00
|
|
|
var vr [32]byte
|
|
|
|
require.NoError(t, gs.SetClock(startup.NewClock(time.Now(), vr)))
|
2021-09-29 18:17:37 +00:00
|
|
|
time.Sleep(time.Millisecond * 100)
|
2021-10-03 07:49:01 +00:00
|
|
|
srv.attsSlotTicker = &slots.SlotTicker{}
|
|
|
|
srv.blocksSlotTicker = &slots.SlotTicker{}
|
|
|
|
srv.pruningSlotTicker = &slots.SlotTicker{}
|
2021-09-29 18:17:37 +00:00
|
|
|
require.NoError(t, srv.Stop())
|
|
|
|
require.NoError(t, srv.Status())
|
2021-12-06 21:45:38 +00:00
|
|
|
require.LogsContain(t, hook, "received chain initialization")
|
2021-09-29 18:17:37 +00:00
|
|
|
}
|