Skip to content

Commit

Permalink
/destinationTokens returns empty list when bridgeable token isnt in b…
Browse files Browse the repository at this point in the history
…ridgemap with destinations (#3314)
  • Loading branch information
abtestingalpha authored Oct 20, 2024
1 parent 7f44c5d commit 98a3a69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
14 changes: 10 additions & 4 deletions packages/rest-api/src/controllers/destinationTokensController.ts
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

0 comments on commit 98a3a69

Please sign in to comment.