mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Update API to return empty next page token on last page response (#4176)
* Update API to return empty next page token on last page response * Update tests * Merge branch 'master' into api-return-empty-page-token-on-last-page
This commit is contained in:
committed by
prylabs-bulldozer[bot]
parent
8e4022f8aa
commit
a2d4701f6e
@@ -513,7 +513,7 @@ func TestServer_ListAssignments_CanFilterPubkeysIndices_WithPagination(t *testin
|
||||
wantedRes = ðpb.ValidatorAssignments{
|
||||
Assignments: assignments,
|
||||
TotalSize: int32(len(req.Indices)),
|
||||
NextPageToken: "2",
|
||||
NextPageToken: "",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(res, wantedRes) {
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestServer_ListAttestations_Genesis(t *testing.T) {
|
||||
}
|
||||
wanted := ðpb.ListAttestationsResponse{
|
||||
Attestations: []*ethpb.Attestation{att},
|
||||
NextPageToken: "1",
|
||||
NextPageToken: "",
|
||||
TotalSize: 1,
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ func TestServer_ListAttestations_Pagination_CustomPageParameters(t *testing.T) {
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
CustodyBits: bitfield.NewBitlist(1)},
|
||||
},
|
||||
NextPageToken: strconv.Itoa(34),
|
||||
NextPageToken: "",
|
||||
TotalSize: int32(count)}},
|
||||
{
|
||||
req: ðpb.ListAttestationsRequest{
|
||||
|
||||
@@ -174,7 +174,7 @@ func TestServer_ListBlocks_Pagination(t *testing.T) {
|
||||
PageSize: 3},
|
||||
res: ðpb.ListBlocksResponse{
|
||||
BlockContainers: []*ethpb.BeaconBlockContainer{{Block: ðpb.BeaconBlock{Slot: 5}, BlockRoot: blkContainers[5].BlockRoot}},
|
||||
NextPageToken: strconv.Itoa(1),
|
||||
NextPageToken: "",
|
||||
TotalSize: 1}},
|
||||
{req: ðpb.ListBlocksRequest{
|
||||
PageToken: strconv.Itoa(0),
|
||||
@@ -193,7 +193,7 @@ func TestServer_ListBlocks_Pagination(t *testing.T) {
|
||||
PageSize: 100},
|
||||
res: ðpb.ListBlocksResponse{
|
||||
BlockContainers: blkContainers[0:params.BeaconConfig().SlotsPerEpoch],
|
||||
NextPageToken: strconv.Itoa(1),
|
||||
NextPageToken: "",
|
||||
TotalSize: int32(params.BeaconConfig().SlotsPerEpoch)}},
|
||||
{req: ðpb.ListBlocksRequest{
|
||||
PageToken: strconv.Itoa(1),
|
||||
@@ -201,7 +201,7 @@ func TestServer_ListBlocks_Pagination(t *testing.T) {
|
||||
PageSize: 3},
|
||||
res: ðpb.ListBlocksResponse{
|
||||
BlockContainers: blkContainers[43:46],
|
||||
NextPageToken: strconv.Itoa(2),
|
||||
NextPageToken: "2",
|
||||
TotalSize: int32(params.BeaconConfig().SlotsPerEpoch)}},
|
||||
{req: ðpb.ListBlocksRequest{
|
||||
PageToken: strconv.Itoa(1),
|
||||
@@ -209,7 +209,7 @@ func TestServer_ListBlocks_Pagination(t *testing.T) {
|
||||
PageSize: 7},
|
||||
res: ðpb.ListBlocksResponse{
|
||||
BlockContainers: blkContainers[95:96],
|
||||
NextPageToken: strconv.Itoa(2),
|
||||
NextPageToken: "",
|
||||
TotalSize: int32(params.BeaconConfig().SlotsPerEpoch)}},
|
||||
{req: ðpb.ListBlocksRequest{
|
||||
PageToken: strconv.Itoa(0),
|
||||
@@ -217,7 +217,7 @@ func TestServer_ListBlocks_Pagination(t *testing.T) {
|
||||
PageSize: 4},
|
||||
res: ðpb.ListBlocksResponse{
|
||||
BlockContainers: blkContainers[96:100],
|
||||
NextPageToken: strconv.Itoa(1),
|
||||
NextPageToken: "1",
|
||||
TotalSize: int32(params.BeaconConfig().SlotsPerEpoch / 2)}},
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ func TestServer_ListBlocks_Pagination(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !proto.Equal(res, test.res) {
|
||||
t.Errorf("Incorrect blocks response, wanted %d, received %d", len(test.res.BlockContainers), len(res.BlockContainers))
|
||||
t.Errorf("Incorrect blocks response, wanted %v, received %v", test.res, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ func TestServer_ListBeaconCommittees_FromArchive(t *testing.T) {
|
||||
Epoch: 0,
|
||||
Committees: wanted,
|
||||
ActiveValidatorCount: uint64(numValidators),
|
||||
NextPageToken: strconv.Itoa(1),
|
||||
NextPageToken: "",
|
||||
TotalSize: int32(len(wanted)),
|
||||
}
|
||||
if !reflect.DeepEqual(wantedRes, res1) {
|
||||
|
||||
@@ -248,7 +248,7 @@ func TestServer_ListValidatorBalances_Pagination_Default(t *testing.T) {
|
||||
Balances: []*ethpb.ValidatorBalances_Balance{
|
||||
{Index: 99, PublicKey: []byte{99}, Balance: 99},
|
||||
},
|
||||
NextPageToken: strconv.Itoa(1),
|
||||
NextPageToken: "",
|
||||
TotalSize: 1,
|
||||
},
|
||||
},
|
||||
@@ -259,7 +259,7 @@ func TestServer_ListValidatorBalances_Pagination_Default(t *testing.T) {
|
||||
{Index: 2, PublicKey: []byte{2}, Balance: 2},
|
||||
{Index: 3, PublicKey: []byte{3}, Balance: 3},
|
||||
},
|
||||
NextPageToken: strconv.Itoa(1),
|
||||
NextPageToken: "",
|
||||
TotalSize: 3,
|
||||
},
|
||||
},
|
||||
@@ -270,7 +270,7 @@ func TestServer_ListValidatorBalances_Pagination_Default(t *testing.T) {
|
||||
{Index: 11, PublicKey: []byte{11}, Balance: 11},
|
||||
{Index: 12, PublicKey: []byte{12}, Balance: 12},
|
||||
},
|
||||
NextPageToken: strconv.Itoa(1),
|
||||
NextPageToken: "",
|
||||
TotalSize: 3,
|
||||
}},
|
||||
{req: ðpb.ListValidatorBalancesRequest{PublicKeys: [][]byte{{2}, {3}}, Indices: []uint64{3, 4}}, // Duplication
|
||||
@@ -280,7 +280,7 @@ func TestServer_ListValidatorBalances_Pagination_Default(t *testing.T) {
|
||||
{Index: 3, PublicKey: []byte{3}, Balance: 3},
|
||||
{Index: 4, PublicKey: []byte{4}, Balance: 4},
|
||||
},
|
||||
NextPageToken: strconv.Itoa(1),
|
||||
NextPageToken: "",
|
||||
TotalSize: 3,
|
||||
}},
|
||||
{req: ðpb.ListValidatorBalancesRequest{PublicKeys: [][]byte{{}}, Indices: []uint64{3, 4}}, // Public key has a blank value
|
||||
@@ -289,7 +289,7 @@ func TestServer_ListValidatorBalances_Pagination_Default(t *testing.T) {
|
||||
{Index: 3, PublicKey: []byte{3}, Balance: 3},
|
||||
{Index: 4, PublicKey: []byte{4}, Balance: 4},
|
||||
},
|
||||
NextPageToken: strconv.Itoa(1),
|
||||
NextPageToken: "",
|
||||
TotalSize: 2,
|
||||
}},
|
||||
}
|
||||
@@ -351,7 +351,7 @@ func TestServer_ListValidatorBalances_Pagination_CustomPageSizes(t *testing.T) {
|
||||
{PublicKey: []byte{100}, Index: 100, Balance: uint64(100)},
|
||||
{PublicKey: []byte{101}, Index: 101, Balance: uint64(101)},
|
||||
},
|
||||
NextPageToken: strconv.Itoa(34),
|
||||
NextPageToken: "34",
|
||||
TotalSize: int32(count)}},
|
||||
{req: ðpb.ListValidatorBalancesRequest{PageSize: 2},
|
||||
res: ðpb.ValidatorBalances{
|
||||
@@ -663,7 +663,7 @@ func TestServer_ListValidators_Pagination(t *testing.T) {
|
||||
res: ðpb.Validators{
|
||||
Validators: []*ethpb.Validator{
|
||||
{PublicKey: []byte{99}}},
|
||||
NextPageToken: strconv.Itoa(34),
|
||||
NextPageToken: "",
|
||||
TotalSize: int32(count)}},
|
||||
{req: ðpb.ListValidatorsRequest{PageSize: 2},
|
||||
res: ðpb.Validators{
|
||||
@@ -679,7 +679,7 @@ func TestServer_ListValidators_Pagination(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !proto.Equal(res, test.res) {
|
||||
t.Error("Incorrect respond of validators")
|
||||
t.Errorf("Incorrect validator response, wanted %v, received %v", test.res, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func StartAndEndPage(pageToken string, pageSize int, totalSize int) (int, int, s
|
||||
return 0, 0, "", errors.Wrap(err, "could not convert page token")
|
||||
}
|
||||
|
||||
// Start page can not be greater than validator size.
|
||||
// Start page can not be greater than set size.
|
||||
start := token * pageSize
|
||||
if start >= totalSize {
|
||||
return 0, 0, "", fmt.Errorf("page start %d >= list %d", start, totalSize)
|
||||
@@ -31,10 +31,12 @@ func StartAndEndPage(pageToken string, pageSize int, totalSize int) (int, int, s
|
||||
|
||||
// End page can not go out of bound.
|
||||
end := start + pageSize
|
||||
nextPageToken := strconv.Itoa(token + 1)
|
||||
|
||||
if end > totalSize {
|
||||
end = totalSize
|
||||
nextPageToken = "" // Return an empty next page token for the last page of a set
|
||||
}
|
||||
|
||||
nextPageToken := strconv.Itoa(token + 1)
|
||||
return start, end, nextPageToken, nil
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestStartAndEndPage(t *testing.T) {
|
||||
token: "3",
|
||||
pageSize: 33,
|
||||
totalSize: 100,
|
||||
nextToken: "4",
|
||||
nextToken: "",
|
||||
start: 99,
|
||||
end: 100,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user