Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rest-api): /destinationTokens returns empty list when bridgeable token doesnt exist in bridge map #3314

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,34 @@ export const destinationTokensController = async (req, res) => {
return res.status(400).json({ errors: errors.array() })
}

let payload

try {
const { fromChain, fromToken } = req.query

const fromTokenInfo = tokenAddressToToken(fromChain.toString(), fromToken)

const constructedKey = `${fromTokenInfo.symbol}-${fromChain}`
if (!fromTokenInfo) {
payload = []
} else {
const constructedKey = `${fromTokenInfo.symbol}-${fromChain}`

const payload = BRIDGE_ROUTE_MAPPING[constructedKey]
payload = BRIDGE_ROUTE_MAPPING[constructedKey]
}

logger.info(`Successful destinationTokensController response`, {
query: req.query,
payload,
})

res.json(payload)
return res.json(payload)
} catch (err) {
logger.error(`Error in destinationTokensController`, {
query: req.query,
error: err.message,
stack: err.stack,
})
res.status(500).json({
return res.status(500).json({
error:
'An unexpected error occurred in /destinationTokens. Please try again later.',
})
Expand Down
13 changes: 12 additions & 1 deletion packages/rest-api/src/tests/destinationTokensRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import express from 'express'

import destinationTokensRoute from '../routes/destinationTokensRoute'
import { NativeGasAddress, ZeroAddress } from '../constants'
import { USDC, USDT } from '../constants/bridgeable'
import { ONEETH, USDC, USDT } from '../constants/bridgeable'

const app = express()
app.use('/destinationTokens', destinationTokensRoute)
Expand Down Expand Up @@ -81,6 +81,17 @@ describe('destinatonTokens Route', () => {
expect(response.body[0]).toHaveProperty('chainId')
})

it('should return empty list if there are no destinations', async () => {
const response = await request(app).get('/destinationTokens').query({
fromChain: '1666600000',
fromToken: ONEETH.addresses[1666600000].toLowerCase(),
})

expect(response.status).toBe(200)
expect(Array.isArray(response.body)).toBe(true)
expect(response.body.length).toEqual(0)
})

it('should return 400 for unsupported fromChain', async () => {
const response = await request(app).get('/destinationTokens').query({
fromChain: '999',
Expand Down
Loading