|
@ -37,7 +37,7 @@ const apiURL = "http://localhost" + apiPort + "/" |
|
|
|
|
|
|
|
|
type testCommon struct { |
|
|
type testCommon struct { |
|
|
blocks []common.Block |
|
|
blocks []common.Block |
|
|
tokens []historydb.TokenRead |
|
|
|
|
|
|
|
|
tokens []tokenAPI |
|
|
batches []common.Batch |
|
|
batches []common.Batch |
|
|
usrAddr string |
|
|
usrAddr string |
|
|
usrBjj string |
|
|
usrBjj string |
|
@ -201,9 +201,9 @@ func TestMain(m *testing.M) { |
|
|
panic(err) |
|
|
panic(err) |
|
|
} |
|
|
} |
|
|
// Set token value
|
|
|
// Set token value
|
|
|
tokensUSD := []historydb.TokenRead{} |
|
|
|
|
|
|
|
|
tokensUSD := []tokenAPI{} |
|
|
for i, tkn := range tokens { |
|
|
for i, tkn := range tokens { |
|
|
token := historydb.TokenRead{ |
|
|
|
|
|
|
|
|
token := tokenAPI{ |
|
|
TokenID: tkn.TokenID, |
|
|
TokenID: tkn.TokenID, |
|
|
EthBlockNum: tkn.EthBlockNum, |
|
|
EthBlockNum: tkn.EthBlockNum, |
|
|
EthAddr: tkn.EthAddr, |
|
|
EthAddr: tkn.EthAddr, |
|
@ -287,7 +287,7 @@ func TestMain(m *testing.M) { |
|
|
} |
|
|
} |
|
|
panic("timesamp not found") |
|
|
panic("timesamp not found") |
|
|
} |
|
|
} |
|
|
getToken := func(id common.TokenID) historydb.TokenRead { |
|
|
|
|
|
|
|
|
getToken := func(id common.TokenID) tokenAPI { |
|
|
for i := 0; i < len(tokensUSD); i++ { |
|
|
for i := 0; i < len(tokensUSD); i++ { |
|
|
if tokensUSD[i].TokenID == id { |
|
|
if tokensUSD[i].TokenID == id { |
|
|
return tokensUSD[i] |
|
|
return tokensUSD[i] |
|
@ -295,7 +295,7 @@ func TestMain(m *testing.M) { |
|
|
} |
|
|
} |
|
|
panic("token not found") |
|
|
panic("token not found") |
|
|
} |
|
|
} |
|
|
getTokenByIdx := func(idx common.Idx) historydb.TokenRead { |
|
|
|
|
|
|
|
|
getTokenByIdx := func(idx common.Idx) tokenAPI { |
|
|
for _, acc := range accs { |
|
|
for _, acc := range accs { |
|
|
if idx == acc.Idx { |
|
|
if idx == acc.Idx { |
|
|
return getToken(acc.TokenID) |
|
|
return getToken(acc.TokenID) |
|
@ -874,18 +874,113 @@ func assertExitAPIs(t *testing.T, expected, actual []exitAPI) { |
|
|
func TestGetToken(t *testing.T) { |
|
|
func TestGetToken(t *testing.T) { |
|
|
// Get all txs by their ID
|
|
|
// Get all txs by their ID
|
|
|
endpoint := apiURL + "tokens/" |
|
|
endpoint := apiURL + "tokens/" |
|
|
fetchedTokens := []historydb.TokenRead{} |
|
|
|
|
|
|
|
|
fetchedTokens := []tokenAPI{} |
|
|
for _, token := range tc.tokens { |
|
|
for _, token := range tc.tokens { |
|
|
fetchedToken := historydb.TokenRead{} |
|
|
|
|
|
|
|
|
fetchedToken := tokenAPI{} |
|
|
assert.NoError(t, doGoodReq("GET", endpoint+strconv.Itoa(int(token.TokenID)), nil, &fetchedToken)) |
|
|
assert.NoError(t, doGoodReq("GET", endpoint+strconv.Itoa(int(token.TokenID)), nil, &fetchedToken)) |
|
|
fetchedTokens = append(fetchedTokens, fetchedToken) |
|
|
fetchedTokens = append(fetchedTokens, fetchedToken) |
|
|
} |
|
|
} |
|
|
assertTokensAPIs(t, tc.tokens, fetchedTokens) |
|
|
assertTokensAPIs(t, tc.tokens, fetchedTokens) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func assertTokensAPIs(t *testing.T, expected, actual []historydb.TokenRead) { |
|
|
|
|
|
|
|
|
func TestGetTokens(t *testing.T) { |
|
|
|
|
|
endpoint := apiURL + "tokens" |
|
|
|
|
|
fetchedTokens := []tokenAPI{} |
|
|
|
|
|
appendIter := func(intr interface{}) { |
|
|
|
|
|
for i := 0; i < len(intr.(*tokensAPI).Tokens); i++ { |
|
|
|
|
|
tmp, err := copystructure.Copy(intr.(*tokensAPI).Tokens[i]) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
fetchedTokens = append(fetchedTokens, tmp.(tokenAPI)) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
// Get all (no filters)
|
|
|
|
|
|
limit := 8 |
|
|
|
|
|
path := fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit) |
|
|
|
|
|
err := doGoodReqPaginated(path, historydb.OrderAsc, &tokensAPI{}, appendIter) |
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
assertTokensAPIs(t, tc.tokens, fetchedTokens) |
|
|
|
|
|
|
|
|
|
|
|
// Get by tokenIds
|
|
|
|
|
|
fetchedTokens = []tokenAPI{} |
|
|
|
|
|
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=", |
|
|
|
|
|
endpoint, stringIds, limit, |
|
|
|
|
|
) |
|
|
|
|
|
err = doGoodReqPaginated(path, historydb.OrderAsc, &tokensAPI{}, appendIter) |
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
var tokensFiltered []tokenAPI |
|
|
|
|
|
tokensFiltered = append(tokensFiltered, tc.tokens[2]) |
|
|
|
|
|
tokensFiltered = append(tokensFiltered, tc.tokens[5]) |
|
|
|
|
|
tokensFiltered = append(tokensFiltered, tc.tokens[6]) |
|
|
|
|
|
assertTokensAPIs(t, tokensFiltered, fetchedTokens) |
|
|
|
|
|
|
|
|
|
|
|
// Get by symbols
|
|
|
|
|
|
fetchedTokens = []tokenAPI{} |
|
|
|
|
|
limit = 7 |
|
|
|
|
|
stringSymbols := tc.tokens[1].Symbol + "," + tc.tokens[3].Symbol |
|
|
|
|
|
path = fmt.Sprintf( |
|
|
|
|
|
"%s?symbols=%s&limit=%d&fromItem=", |
|
|
|
|
|
endpoint, stringSymbols, limit, |
|
|
|
|
|
) |
|
|
|
|
|
err = doGoodReqPaginated(path, historydb.OrderAsc, &tokensAPI{}, appendIter) |
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
tokensFiltered = nil |
|
|
|
|
|
tokensFiltered = append(tokensFiltered, tc.tokens[1]) |
|
|
|
|
|
tokensFiltered = append(tokensFiltered, tc.tokens[3]) |
|
|
|
|
|
assertTokensAPIs(t, tokensFiltered, fetchedTokens) |
|
|
|
|
|
|
|
|
|
|
|
// Get by name
|
|
|
|
|
|
fetchedTokens = []tokenAPI{} |
|
|
|
|
|
limit = 5 |
|
|
|
|
|
stringName := tc.tokens[8].Name[4:5] |
|
|
|
|
|
path = fmt.Sprintf( |
|
|
|
|
|
"%s?name=%s&limit=%d&fromItem=", |
|
|
|
|
|
endpoint, stringName, limit, |
|
|
|
|
|
) |
|
|
|
|
|
err = doGoodReqPaginated(path, historydb.OrderAsc, &tokensAPI{}, appendIter) |
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
tokensFiltered = nil |
|
|
|
|
|
tokensFiltered = append(tokensFiltered, tc.tokens[8]) |
|
|
|
|
|
assertTokensAPIs(t, tokensFiltered, fetchedTokens) |
|
|
|
|
|
|
|
|
|
|
|
// Multiple filters
|
|
|
|
|
|
fetchedTokens = []tokenAPI{} |
|
|
|
|
|
limit = 5 |
|
|
|
|
|
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=", |
|
|
|
|
|
endpoint, stringSymbols, stringIds, limit, |
|
|
|
|
|
) |
|
|
|
|
|
err = doGoodReqPaginated(path, historydb.OrderAsc, &tokensAPI{}, appendIter) |
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
|
|
|
|
tokensFiltered = nil |
|
|
|
|
|
tokensFiltered = append(tokensFiltered, tc.tokens[2]) |
|
|
|
|
|
tokensFiltered = append(tokensFiltered, tc.tokens[6]) |
|
|
|
|
|
assertTokensAPIs(t, tokensFiltered, fetchedTokens) |
|
|
|
|
|
|
|
|
|
|
|
// All, in reverse order
|
|
|
|
|
|
fetchedTokens = []tokenAPI{} |
|
|
|
|
|
limit = 5 |
|
|
|
|
|
path = fmt.Sprintf("%s?limit=%d&fromItem=", endpoint, limit) |
|
|
|
|
|
err = doGoodReqPaginated(path, historydb.OrderDesc, &tokensAPI{}, appendIter) |
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
flipedTokens := []tokenAPI{} |
|
|
|
|
|
for i := 0; i < len(tc.tokens); i++ { |
|
|
|
|
|
flipedTokens = append(flipedTokens, tc.tokens[len(tc.tokens)-1-i]) |
|
|
|
|
|
} |
|
|
|
|
|
assertTokensAPIs(t, flipedTokens, fetchedTokens) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func assertTokensAPIs(t *testing.T, expected, actual []tokenAPI) { |
|
|
require.Equal(t, len(expected), len(actual)) |
|
|
require.Equal(t, len(expected), len(actual)) |
|
|
for i := 0; i < len(actual); i++ { //nolint len(actual) won't change within the loop
|
|
|
for i := 0; i < len(actual); i++ { //nolint len(actual) won't change within the loop
|
|
|
|
|
|
actual[i].ItemID = 0 |
|
|
if expected[i].USDUpdate == nil { |
|
|
if expected[i].USDUpdate == nil { |
|
|
assert.Equal(t, expected[i].USDUpdate, actual[i].USDUpdate) |
|
|
assert.Equal(t, expected[i].USDUpdate, actual[i].USDUpdate) |
|
|
} else { |
|
|
} else { |
|
|