Skip to content

Commit

Permalink
add eth test for bridge limit endpoint, use checksumd address in util
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboydiamonds committed Sep 24, 2024
1 parent a1d4650 commit 33f5584
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
19 changes: 16 additions & 3 deletions packages/rest-api/src/tests/bridgeLimitsRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import request from 'supertest'
import express from 'express'

import bridgeLimitsRoute from '../routes/bridgeLimitsRoute'
import { USDC } from '../constants/bridgeable'
import { USDC, ETH } from '../constants/bridgeable'

const app = express()
app.use('/bridgeLimits', bridgeLimitsRoute)

describe('Get Bridge Limits Route', () => {
it('should return min/max origin amounts for valid input', async () => {
it('should return min/max origin amounts bridging USDC', async () => {
const response = await request(app).get('/bridgeLimits').query({
fromChain: 1,
fromToken: USDC.addresses[1],
Expand All @@ -21,6 +21,19 @@ describe('Get Bridge Limits Route', () => {
expect(response.body).toHaveProperty('minOriginAmount')
}, 10_000)

it('should return min/max origin amounts bridging ETH', async () => {
const response = await request(app).get('/bridgeLimits').query({
fromChain: 1,
fromToken: ETH.addresses[1],
toChain: 10,
toToken: ETH.addresses[10],
})

expect(response.status).toBe(200)
expect(response.body).toHaveProperty('maxOriginAmount')
expect(response.body).toHaveProperty('minOriginAmount')
}, 10_000)

it('should return 400 for unsupported fromChain', async () => {
const response = await request(app).get('/bridgeLimits').query({
fromChain: '999',
Expand Down Expand Up @@ -60,7 +73,7 @@ describe('Get Bridge Limits Route', () => {
const response = await request(app).get('/bridgeLimits').query({
fromChain: '1',
toChain: '137',
fromToken: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
fromToken: USDC.addresses[1],
})
expect(response.status).toBe(400)
expect(response.body.error).toHaveProperty('field', 'toToken')
Expand Down
8 changes: 6 additions & 2 deletions packages/rest-api/src/utils/tokenAddressToToken.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { getAddress } from '@ethersproject/address'

import { BRIDGE_MAP } from '../constants/bridgeMap'

export const tokenAddressToToken = (chain: string, tokenAddress: string) => {
const address = getAddress(tokenAddress)

const chainData = BRIDGE_MAP[chain]
if (!chainData) {
return null
}

const tokenInfo = chainData[tokenAddress]
const tokenInfo = chainData[address]

if (!tokenInfo) {
return null
}

return {
address: tokenAddress,
address,
symbol: tokenInfo.symbol,
decimals: tokenInfo.decimals,
}
Expand Down

0 comments on commit 33f5584

Please sign in to comment.