mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-12 04:30:04 +00:00
Check ListValidatorBalances
response length (#7583)
* Check length * Add regression test Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
78ca8c9265
commit
544dac298a
@ -162,6 +162,10 @@ func (bs *Server) ListValidatorBalances(
|
||||
}, nil
|
||||
}
|
||||
|
||||
if end > len(res) || end < start {
|
||||
return nil, status.Error(codes.OutOfRange, "Request exceeds response length")
|
||||
}
|
||||
|
||||
return ðpb.ValidatorBalances{
|
||||
Epoch: requestedEpoch,
|
||||
Balances: res[start:end],
|
||||
|
@ -372,6 +372,33 @@ func TestServer_ListValidatorBalances_Pagination_CustomPageSizes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_ListValidatorBalances_ResponseOutOfBound(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
ctx := context.Background()
|
||||
|
||||
count := 10
|
||||
setupValidators(t, db, count)
|
||||
headState, err := db.HeadState(context.Background())
|
||||
require.NoError(t, err)
|
||||
b := testutil.NewBeaconBlock()
|
||||
gRoot, err := b.Block.HashTreeRoot()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, db.SaveGenesisBlockRoot(ctx, gRoot))
|
||||
require.NoError(t, db.SaveState(ctx, headState, gRoot))
|
||||
|
||||
bs := &Server{
|
||||
GenesisTimeFetcher: &mock.ChainService{},
|
||||
StateGen: stategen.New(db, sc),
|
||||
HeadFetcher: &mock.ChainService{
|
||||
State: headState,
|
||||
},
|
||||
}
|
||||
|
||||
req := ðpb.ListValidatorBalancesRequest{PageSize: 250, QueryFilter: ðpb.ListValidatorBalancesRequest_Epoch{Epoch: 0}, PublicKeys: [][]byte{{'a'}}}
|
||||
_, err = bs.ListValidatorBalances(context.Background(), req)
|
||||
require.ErrorContains(t, "Request exceeds response length", err)
|
||||
}
|
||||
|
||||
func TestServer_ListValidatorBalances_OutOfRange(t *testing.T) {
|
||||
db, sc := dbTest.SetupDB(t)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user