Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check ListValidatorBalances response length #7583

Merged
merged 4 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions beacon-chain/rpc/beacon/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 &ethpb.ValidatorBalances{
Epoch: requestedEpoch,
Balances: res[start:end],
Expand Down
27 changes: 27 additions & 0 deletions beacon-chain/rpc/beacon/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := &ethpb.ListValidatorBalancesRequest{PageSize: 250, QueryFilter: &ethpb.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)

Expand Down