Browse Source

Merge pull request #336 from hermeznetwork/fix/api1

Fix/api1
feature/sql-semaphore1
laisolizq 4 years ago
committed by GitHub
parent
commit
d5f579aec5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 69 additions and 81 deletions
  1. +6
    -6
      api/account_test.go
  2. +2
    -9
      api/api_test.go
  3. +7
    -7
      api/batch_test.go
  4. +5
    -5
      api/bids_test.go
  5. +1
    -1
      api/coordinator_test.go
  6. +10
    -10
      api/exits_test.go
  7. +0
    -5
      api/parsers.go
  8. +9
    -6
      api/slots.go
  9. +12
    -12
      api/slots_test.go
  10. +6
    -6
      api/token_test.go
  11. +10
    -10
      api/txshistory_test.go
  12. +1
    -1
      db/l2db/l2db_test.go
  13. +0
    -3
      db/migrations/0001.sql

+ 6
- 6
api/account_test.go

@ -74,40 +74,40 @@ func TestGetAccounts(t *testing.T) {
stringIds := strconv.Itoa(int(tc.tokens[2].TokenID)) + "," + strconv.Itoa(int(tc.tokens[5].TokenID)) + "," + strconv.Itoa(int(tc.tokens[6].TokenID))
// Filter by BJJ
path := fmt.Sprintf("%s?BJJ=%s&limit=%d&fromItem=", endpoint, tc.accounts[0].PublicKey, limit)
path := fmt.Sprintf("%s?BJJ=%s&limit=%d", endpoint, tc.accounts[0].PublicKey, limit)
err := doGoodReqPaginated(path, historydb.OrderAsc, &testAccountsResponse{}, appendIter)
assert.NoError(t, err)
assert.Greater(t, len(fetchedAccounts), 0)
assert.LessOrEqual(t, len(fetchedAccounts), len(tc.accounts))
fetchedAccounts = []testAccount{}
// Filter by ethAddr
path = fmt.Sprintf("%s?hermezEthereumAddress=%s&limit=%d&fromItem=", endpoint, tc.accounts[3].EthAddr, limit)
path = fmt.Sprintf("%s?hermezEthereumAddress=%s&limit=%d", endpoint, tc.accounts[3].EthAddr, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testAccountsResponse{}, appendIter)
assert.NoError(t, err)
assert.Greater(t, len(fetchedAccounts), 0)
assert.LessOrEqual(t, len(fetchedAccounts), len(tc.accounts))
fetchedAccounts = []testAccount{}
// both filters (incompatible)
path = fmt.Sprintf("%s?hermezEthereumAddress=%s&BJJ=%s&limit=%d&fromItem=", endpoint, tc.accounts[0].EthAddr, tc.accounts[0].PublicKey, limit)
path = fmt.Sprintf("%s?hermezEthereumAddress=%s&BJJ=%s&limit=%d", endpoint, tc.accounts[0].EthAddr, tc.accounts[0].PublicKey, limit)
err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err)
fetchedAccounts = []testAccount{}
// Filter by token IDs
path = fmt.Sprintf("%s?tokenIds=%s&limit=%d&fromItem=", endpoint, stringIds, limit)
path = fmt.Sprintf("%s?tokenIds=%s&limit=%d", endpoint, stringIds, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testAccountsResponse{}, appendIter)
assert.NoError(t, err)
assert.Greater(t, len(fetchedAccounts), 0)
assert.LessOrEqual(t, len(fetchedAccounts), len(tc.accounts))
fetchedAccounts = []testAccount{}
// Token Ids + bjj
path = fmt.Sprintf("%s?tokenIds=%s&BJJ=%s&limit=%d&fromItem=", endpoint, stringIds, tc.accounts[10].PublicKey, limit)
path = fmt.Sprintf("%s?tokenIds=%s&BJJ=%s&limit=%d", endpoint, stringIds, tc.accounts[10].PublicKey, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testAccountsResponse{}, appendIter)
assert.NoError(t, err)
assert.Greater(t, len(fetchedAccounts), 0)
assert.LessOrEqual(t, len(fetchedAccounts), len(tc.accounts))
fetchedAccounts = []testAccount{}
// No filters (checks response content)
path = fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit)
path = fmt.Sprintf("%s?limit=%d", endpoint, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testAccountsResponse{}, appendIter)
assert.NoError(t, err)
assert.Equal(t, len(tc.accounts), len(fetchedAccounts))

+ 2
- 9
api/api_test.go

@ -456,15 +456,8 @@ func doGoodReqPaginated(
for {
// Calculate fromItem
iterPath := path
if firstIte {
if order == historydb.OrderDesc {
// Fetch first item in reverse order
iterPath += "99999" // Asumption that for testing there won't be any itemID > 99999
} else {
iterPath += "0"
}
} else {
iterPath += strconv.Itoa(int(next))
if !firstIte {
iterPath += "&fromItem=" + strconv.Itoa(int(next))
}
// Call API to get this iteration items
iterStruct = iterStruct.New()

+ 7
- 7
api/batch_test.go

@ -119,7 +119,7 @@ func TestGetBatches(t *testing.T) {
}
// Get all (no filters)
limit := 3
path := fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit)
path := fmt.Sprintf("%s?limit=%d", endpoint, limit)
err := doGoodReqPaginated(path, historydb.OrderAsc, &testBatchesResponse{}, appendIter)
assert.NoError(t, err)
assertBatches(t, tc.batches, fetchedBatches)
@ -128,7 +128,7 @@ func TestGetBatches(t *testing.T) {
fetchedBatches = []testBatch{}
limit = 2
minBatchNum := tc.batches[len(tc.batches)/2].BatchNum
path = fmt.Sprintf("%s?minBatchNum=%d&limit=%d&fromItem=", endpoint, minBatchNum, limit)
path = fmt.Sprintf("%s?minBatchNum=%d&limit=%d", endpoint, minBatchNum, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testBatchesResponse{}, appendIter)
assert.NoError(t, err)
minBatchNumBatches := []testBatch{}
@ -143,7 +143,7 @@ func TestGetBatches(t *testing.T) {
fetchedBatches = []testBatch{}
limit = 1
maxBatchNum := tc.batches[len(tc.batches)/2].BatchNum
path = fmt.Sprintf("%s?maxBatchNum=%d&limit=%d&fromItem=", endpoint, maxBatchNum, limit)
path = fmt.Sprintf("%s?maxBatchNum=%d&limit=%d", endpoint, maxBatchNum, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testBatchesResponse{}, appendIter)
assert.NoError(t, err)
maxBatchNumBatches := []testBatch{}
@ -158,7 +158,7 @@ func TestGetBatches(t *testing.T) {
fetchedBatches = []testBatch{}
limit = 5
slotNum := tc.batches[len(tc.batches)/2].SlotNum
path = fmt.Sprintf("%s?slotNum=%d&limit=%d&fromItem=", endpoint, slotNum, limit)
path = fmt.Sprintf("%s?slotNum=%d&limit=%d", endpoint, slotNum, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testBatchesResponse{}, appendIter)
assert.NoError(t, err)
slotNumBatches := []testBatch{}
@ -173,7 +173,7 @@ func TestGetBatches(t *testing.T) {
fetchedBatches = []testBatch{}
limit = 10
forgerAddr := tc.batches[len(tc.batches)/2].ForgerAddr
path = fmt.Sprintf("%s?forgerAddr=%s&limit=%d&fromItem=", endpoint, forgerAddr.String(), limit)
path = fmt.Sprintf("%s?forgerAddr=%s&limit=%d", endpoint, forgerAddr.String(), limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testBatchesResponse{}, appendIter)
assert.NoError(t, err)
forgerAddrBatches := []testBatch{}
@ -187,7 +187,7 @@ func TestGetBatches(t *testing.T) {
// All, in reverse order
fetchedBatches = []testBatch{}
limit = 6
path = fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit)
path = fmt.Sprintf("%s?limit=%d", endpoint, limit)
err = doGoodReqPaginated(path, historydb.OrderDesc, &testBatchesResponse{}, appendIter)
assert.NoError(t, err)
flippedBatches := []testBatch{}
@ -201,7 +201,7 @@ func TestGetBatches(t *testing.T) {
limit = 1
maxBatchNum = tc.batches[len(tc.batches)-len(tc.batches)/4].BatchNum
minBatchNum = tc.batches[len(tc.batches)/4].BatchNum
path = fmt.Sprintf("%s?minBatchNum=%d&maxBatchNum=%d&limit=%d&fromItem=", endpoint, minBatchNum, maxBatchNum, limit)
path = fmt.Sprintf("%s?minBatchNum=%d&maxBatchNum=%d&limit=%d", endpoint, minBatchNum, maxBatchNum, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testBatchesResponse{}, appendIter)
assert.NoError(t, err)
minMaxBatchNumBatches := []testBatch{}

+ 5
- 5
api/bids_test.go

@ -76,7 +76,7 @@ func TestGetBids(t *testing.T) {
// bidderAddress
fetchedBids = []testBid{}
bidderAddress := tc.bids[3].Bidder
path := fmt.Sprintf("%s?bidderAddr=%s&limit=%d&fromItem=", endpoint, bidderAddress.String(), limit)
path := fmt.Sprintf("%s?bidderAddr=%s&limit=%d", endpoint, bidderAddress.String(), limit)
err := doGoodReqPaginated(path, historydb.OrderAsc, &testBidsResponse{}, appendIter)
assert.NoError(t, err)
bidderAddrBids := []testBid{}
@ -90,7 +90,7 @@ func TestGetBids(t *testing.T) {
// slotNum
fetchedBids = []testBid{}
slotNum := tc.bids[3].SlotNum
path = fmt.Sprintf("%s?slotNum=%d&limit=%d&fromItem=", endpoint, slotNum, limit)
path = fmt.Sprintf("%s?slotNum=%d&limit=%d", endpoint, slotNum, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testBidsResponse{}, appendIter)
assert.NoError(t, err)
slotNumBids := []testBid{}
@ -103,7 +103,7 @@ func TestGetBids(t *testing.T) {
// slotNum, in reverse order
fetchedBids = []testBid{}
path = fmt.Sprintf("%s?slotNum=%d&limit=%d&fromItem=", endpoint, slotNum, limit)
path = fmt.Sprintf("%s?slotNum=%d&limit=%d", endpoint, slotNum, limit)
err = doGoodReqPaginated(path, historydb.OrderDesc, &testBidsResponse{}, appendIter)
assert.NoError(t, err)
flippedBids := []testBid{}
@ -116,7 +116,7 @@ func TestGetBids(t *testing.T) {
fetchedBids = []testBid{}
bidderAddress = tc.bids[1].Bidder
slotNum = tc.bids[1].SlotNum
path = fmt.Sprintf("%s?bidderAddr=%s&slotNum=%d&limit=%d&fromItem=", endpoint, bidderAddress.String(), slotNum, limit)
path = fmt.Sprintf("%s?bidderAddr=%s&slotNum=%d&limit=%d", endpoint, bidderAddress.String(), slotNum, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testBidsResponse{}, appendIter)
assert.NoError(t, err)
slotNumBidderAddrBids := []testBid{}
@ -129,7 +129,7 @@ func TestGetBids(t *testing.T) {
// 400
// No filters
path = fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit)
path = fmt.Sprintf("%s?limit=%d", endpoint, limit)
err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err)
// Invalid slotNum

+ 1
- 1
api/coordinator_test.go

@ -53,7 +53,7 @@ func TestGetCoordinators(t *testing.T) {
// All
limit := 5
path := fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit)
path := fmt.Sprintf("%s?limit=%d", endpoint, limit)
err := doGoodReqPaginated(path, historydb.OrderAsc, &testCoordinatorsResponse{}, appendIter)
assert.NoError(t, err)
assertCoordinators(t, tc.coordinators, fetchedCoordinators)

+ 10
- 10
api/exits_test.go

@ -100,7 +100,7 @@ func TestGetExits(t *testing.T) {
}
// Get all (no filters)
limit := 8
path := fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit)
path := fmt.Sprintf("%s?limit=%d", endpoint, limit)
err := doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter)
assert.NoError(t, err)
assertExitAPIs(t, tc.exits, fetchedExits)
@ -124,7 +124,7 @@ func TestGetExits(t *testing.T) {
}
}
path = fmt.Sprintf(
"%s?hermezEthereumAddress=%s&limit=%d&fromItem=",
"%s?hermezEthereumAddress=%s&limit=%d",
endpoint, account.EthAddr, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter)
@ -144,7 +144,7 @@ func TestGetExits(t *testing.T) {
fetchedExits = []testExit{}
limit = 6
path = fmt.Sprintf(
"%s?BJJ=%s&limit=%d&fromItem=",
"%s?BJJ=%s&limit=%d",
endpoint, account.PublicKey, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter)
@ -155,7 +155,7 @@ func TestGetExits(t *testing.T) {
limit = 5
tokenID := tc.exits[0].Token.TokenID
path = fmt.Sprintf(
"%s?tokenId=%d&limit=%d&fromItem=",
"%s?tokenId=%d&limit=%d",
endpoint, tokenID, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter)
@ -172,7 +172,7 @@ func TestGetExits(t *testing.T) {
limit = 4
idx := tc.exits[0].AccountIdx
path = fmt.Sprintf(
"%s?accountIndex=%s&limit=%d&fromItem=",
"%s?accountIndex=%s&limit=%d",
endpoint, idx, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter)
@ -189,7 +189,7 @@ func TestGetExits(t *testing.T) {
limit = 3
batchNum := tc.exits[0].BatchNum
path = fmt.Sprintf(
"%s?batchNum=%d&limit=%d&fromItem=",
"%s?batchNum=%d&limit=%d",
endpoint, batchNum, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter)
@ -205,7 +205,7 @@ func TestGetExits(t *testing.T) {
fetchedExits = []testExit{}
limit = 7
path = fmt.Sprintf(
"%s?&onlyPendingWithdraws=%t&limit=%d&fromItem=",
"%s?&onlyPendingWithdraws=%t&limit=%d",
endpoint, true, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter)
@ -221,7 +221,7 @@ func TestGetExits(t *testing.T) {
fetchedExits = []testExit{}
limit = 1
path = fmt.Sprintf(
"%s?batchNum=%d&tokeId=%d&limit=%d&fromItem=",
"%s?batchNum=%d&tokeId=%d&limit=%d",
endpoint, batchNum, tokenID, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter)
@ -238,7 +238,7 @@ func TestGetExits(t *testing.T) {
// All, in reverse order
fetchedExits = []testExit{}
limit = 5
path = fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit)
path = fmt.Sprintf("%s?limit=%d", endpoint, limit)
err = doGoodReqPaginated(path, historydb.OrderDesc, &testExitsResponse{}, appendIter)
assert.NoError(t, err)
assertExitAPIs(t, flipedExits, fetchedExits)
@ -256,7 +256,7 @@ func TestGetExits(t *testing.T) {
path = fmt.Sprintf("%s?batchNum=999999", endpoint)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
path = fmt.Sprintf("%s?limit=1000&fromItem=999999", endpoint)
path = fmt.Sprintf("%s?fromItem=1000999999", endpoint)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
}

+ 0
- 5
api/parsers.go

@ -14,8 +14,6 @@ import (
"github.com/iden3/go-iden3-crypto/babyjub"
)
const exitIdx = "hez:EXIT:1"
// Query parsers
type querier interface {
@ -453,8 +451,5 @@ func ethAddrToHez(addr ethCommon.Address) string {
}
func idxToHez(idx common.Idx, tokenSymbol string) string {
if idx == 1 {
return exitIdx
}
return "hez:" + tokenSymbol + ":" + strconv.Itoa(int(idx))
}

+ 9
- 6
api/slots.go

@ -65,11 +65,11 @@ func (a *API) newSlotsAPIFromWinnerBids(fromItem *uint, order string, bids []his
slotNum := bids[i].SlotNum
slot := a.newSlotAPI(slotNum, currentBlockNum, &bids[i], auctionVars)
if order == historydb.OrderAsc {
if slot.ItemID >= uint64(*fromItem) {
if fromItem == nil || slot.ItemID >= uint64(*fromItem) {
slots = append(slots, slot)
}
} else {
if slot.ItemID <= uint64(*fromItem) {
if fromItem == nil || slot.ItemID <= uint64(*fromItem) {
slots = append(slots, slot)
}
}
@ -80,11 +80,11 @@ func (a *API) newSlotsAPIFromWinnerBids(fromItem *uint, order string, bids []his
func (a *API) addEmptySlot(slots []SlotAPI, slotNum int64, currentBlockNum int64, auctionVars *common.AuctionVariables, fromItem *uint, order string) ([]SlotAPI, error) {
emptySlot := a.newSlotAPI(slotNum, currentBlockNum, nil, auctionVars)
if order == historydb.OrderAsc {
if emptySlot.ItemID >= uint64(*fromItem) {
if fromItem == nil || emptySlot.ItemID >= uint64(*fromItem) {
slots = append(slots, emptySlot)
}
} else {
if emptySlot.ItemID <= uint64(*fromItem) {
if fromItem == nil || emptySlot.ItemID <= uint64(*fromItem) {
slots = append([]SlotAPI{emptySlot}, slots...)
}
}
@ -175,6 +175,9 @@ func getLimitsWithAddr(minSlotNum, maxSlotNum *int64, fromItem, limit *uint, ord
maxLim = *maxSlotNum
}
}
} else {
maxLim = *maxSlotNum
minLim = *minSlotNum
}
return minLim, maxLim
}
@ -285,11 +288,11 @@ func (a *API) getSlots(c *gin.Context) {
if slotsBids[j].SlotNum == i {
found = true
if order == historydb.OrderAsc {
if slotsBids[j].ItemID >= uint64(*fromItem) {
if fromItem == nil || slotsBids[j].ItemID >= uint64(*fromItem) {
slots = append(slots, slotsBids[j])
}
} else {
if slotsBids[j].ItemID <= uint64(*fromItem) {
if fromItem == nil || slotsBids[j].ItemID <= uint64(*fromItem) {
slots = append([]SlotAPI{slotsBids[j]}, slots...)
}
}

+ 12
- 12
api/slots_test.go

@ -122,7 +122,7 @@ func TestGetSlots(t *testing.T) {
// All slots with maxSlotNum filter
maxSlotNum := tc.slots[len(tc.slots)-1].SlotNum + 5
limit := 1
path := fmt.Sprintf("%s?maxSlotNum=%d&limit=%d&fromItem=", endpoint, maxSlotNum, limit)
path := fmt.Sprintf("%s?maxSlotNum=%d&limit=%d", endpoint, maxSlotNum, limit)
err := doGoodReqPaginated(path, historydb.OrderAsc, &testSlotsResponse{}, appendIter)
assert.NoError(t, err)
allSlots := tc.slots
@ -135,7 +135,7 @@ func TestGetSlots(t *testing.T) {
// All slots with maxSlotNum filter, in reverse order
fetchedSlots = []testSlot{}
limit = 3
path = fmt.Sprintf("%s?maxSlotNum=%d&limit=%d&fromItem=", endpoint, maxSlotNum, limit)
path = fmt.Sprintf("%s?maxSlotNum=%d&limit=%d", endpoint, maxSlotNum, limit)
err = doGoodReqPaginated(path, historydb.OrderDesc, &testSlotsResponse{}, appendIter)
assert.NoError(t, err)
@ -149,7 +149,7 @@ func TestGetSlots(t *testing.T) {
fetchedSlots = []testSlot{}
limit = 1
bidderAddr := tc.coordinators[2].Bidder
path = fmt.Sprintf("%s?maxSlotNum=%d&wonByEthereumAddress=%s&limit=%d&fromItem=", endpoint, maxSlotNum, bidderAddr.String(), limit)
path = fmt.Sprintf("%s?maxSlotNum=%d&wonByEthereumAddress=%s&limit=%d", endpoint, maxSlotNum, bidderAddr.String(), limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testSlotsResponse{}, appendIter)
assert.NoError(t, err)
bidderAddressSlots := []testSlot{}
@ -165,7 +165,7 @@ func TestGetSlots(t *testing.T) {
// maxSlotNum & wonByEthereumAddress, in reverse order
fetchedSlots = []testSlot{}
limit = 1
path = fmt.Sprintf("%s?maxSlotNum=%d&wonByEthereumAddress=%s&limit=%d&fromItem=", endpoint, maxSlotNum, bidderAddr.String(), limit)
path = fmt.Sprintf("%s?maxSlotNum=%d&wonByEthereumAddress=%s&limit=%d", endpoint, maxSlotNum, bidderAddr.String(), limit)
err = doGoodReqPaginated(path, historydb.OrderDesc, &testSlotsResponse{}, appendIter)
assert.NoError(t, err)
flippedBidderAddressSlots := []testSlot{}
@ -177,7 +177,7 @@ func TestGetSlots(t *testing.T) {
// finishedAuction
fetchedSlots = []testSlot{}
limit = 15
path = fmt.Sprintf("%s?finishedAuction=%t&limit=%d&fromItem=", endpoint, true, limit)
path = fmt.Sprintf("%s?finishedAuction=%t&limit=%d", endpoint, true, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testSlotsResponse{}, appendIter)
assert.NoError(t, err)
@ -198,7 +198,7 @@ func TestGetSlots(t *testing.T) {
minSlotNum := tc.slots[3].SlotNum
maxSlotNum = tc.slots[len(tc.slots)-1].SlotNum - 1
fetchedSlots = []testSlot{}
path = fmt.Sprintf("%s?maxSlotNum=%d&minSlotNum=%d&limit=%d&fromItem=", endpoint, maxSlotNum, minSlotNum, limit)
path = fmt.Sprintf("%s?maxSlotNum=%d&minSlotNum=%d&limit=%d", endpoint, maxSlotNum, minSlotNum, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testSlotsResponse{}, appendIter)
assert.NoError(t, err)
minMaxBatchNumSlots := []testSlot{}
@ -214,7 +214,7 @@ func TestGetSlots(t *testing.T) {
minSlotNum = tc.slots[0].SlotNum
maxSlotNum = tc.slots[0].SlotNum
fetchedSlots = []testSlot{}
path = fmt.Sprintf("%s?maxSlotNum=%d&minSlotNum=%d&limit=%d&fromItem=", endpoint, maxSlotNum, minSlotNum, limit)
path = fmt.Sprintf("%s?maxSlotNum=%d&minSlotNum=%d&limit=%d", endpoint, maxSlotNum, minSlotNum, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testSlotsResponse{}, appendIter)
assert.NoError(t, err)
minMaxBatchNumSlots = []testSlot{}
@ -230,7 +230,7 @@ func TestGetSlots(t *testing.T) {
minSlotNum = tc.slots[len(tc.slots)-1].SlotNum + 1
maxSlotNum = tc.slots[len(tc.slots)-1].SlotNum + 5
fetchedSlots = []testSlot{}
path = fmt.Sprintf("%s?maxSlotNum=%d&minSlotNum=%d&limit=%d&fromItem=", endpoint, maxSlotNum, minSlotNum, limit)
path = fmt.Sprintf("%s?maxSlotNum=%d&minSlotNum=%d&limit=%d", endpoint, maxSlotNum, minSlotNum, limit)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testSlotsResponse{}, appendIter)
assert.NoError(t, err)
emptySlots := []testSlot{}
@ -246,7 +246,7 @@ func TestGetSlots(t *testing.T) {
minSlotNum = tc.slots[len(tc.slots)-1].SlotNum + 1
maxSlotNum = tc.slots[len(tc.slots)-1].SlotNum + 5
fetchedSlots = []testSlot{}
path = fmt.Sprintf("%s?maxSlotNum=%d&minSlotNum=%d&limit=%d&fromItem=", endpoint, maxSlotNum, minSlotNum, limit)
path = fmt.Sprintf("%s?maxSlotNum=%d&minSlotNum=%d&limit=%d", endpoint, maxSlotNum, minSlotNum, limit)
err = doGoodReqPaginated(path, historydb.OrderDesc, &testSlotsResponse{}, appendIter)
assert.NoError(t, err)
flippedEmptySlots := []testSlot{}
@ -259,7 +259,7 @@ func TestGetSlots(t *testing.T) {
// 400
// No filters
path = fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit)
path = fmt.Sprintf("%s?limit=%d", endpoint, limit)
err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err)
// Invalid maxSlotNum
@ -273,12 +273,12 @@ func TestGetSlots(t *testing.T) {
// Invalid minSlotNum / maxSlotNum (minSlotNum > maxSlotNum)
maxSlotNum = tc.slots[1].SlotNum
minSlotNum = tc.slots[4].SlotNum
path = fmt.Sprintf("%s?maxSlotNum=%d&minSlotNum=%d&limit=%d&fromItem=", endpoint, maxSlotNum, minSlotNum, limit)
path = fmt.Sprintf("%s?maxSlotNum=%d&minSlotNum=%d&limit=%d", endpoint, maxSlotNum, minSlotNum, limit)
err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err)
// 404
maxSlotNum = tc.slots[1].SlotNum
path = fmt.Sprintf("%s?maxSlotNum=%d&wonByEthereumAddress=%s&limit=%d&fromItem=", endpoint, maxSlotNum, tc.coordinators[3].Bidder.String(), limit)
path = fmt.Sprintf("%s?maxSlotNum=%d&wonByEthereumAddress=%s&limit=%d", endpoint, maxSlotNum, tc.coordinators[3].Bidder.String(), limit)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
}

+ 6
- 6
api/token_test.go

@ -54,7 +54,7 @@ func TestGetTokens(t *testing.T) {
}
// Get all (no filters)
limit := 8
path := fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit)
path := fmt.Sprintf("%s?limit=%d", endpoint, limit)
err := doGoodReqPaginated(path, historydb.OrderAsc, &testTokensResponse{}, appendIter)
assert.NoError(t, err)
assertTokensAPIs(t, tc.tokens, fetchedTokens)
@ -64,7 +64,7 @@ func TestGetTokens(t *testing.T) {
limit = 7
stringIds := strconv.Itoa(int(tc.tokens[2].TokenID)) + "," + strconv.Itoa(int(tc.tokens[5].TokenID)) + "," + strconv.Itoa(int(tc.tokens[6].TokenID))
path = fmt.Sprintf(
"%s?ids=%s&limit=%d&fromItem=",
"%s?ids=%s&limit=%d",
endpoint, stringIds, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testTokensResponse{}, appendIter)
@ -80,7 +80,7 @@ func TestGetTokens(t *testing.T) {
limit = 7
stringSymbols := tc.tokens[1].Symbol + "," + tc.tokens[3].Symbol
path = fmt.Sprintf(
"%s?symbols=%s&limit=%d&fromItem=",
"%s?symbols=%s&limit=%d",
endpoint, stringSymbols, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testTokensResponse{}, appendIter)
@ -96,7 +96,7 @@ func TestGetTokens(t *testing.T) {
tokenNameLen := len(tc.tokens[8].Name)
stringName := tc.tokens[8].Name[tokenNameLen-1:]
path = fmt.Sprintf(
"%s?name=%s&limit=%d&fromItem=",
"%s?name=%s&limit=%d",
endpoint, stringName, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testTokensResponse{}, appendIter)
@ -111,7 +111,7 @@ func TestGetTokens(t *testing.T) {
stringSymbols = tc.tokens[2].Symbol + "," + tc.tokens[6].Symbol
stringIds = strconv.Itoa(int(tc.tokens[2].TokenID)) + "," + strconv.Itoa(int(tc.tokens[5].TokenID)) + "," + strconv.Itoa(int(tc.tokens[6].TokenID))
path = fmt.Sprintf(
"%s?symbols=%s&ids=%s&limit=%d&fromItem=",
"%s?symbols=%s&ids=%s&limit=%d",
endpoint, stringSymbols, stringIds, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testTokensResponse{}, appendIter)
@ -125,7 +125,7 @@ func TestGetTokens(t *testing.T) {
// All, in reverse order
fetchedTokens = []historydb.TokenWithUSD{}
limit = 5
path = fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit)
path = fmt.Sprintf("%s?limit=%d", endpoint, limit)
err = doGoodReqPaginated(path, historydb.OrderDesc, &testTokensResponse{}, appendIter)
assert.NoError(t, err)
flipedTokens := []historydb.TokenWithUSD{}

+ 10
- 10
api/txshistory_test.go

@ -256,7 +256,7 @@ func TestGetHistoryTxs(t *testing.T) {
}
// Get all (no filters)
limit := 20
path := fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit)
path := fmt.Sprintf("%s?limit=%d", endpoint, limit)
err := doGoodReqPaginated(path, historydb.OrderAsc, &testTxsResponse{}, appendIter)
assert.NoError(t, err)
assertTxs(t, tc.txs, fetchedTxs)
@ -265,7 +265,7 @@ func TestGetHistoryTxs(t *testing.T) {
fetchedTxs = []testTx{}
limit = 7
path = fmt.Sprintf(
"%s?hermezEthereumAddress=%s&limit=%d&fromItem=",
"%s?hermezEthereumAddress=%s&limit=%d",
endpoint, account.EthAddr, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testTxsResponse{}, appendIter)
@ -287,7 +287,7 @@ func TestGetHistoryTxs(t *testing.T) {
fetchedTxs = []testTx{}
limit = 6
path = fmt.Sprintf(
"%s?BJJ=%s&limit=%d&fromItem=",
"%s?BJJ=%s&limit=%d",
endpoint, account.PublicKey, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testTxsResponse{}, appendIter)
@ -298,7 +298,7 @@ func TestGetHistoryTxs(t *testing.T) {
limit = 5
tokenID := tc.txs[0].Token.TokenID
path = fmt.Sprintf(
"%s?tokenId=%d&limit=%d&fromItem=",
"%s?tokenId=%d&limit=%d",
endpoint, tokenID, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testTxsResponse{}, appendIter)
@ -317,7 +317,7 @@ func TestGetHistoryTxs(t *testing.T) {
idx, err := stringToIdx(idxStr, "")
assert.NoError(t, err)
path = fmt.Sprintf(
"%s?accountIndex=%s&limit=%d&fromItem=",
"%s?accountIndex=%s&limit=%d",
endpoint, idxStr, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testTxsResponse{}, appendIter)
@ -345,7 +345,7 @@ func TestGetHistoryTxs(t *testing.T) {
limit = 3
batchNum := tc.txs[0].BatchNum
path = fmt.Sprintf(
"%s?batchNum=%d&limit=%d&fromItem=",
"%s?batchNum=%d&limit=%d",
endpoint, *batchNum, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testTxsResponse{}, appendIter)
@ -374,7 +374,7 @@ func TestGetHistoryTxs(t *testing.T) {
fetchedTxs = []testTx{}
limit = 2
path = fmt.Sprintf(
"%s?type=%s&limit=%d&fromItem=",
"%s?type=%s&limit=%d",
endpoint, txType, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testTxsResponse{}, appendIter)
@ -391,7 +391,7 @@ func TestGetHistoryTxs(t *testing.T) {
fetchedTxs = []testTx{}
limit = 1
path = fmt.Sprintf(
"%s?batchNum=%d&tokenId=%d&limit=%d&fromItem=",
"%s?batchNum=%d&tokenId=%d&limit=%d",
endpoint, *batchNum, tokenID, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testTxsResponse{}, appendIter)
@ -408,7 +408,7 @@ func TestGetHistoryTxs(t *testing.T) {
// All, in reverse order
fetchedTxs = []testTx{}
limit = 5
path = fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit)
path = fmt.Sprintf("%s?limit=%d", endpoint, limit)
err = doGoodReqPaginated(path, historydb.OrderDesc, &testTxsResponse{}, appendIter)
assert.NoError(t, err)
flipedTxs := []testTx{}
@ -430,7 +430,7 @@ func TestGetHistoryTxs(t *testing.T) {
path = fmt.Sprintf("%s?batchNum=999999", endpoint)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
path = fmt.Sprintf("%s?limit=1000&fromItem=999999", endpoint)
path = fmt.Sprintf("%s?fromItem=1000999999", endpoint)
err = doBadReq("GET", path, nil, 404)
assert.NoError(t, err)
}

+ 1
- 1
db/l2db/l2db_test.go

@ -170,7 +170,7 @@ func assertTx(t *testing.T, expected, actual *common.PoolL2Tx) {
token := tokens[expected.TokenID]
// If the token has value in USD setted
if token.USDUpdate != nil {
assert.Equal(t, token.USDUpdate.Unix(), actual.AbsoluteFeeUpdate.Unix())
assert.Less(t, token.USDUpdate.Unix()-3, actual.AbsoluteFeeUpdate.Unix())
expected.AbsoluteFeeUpdate = actual.AbsoluteFeeUpdate
// Set expected fee
f := new(big.Float).SetInt(expected.Amount)

+ 0
- 3
db/migrations/0001.sql

@ -85,9 +85,6 @@ CREATE FUNCTION hez_idx(BIGINT, VARCHAR)
AS
$BODY$
BEGIN
IF $1 = 1 THEN
RETURN 'hez:EXIT:1';
END IF;
RETURN 'hez:' || $2 || ':' || $1;
END;
$BODY$

Loading…
Cancel
Save