empty array instead of 404

This commit is contained in:
Arnau B
2020-12-30 12:41:53 +01:00
parent c2dd982d26
commit a32f75db78
7 changed files with 56 additions and 78 deletions

View File

@@ -35,6 +35,9 @@ type testBatchesResponse struct {
}
func (t testBatchesResponse) GetPending() (pendingItems, lastItemID uint64) {
if len(t.Batches) == 0 {
return 0, 0
}
pendingItems = t.PendingItems
lastItemID = t.Batches[len(t.Batches)-1].ItemID
return pendingItems, lastItemID
@@ -220,6 +223,13 @@ func TestGetBatches(t *testing.T) {
}
assertBatches(t, minMaxBatchNumBatches, fetchedBatches)
// Empty array
fetchedBatches = []testBatch{}
path = fmt.Sprintf("%s?slotNum=%d&minBatchNum=%d", endpoint, 1, 25)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testBatchesResponse{}, appendIter)
assert.NoError(t, err)
assertBatches(t, []testBatch{}, fetchedBatches)
// 400
// Invalid minBatchNum
path = fmt.Sprintf("%s?minBatchNum=%d", endpoint, -2)
@@ -229,10 +239,6 @@ func TestGetBatches(t *testing.T) {
path = fmt.Sprintf("%s?forgerAddr=%s", endpoint, "0xG0000001")
err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err)
// 404
path = fmt.Sprintf("%s?slotNum=%d&minBatchNum=%d", endpoint, 1, 25)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
}
func TestGetBatch(t *testing.T) {

View File

@@ -29,6 +29,9 @@ type testBidsResponse struct {
}
func (t testBidsResponse) GetPending() (pendingItems, lastItemID uint64) {
if len(t.Bids) == 0 {
return 0, 0
}
pendingItems = t.PendingItems
lastItemID = t.Bids[len(t.Bids)-1].ItemID
return pendingItems, lastItemID
@@ -127,6 +130,13 @@ func TestGetBids(t *testing.T) {
}
assertBids(t, slotNumBidderAddrBids, fetchedBids)
// Empty array
fetchedBids = []testBid{}
path = fmt.Sprintf("%s?slotNum=%d&bidderAddr=%s", endpoint, 5, tc.bids[1].Bidder.String())
err = doGoodReqPaginated(path, historydb.OrderAsc, &testBidsResponse{}, appendIter)
assert.NoError(t, err)
assertBids(t, []testBid{}, fetchedBids)
// 400
// No filters
path = fmt.Sprintf("%s?limit=%d", endpoint, limit)
@@ -140,10 +150,6 @@ func TestGetBids(t *testing.T) {
path = fmt.Sprintf("%s?bidderAddr=%s", endpoint, "0xG0000001")
err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err)
// 404
path = fmt.Sprintf("%s?slotNum=%d&bidderAddr=%s", endpoint, 5, tc.bids[1].Bidder.String())
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
}
func assertBids(t *testing.T, expected, actual []testBid) {

View File

@@ -16,6 +16,9 @@ type testCoordinatorsResponse struct {
}
func (t testCoordinatorsResponse) GetPending() (pendingItems, lastItemID uint64) {
if len(t.Coordinators) == 0 {
return 0, 0
}
pendingItems = t.PendingItems
lastItemID = t.Coordinators[len(t.Coordinators)-1].ItemID
return pendingItems, lastItemID
@@ -67,7 +70,6 @@ func TestGetCoordinators(t *testing.T) {
reversedCoordinators = append(reversedCoordinators, tc.coordinators[len(tc.coordinators)-1-i])
}
assertCoordinators(t, reversedCoordinators, fetchedCoordinators)
for _, filteredCoord := range tc.coordinators {
// By bidder
fetchedCoordinators = []historydb.CoordinatorAPI{}
@@ -87,14 +89,17 @@ func TestGetCoordinators(t *testing.T) {
assertCoordinators(t, []historydb.CoordinatorAPI{filteredCoord}, fetchedCoordinators)
}
// Empty array
fetchedCoordinators = []historydb.CoordinatorAPI{}
path = fmt.Sprintf("%s?bidderAddr=0xaa942cfcd25ad4d90a62358b0dd84f33b398262a", endpoint)
err = doGoodReqPaginated(path, historydb.OrderDesc, &testCoordinatorsResponse{}, appendIter)
assert.NoError(t, err)
assertCoordinators(t, []historydb.CoordinatorAPI{}, fetchedCoordinators)
// 400
path = fmt.Sprintf("%s?bidderAddr=0x001", endpoint)
err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err)
// 404
path = fmt.Sprintf("%s?bidderAddr=0xaa942cfcd25ad4d90a62358b0dd84f33b398262a", endpoint)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
}
func assertCoordinator(t *testing.T, expected, actual historydb.CoordinatorAPI) {

View File

@@ -43,6 +43,9 @@ type testExitsResponse struct {
}
func (t testExitsResponse) GetPending() (pendingItems, lastItemID uint64) {
if len(t.Exits) == 0 {
return 0, 0
}
pendingItems = t.PendingItems
lastItemID = t.Exits[len(t.Exits)-1].ItemID
return pendingItems, lastItemID
@@ -248,6 +251,12 @@ func TestGetExits(t *testing.T) {
err = doGoodReqPaginated(path, historydb.OrderDesc, &testExitsResponse{}, appendIter)
assert.NoError(t, err)
assertExitAPIs(t, flipedExits, fetchedExits)
// Empty array
fetchedExits = []testExit{}
path = fmt.Sprintf("%s?batchNum=999999", endpoint)
err = doGoodReqPaginated(path, historydb.OrderDesc, &testExitsResponse{}, appendIter)
assert.NoError(t, err)
assertExitAPIs(t, []testExit{}, fetchedExits)
// 400
path = fmt.Sprintf(
"%s?accountIndex=%s&hezEthereumAddress=%s",
@@ -258,13 +267,6 @@ func TestGetExits(t *testing.T) {
path = fmt.Sprintf("%s?tokenId=X", endpoint)
err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err)
// 404
path = fmt.Sprintf("%s?batchNum=999999", endpoint)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
path = fmt.Sprintf("%s?fromItem=1000999999", endpoint)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
}
func TestGetExit(t *testing.T) {

View File

@@ -215,12 +215,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error400'
'404':
description: Not found.
content:
application/json:
schema:
$ref: '#/components/schemas/Error404'
'500':
description: Internal server error.
content:
@@ -347,12 +341,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error400'
'404':
description: Not found.
content:
application/json:
schema:
$ref: '#/components/schemas/Error404'
'500':
description: Internal server error.
content:
@@ -565,12 +553,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error400'
'404':
description: Not found.
content:
application/json:
schema:
$ref: '#/components/schemas/Error404'
'500':
description: Internal server error.
content:
@@ -687,12 +669,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error400'
'404':
description: Not found.
content:
application/json:
schema:
$ref: '#/components/schemas/Error404'
'500':
description: Internal server error.
content:
@@ -850,12 +826,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error400'
'404':
description: Not found.
content:
application/json:
schema:
$ref: '#/components/schemas/Error404'
'500':
description: Internal server error.
content:
@@ -960,12 +930,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error400'
'404':
description: Not found.
content:
application/json:
schema:
$ref: '#/components/schemas/Error404'
'500':
description: Internal server error.
content:
@@ -1085,12 +1049,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error400'
'404':
description: Not found.
content:
application/json:
schema:
$ref: '#/components/schemas/Error404'
'500':
description: Internal server error.
content:

View File

@@ -88,6 +88,9 @@ type testTxsResponse struct {
}
func (t testTxsResponse) GetPending() (pendingItems, lastItemID uint64) {
if len(t.Txs) == 0 {
return 0, 0
}
pendingItems = t.PendingItems
lastItemID = t.Txs[len(t.Txs)-1].ItemID
return pendingItems, lastItemID
@@ -420,6 +423,12 @@ func TestGetHistoryTxs(t *testing.T) {
flipedTxs = append(flipedTxs, tc.txs[len(tc.txs)-1-i])
}
assertTxs(t, flipedTxs, fetchedTxs)
// Empty array
fetchedTxs = []testTx{}
path = fmt.Sprintf("%s?batchNum=999999", endpoint)
err = doGoodReqPaginated(path, historydb.OrderDesc, &testTxsResponse{}, appendIter)
assert.NoError(t, err)
assertTxs(t, []testTx{}, fetchedTxs)
// 400
path = fmt.Sprintf(
"%s?accountIndex=%s&hezEthereumAddress=%s",
@@ -430,13 +439,6 @@ func TestGetHistoryTxs(t *testing.T) {
path = fmt.Sprintf("%s?tokenId=X", endpoint)
err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err)
// 404
path = fmt.Sprintf("%s?batchNum=999999", endpoint)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
path = fmt.Sprintf("%s?fromItem=1000999999", endpoint)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
}
func TestGetHistoryTx(t *testing.T) {