mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
v1alpha1 validators: catch possible reqState nil case (#9275)
* v1alpha1 validators: catch possible reqState nil case * Minor format of error log Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl>
This commit is contained in:
parent
14d0d9195f
commit
a8c49c50ad
@ -228,6 +228,9 @@ func (bs *Server) ListValidators(
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not get requested state: %v", err)
|
||||
}
|
||||
if reqState == nil || reqState.IsNil() {
|
||||
return nil, status.Error(codes.Internal, "Requested state is nil")
|
||||
}
|
||||
|
||||
s, err := helpers.StartSlot(requestedEpoch)
|
||||
if err != nil {
|
||||
|
@ -433,6 +433,40 @@ func TestServer_ListValidators_CannotRequestFutureEpoch(t *testing.T) {
|
||||
assert.ErrorContains(t, wanted, err)
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_reqStateIsNil(t *testing.T) {
|
||||
beaconDB := dbTest.SetupDB(t)
|
||||
secondsPerEpoch := params.BeaconConfig().SecondsPerSlot * uint64(params.BeaconConfig().SlotsPerEpoch)
|
||||
bs := &Server{
|
||||
BeaconDB: beaconDB,
|
||||
GenesisTimeFetcher: &mock.ChainService{
|
||||
// We are in epoch 1.
|
||||
Genesis: time.Now().Add(time.Duration(-1*int64(secondsPerEpoch)) * time.Second),
|
||||
},
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: nil,
|
||||
},
|
||||
StateGen: &stategen.MockStateManager{
|
||||
StatesBySlot: map[types.Slot]state.BeaconState{
|
||||
0: nil,
|
||||
},
|
||||
},
|
||||
}
|
||||
// request uses HeadFetcher to get reqState.
|
||||
req1 := ðpb.ListValidatorsRequest{PageToken: strconv.Itoa(1), PageSize: 100}
|
||||
wanted := "Requested state is nil"
|
||||
_, err := bs.ListValidators(context.Background(), req1)
|
||||
assert.ErrorContains(t, wanted, err)
|
||||
|
||||
// request uses StateGen to get reqState.
|
||||
req2 := ðpb.ListValidatorsRequest{
|
||||
QueryFilter: ðpb.ListValidatorsRequest_Genesis{},
|
||||
PageToken: strconv.Itoa(1),
|
||||
PageSize: 100,
|
||||
}
|
||||
_, err = bs.ListValidators(context.Background(), req2)
|
||||
assert.ErrorContains(t, wanted, err)
|
||||
}
|
||||
|
||||
func TestServer_ListValidators_NoResults(t *testing.T) {
|
||||
beaconDB := dbTest.SetupDB(t)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user