prysm-pulse/beacon-chain/slasher/service_test.go
Raul Jordan d077483577
Add V3 Suffix to All Prysm Packages (#11083)
* v3 import renamings

* tidy

* fmt

* rev

* Update beacon-chain/core/epoch/precompute/reward_penalty_test.go

* Update beacon-chain/core/helpers/validators_test.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/iface/BUILD.bazel

* Update beacon-chain/db/kv/kv.go

* Update beacon-chain/db/kv/state.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/sync/initial-sync/service.go

* fix deps

* fix bad replacements

* fix bad replacements

* change back

* gohashtree version

* fix deps

Co-authored-by: Nishant Das <nishdas93@gmail.com>
Co-authored-by: Potuz <potuz@prysmaticlabs.com>
2022-08-16 12:20:13 +00:00

68 lines
2.2 KiB
Go

package slasher
import (
"context"
"io"
"testing"
"time"
"github.com/prysmaticlabs/prysm/v3/async/event"
mock "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed"
statefeed "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed/state"
dbtest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
mockslasher "github.com/prysmaticlabs/prysm/v3/beacon-chain/slasher/mock"
mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/testing/require"
"github.com/prysmaticlabs/prysm/v3/testing/util"
"github.com/prysmaticlabs/prysm/v3/time/slots"
"github.com/sirupsen/logrus"
logTest "github.com/sirupsen/logrus/hooks/test"
)
var _ = SlashingChecker(&Service{})
var _ = SlashingChecker(&mockslasher.MockSlashingChecker{})
func TestMain(m *testing.M) {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(io.Discard)
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 := types.Slot(4)
require.NoError(t, beaconState.SetSlot(currentSlot))
mockChain := &mock.ChainService{
State: beaconState,
Slot: &currentSlot,
}
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)
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")
}