Integrate til into api

This commit is contained in:
Arnau B
2020-11-16 18:10:43 +01:00
parent b3b23473b6
commit ce1218e28a
19 changed files with 583 additions and 766 deletions

View File

@@ -45,6 +45,8 @@ func (t testExitsResponse) GetPending() (pendingItems, lastItemID uint64) {
return pendingItems, lastItemID
}
func (t testExitsResponse) New() Pendinger { return &testExitsResponse{} }
func (t *testExitsResponse) Len() int {
return len(t.Exits)
}
@@ -53,9 +55,8 @@ func genTestExits(
commonExits []common.ExitInfo,
tokens []historydb.TokenWithUSD,
accs []common.Account,
usrIdxs []string,
) (usrExits, allExits []testExit) {
allExits = []testExit{}
) []testExit {
allExits := []testExit{}
for _, exit := range commonExits {
token := getTokenByIdx(exit.AccountIdx, tokens, accs)
siblings := []string{}
@@ -82,16 +83,7 @@ func genTestExits(
Token: token,
})
}
usrExits = []testExit{}
for _, exit := range allExits {
for _, idx := range usrIdxs {
if idx == exit.AccountIdx {
usrExits = append(usrExits, exit)
break
}
}
}
return usrExits, allExits
return allExits
}
func TestGetExits(t *testing.T) {
@@ -116,21 +108,38 @@ func TestGetExits(t *testing.T) {
// Get by ethAddr
fetchedExits = []testExit{}
limit = 7
account := tc.accounts[3]
var account testAccount
for _, tx := range tc.txs {
found := false
if tx.Type == common.TxTypeExit {
for i := 0; i < len(tc.accounts); i++ {
if tx.FromIdx != nil && string(tc.accounts[i].Idx) == *tx.FromIdx {
account = tc.accounts[i]
break
}
}
}
if found {
break
}
}
path = fmt.Sprintf(
"%s?hermezEthereumAddress=%s&limit=%d&fromItem=",
endpoint, account.EthAddr, limit,
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter)
assert.NoError(t, err)
accountIdx := fetchedExits[0].AccountIdx
var hermezEthExits []testExit
for i := range tc.usrExits {
if tc.usrExits[i].AccountIdx == accountIdx {
hermezEthExits = append(hermezEthExits, tc.usrExits[i])
var accountExits []testExit
for i := range tc.exits {
for _, acc := range tc.accounts {
if string(acc.Idx) == tc.exits[i].AccountIdx {
if acc.EthAddr == account.EthAddr {
accountExits = append(accountExits, tc.exits[i])
}
}
}
}
assertExitAPIs(t, hermezEthExits, fetchedExits)
assertExitAPIs(t, accountExits, fetchedExits)
// Get by bjj
fetchedExits = []testExit{}
limit = 6
@@ -140,7 +149,7 @@ func TestGetExits(t *testing.T) {
)
err = doGoodReqPaginated(path, historydb.OrderAsc, &testExitsResponse{}, appendIter)
assert.NoError(t, err)
assertExitAPIs(t, hermezEthExits, fetchedExits)
assertExitAPIs(t, accountExits, fetchedExits)
// Get by tokenID
fetchedExits = []testExit{}
limit = 5
@@ -236,7 +245,7 @@ func TestGetExits(t *testing.T) {
// 400
path = fmt.Sprintf(
"%s?accountIndex=%s&hermezEthereumAddress=%s",
endpoint, idx, tc.usrAddr,
endpoint, idx, account.EthAddr,
)
err = doBadReq("GET", path, nil, 400)
assert.NoError(t, err)