Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rkapka committed Jan 16, 2025
1 parent bac79af commit 8341140
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 19 deletions.
7 changes: 5 additions & 2 deletions beacon-chain/blockchain/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func setupBeaconChain(t *testing.T, beaconDB db.Database) *Service {
DepositContainers: []*ethpb.DepositContainer{},
})
require.NoError(t, err)

clockSync := startup.NewClockSynchronizer()

web3Service, err = execution.NewService(
ctx,
execution.WithDatabase(beaconDB),
Expand All @@ -95,15 +98,15 @@ func setupBeaconChain(t *testing.T, beaconDB db.Database) *Service {
WithDepositCache(depositCache),
WithChainStartFetcher(web3Service),
WithAttestationPool(attestations.NewPool()),
WithSlashingPool(slashings.NewPool(false)),
WithSlashingPool(slashings.NewPool(ctx, clockSync)),
WithExitPool(voluntaryexits.NewPool()),
WithP2PBroadcaster(&mockBroadcaster{}),
WithStateNotifier(&mockBeaconNode{}),
WithForkChoiceStore(fc),
WithAttestationService(attService),
WithStateGen(stateGen),
WithPayloadIDCache(cache.NewPayloadIDCache()),
WithClockSynchronizer(startup.NewClockSynchronizer()),
WithClockSynchronizer(clockSync),
}

chainService, err := NewService(ctx, opts...)
Expand Down
1 change: 1 addition & 0 deletions beacon-chain/rpc/prysm/v1alpha1/beacon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ go_test(
"//beacon-chain/operations/slashings:go_default_library",
"//beacon-chain/p2p/testing:go_default_library",
"//beacon-chain/rpc/core:go_default_library",
"//beacon-chain/startup:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/state-native:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
Expand Down
11 changes: 6 additions & 5 deletions beacon-chain/rpc/prysm/v1alpha1/beacon/slashings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
mock "github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/slashings"
mockp2p "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/startup"
"github.com/prysmaticlabs/prysm/v5/config/features"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
Expand All @@ -31,7 +32,7 @@ func TestServer_SubmitProposerSlashing(t *testing.T) {
HeadFetcher: &mock.ChainService{
State: st,
},
SlashingsPool: slashings.NewPool(false),
SlashingsPool: slashings.NewPool(ctx, startup.NewClockSynchronizer()),
Broadcaster: mb,
}

Expand Down Expand Up @@ -61,7 +62,7 @@ func TestServer_SubmitAttesterSlashing(t *testing.T) {
HeadFetcher: &mock.ChainService{
State: st,
},
SlashingsPool: slashings.NewPool(false),
SlashingsPool: slashings.NewPool(ctx, startup.NewClockSynchronizer()),
Broadcaster: mb,
}

Expand Down Expand Up @@ -92,7 +93,7 @@ func TestServer_SubmitProposerSlashing_DontBroadcast(t *testing.T) {
HeadFetcher: &mock.ChainService{
State: st,
},
SlashingsPool: slashings.NewPool(false),
SlashingsPool: slashings.NewPool(ctx, startup.NewClockSynchronizer()),
Broadcaster: mb,
}

Expand Down Expand Up @@ -139,7 +140,7 @@ func TestServer_SubmitAttesterSlashing_DontBroadcast(t *testing.T) {
HeadFetcher: &mock.ChainService{
State: st,
},
SlashingsPool: slashings.NewPool(false),
SlashingsPool: slashings.NewPool(ctx, startup.NewClockSynchronizer()),
Broadcaster: mb,
}

Expand Down Expand Up @@ -180,7 +181,7 @@ func TestServer_SubmitAttesterSlashingElectra(t *testing.T) {
HeadFetcher: &mock.ChainService{
State: st,
},
SlashingsPool: slashings.NewPool(false),
SlashingsPool: slashings.NewPool(ctx, startup.NewClockSynchronizer()),
Broadcaster: mb,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/slashings"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/startup"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
Expand All @@ -13,10 +14,12 @@ import (
)

func TestServer_getSlashings(t *testing.T) {
ctx := context.Background()

beaconState, privKeys := util.DeterministicGenesisState(t, 64)

proposerServer := &Server{
SlashingsPool: slashings.NewPool(false),
SlashingsPool: slashings.NewPool(ctx, startup.NewClockSynchronizer()),
}

proposerSlashings := make([]*ethpb.ProposerSlashing, params.BeaconConfig().MaxProposerSlashings)
Expand Down
19 changes: 10 additions & 9 deletions beacon-chain/rpc/prysm/v1alpha1/validator/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/voluntaryexits"
mockp2p "github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/testutil"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/startup"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state/stategen"
Expand Down Expand Up @@ -90,7 +91,7 @@ func TestServer_GetBeaconBlock_Phase0(t *testing.T) {
require.NoError(t, db.SaveState(ctx, beaconState, parentRoot), "Could not save genesis state")
require.NoError(t, db.SaveHeadBlockRoot(ctx, parentRoot), "Could not save genesis state")

proposerServer := getProposerServer(db, beaconState, parentRoot[:])
proposerServer := getProposerServer(ctx, db, beaconState, parentRoot[:])

randaoReveal, err := util.RandaoReveal(beaconState, 0, privKeys)
require.NoError(t, err)
Expand Down Expand Up @@ -162,7 +163,7 @@ func TestServer_GetBeaconBlock_Altair(t *testing.T) {
require.NoError(t, db.SaveState(ctx, beaconState, blkRoot), "Could not save genesis state")
require.NoError(t, db.SaveHeadBlockRoot(ctx, blkRoot), "Could not save genesis state")

proposerServer := getProposerServer(db, beaconState, parentRoot[:])
proposerServer := getProposerServer(ctx, db, beaconState, parentRoot[:])

randaoReveal, err := util.RandaoReveal(beaconState, 0, privKeys)
require.NoError(t, err)
Expand Down Expand Up @@ -275,7 +276,7 @@ func TestServer_GetBeaconBlock_Bellatrix(t *testing.T) {
Timestamp: uint64(timeStamp.Unix()),
}

proposerServer := getProposerServer(db, beaconState, parentRoot[:])
proposerServer := getProposerServer(ctx, db, beaconState, parentRoot[:])
proposerServer.Eth1BlockFetcher = c
ed, err := blocks.NewWrappedExecutionData(payload)
require.NoError(t, err)
Expand Down Expand Up @@ -401,7 +402,7 @@ func TestServer_GetBeaconBlock_Capella(t *testing.T) {
Withdrawals: make([]*enginev1.Withdrawal, 0),
}

proposerServer := getProposerServer(db, beaconState, parentRoot[:])
proposerServer := getProposerServer(ctx, db, beaconState, parentRoot[:])
ed, err := blocks.NewWrappedExecutionData(payload)
require.NoError(t, err)
proposerServer.ExecutionEngineCaller = &mockExecution.EngineClient{
Expand Down Expand Up @@ -524,7 +525,7 @@ func TestServer_GetBeaconBlock_Deneb(t *testing.T) {
proofs := [][]byte{[]byte("proof"), []byte("proof1"), []byte("proof2")}
blobs := [][]byte{[]byte("blob"), []byte("blob1"), []byte("blob2")}
bundle := &enginev1.BlobsBundle{KzgCommitments: kc, Proofs: proofs, Blobs: blobs}
proposerServer := getProposerServer(db, beaconState, parentRoot[:])
proposerServer := getProposerServer(ctx, db, beaconState, parentRoot[:])
proposerServer.ExecutionEngineCaller = &mockExecution.EngineClient{
PayloadIDBytes: &enginev1.PayloadIDBytes{1},
GetPayloadResponse: &blocks.GetPayloadResponse{
Expand Down Expand Up @@ -657,7 +658,7 @@ func TestServer_GetBeaconBlock_Electra(t *testing.T) {
BaseFeePerGas: make([]byte, fieldparams.RootLength),
BlockHash: make([]byte, fieldparams.RootLength),
}
proposerServer := getProposerServer(db, beaconState, parentRoot[:])
proposerServer := getProposerServer(ctx, db, beaconState, parentRoot[:])
ed, err := blocks.NewWrappedExecutionData(payload)
require.NoError(t, err)
proposerServer.ExecutionEngineCaller = &mockExecution.EngineClient{
Expand Down Expand Up @@ -782,7 +783,7 @@ func TestServer_GetBeaconBlock_Fulu(t *testing.T) {
BaseFeePerGas: make([]byte, fieldparams.RootLength),
BlockHash: make([]byte, fieldparams.RootLength),
}
proposerServer := getProposerServer(db, beaconState, parentRoot[:])
proposerServer := getProposerServer(ctx, db, beaconState, parentRoot[:])
ed, err := blocks.NewWrappedExecutionData(payload)
require.NoError(t, err)
proposerServer.ExecutionEngineCaller = &mockExecution.EngineClient{
Expand Down Expand Up @@ -832,7 +833,7 @@ func TestServer_GetBeaconBlock_Optimistic(t *testing.T) {
require.ErrorContains(t, errOptimisticMode.Error(), err)
}

func getProposerServer(db db.HeadAccessDatabase, headState state.BeaconState, headRoot []byte) *Server {
func getProposerServer(ctx context.Context, db db.HeadAccessDatabase, headState state.BeaconState, headRoot []byte) *Server {
mockChainService := &mock.ChainService{State: headState, Root: headRoot, ForkChoiceStore: doublylinkedtree.New()}
return &Server{
HeadFetcher: mockChainService,
Expand All @@ -846,7 +847,7 @@ func getProposerServer(db db.HeadAccessDatabase, headState state.BeaconState, he
ForkchoiceFetcher: mockChainService,
MockEth1Votes: true,
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(false),
SlashingsPool: slashings.NewPool(ctx, startup.NewClockSynchronizer()),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db, doublylinkedtree.New()),
SyncCommitteePool: synccommittee.NewStore(),
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/sync/subscriber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestSubscribe_ReceivesAttesterSlashing(t *testing.T) {
cfg: &config{
p2p: p2pService,
initialSync: &mockSync.Sync{IsSyncing: false},
slashingPool: slashings.NewPool(false),
slashingPool: slashings.NewPool(ctx, startup.NewClockSynchronizer()),
chain: chainService,
clock: startup.NewClock(gt, vr),
beaconDB: d,
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestSubscribe_ReceivesProposerSlashing(t *testing.T) {
cfg: &config{
p2p: p2pService,
initialSync: &mockSync.Sync{IsSyncing: false},
slashingPool: slashings.NewPool(false),
slashingPool: slashings.NewPool(ctx, startup.NewClockSynchronizer()),
chain: chainService,
beaconDB: d,
clock: startup.NewClock(chainService.Genesis, chainService.ValidatorsRoot),
Expand Down

0 comments on commit 8341140

Please sign in to comment.