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"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/async/event"
|
|
|
|
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
|
|
|
|
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
|
|
|
|
dbtest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
2022-01-26 14:48:20 +00:00
|
|
|
mockslasher "github.com/prysmaticlabs/prysm/beacon-chain/slasher/mock"
|
2021-09-29 18:17:37 +00:00
|
|
|
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
|
2022-04-29 14:32:11 +00:00
|
|
|
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
2021-09-29 18:17:37 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/util"
|
|
|
|
"github.com/prysmaticlabs/prysm/time/slots"
|
|
|
|
"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)
|
|
|
|
currentSlot := types.Slot(4)
|
|
|
|
require.NoError(t, beaconState.SetSlot(currentSlot))
|
|
|
|
mockChain := &mock.ChainService{
|
|
|
|
State: beaconState,
|
|
|
|
Slot: ¤tSlot,
|
|
|
|
}
|
|
|
|
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},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
go srv.Start()
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
|
|
|
srv.serviceCfg.StateNotifier.StateFeed().Send(&feed.Event{
|
|
|
|
Type: statefeed.Initialized,
|
|
|
|
Data: &statefeed.InitializedData{StartTime: time.Now()},
|
|
|
|
})
|
|
|
|
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
|
|
|
}
|