diff --git a/packages/rest-api/src/routes/bridgeRoute.ts b/packages/rest-api/src/routes/bridgeRoute.ts index 3d0b38c129..3c6e34c1ed 100644 --- a/packages/rest-api/src/routes/bridgeRoute.ts +++ b/packages/rest-api/src/routes/bridgeRoute.ts @@ -239,13 +239,9 @@ router.get( ) return validateDecimals(value, fromTokenInfo.decimals) }) - .withMessage((_value, { req }) => { - const fromTokenInfo = tokenAddressToToken( - req.query.fromChain, - req.query.fromToken - ) - return `Amount has too many decimals, maximum allowed for this token is ${fromTokenInfo.decimals}` - }), + .withMessage( + 'Amount has too many decimals, beyond the maximum allowed for this token' + ), check() .custom((_value, { req }) => { const { fromChain, toChain, fromToken, toToken } = req.query diff --git a/packages/rest-api/src/routes/bridgeTxInfoRoute.ts b/packages/rest-api/src/routes/bridgeTxInfoRoute.ts index d61211c50a..357c08fe65 100644 --- a/packages/rest-api/src/routes/bridgeTxInfoRoute.ts +++ b/packages/rest-api/src/routes/bridgeTxInfoRoute.ts @@ -175,13 +175,9 @@ router.get( ) return validateDecimals(value, fromTokenInfo.decimals) }) - .withMessage((_value, { req }) => { - const fromTokenInfo = tokenAddressToToken( - req.query.fromChain, - req.query.fromToken - ) - return `Amount has too many decimals, maximum allowed for this token is ${fromTokenInfo.decimals}` - }), + .withMessage( + 'Amount has too many decimals, beyond the maximum allowed for this token' + ), check('destAddress') .exists() .withMessage('destAddress is required') diff --git a/packages/rest-api/src/routes/swapRoute.ts b/packages/rest-api/src/routes/swapRoute.ts index 8d038e97c0..26faace643 100644 --- a/packages/rest-api/src/routes/swapRoute.ts +++ b/packages/rest-api/src/routes/swapRoute.ts @@ -175,13 +175,9 @@ router.get( ) return validateDecimals(value, fromTokenInfo.decimals) }) - .withMessage((_value, { req }) => { - const fromTokenInfo = tokenAddressToToken( - req.query.chain, - req.query.fromToken - ) - return `Amount has too many decimals, maximum allowed for this token is ${fromTokenInfo.decimals}` - }), + .withMessage( + 'Amount has too many decimals, beyond the maximum allowed for this token' + ), check() .custom((_value, { req }) => { const { chain } = req.query diff --git a/packages/rest-api/src/routes/swapTxInfoRoute.ts b/packages/rest-api/src/routes/swapTxInfoRoute.ts index c28ef8d4f5..041fc29ac3 100644 --- a/packages/rest-api/src/routes/swapTxInfoRoute.ts +++ b/packages/rest-api/src/routes/swapTxInfoRoute.ts @@ -154,13 +154,9 @@ router.get( ) return validateDecimals(value, fromTokenInfo.decimals) }) - .withMessage((_value, { req }) => { - const fromTokenInfo = tokenAddressToToken( - req.query.chain, - req.query.fromToken - ) - return `Amount has too many decimals, maximum allowed for this token is ${fromTokenInfo.decimals}` - }), + .withMessage( + 'Amount has too many decimals, beyond the maximum allowed for this token' + ), check('address') .exists() .withMessage('address is required') diff --git a/packages/rest-api/src/tests/bridgeRoute.test.ts b/packages/rest-api/src/tests/bridgeRoute.test.ts index 542feab63a..811c267d0c 100644 --- a/packages/rest-api/src/tests/bridgeRoute.test.ts +++ b/packages/rest-api/src/tests/bridgeRoute.test.ts @@ -173,4 +173,20 @@ describe('Bridge Route with Real Synapse Service', () => { expect(response.status).toBe(400) expect(response.body.error).toHaveProperty('field', 'amount') }) + + it('should return 400 for amount with too many decimals', async () => { + const response = await request(app).get('/bridge').query({ + fromChain: '1', + toChain: '10', + fromToken: USDC.addresses[1], + toToken: USDC.addresses[10], + amount: '1000.123456789', // Assuming USDC has 6 decimals + }) + + expect(response.status).toBe(400) + expect(response.body.error).toHaveProperty( + 'message', + expect.stringContaining('Amount has too many decimals') + ) + }, 15000) }) diff --git a/packages/rest-api/src/tests/bridgeTxInfoRoute.test.ts b/packages/rest-api/src/tests/bridgeTxInfoRoute.test.ts index e39450e725..9718b8553e 100644 --- a/packages/rest-api/src/tests/bridgeTxInfoRoute.test.ts +++ b/packages/rest-api/src/tests/bridgeTxInfoRoute.test.ts @@ -159,4 +159,21 @@ describe('Bridge TX Info Route', () => { 'Invalid destination address' ) }) + + it('should return 400 for amount with too many decimals', async () => { + const response = await request(app).get('/bridgeTxInfo').query({ + fromChain: '1', + toChain: '137', + fromToken: USDC.addresses[1], + toToken: USDC.addresses[137], + amount: '1000.123456789', // Assuming USDC has 6 decimals + destAddress: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', + }) + + expect(response.status).toBe(400) + expect(response.body.error).toHaveProperty( + 'message', + expect.stringContaining('Amount has too many decimals') + ) + }, 10000) }) diff --git a/packages/rest-api/src/tests/swapRoute.test.ts b/packages/rest-api/src/tests/swapRoute.test.ts index 9c09f89a22..b4408d9bb4 100644 --- a/packages/rest-api/src/tests/swapRoute.test.ts +++ b/packages/rest-api/src/tests/swapRoute.test.ts @@ -133,4 +133,19 @@ describe('Swap Route with Real Synapse Service', () => { expect(response.status).toBe(400) expect(response.body.error).toHaveProperty('field', 'amount') }, 10_000) + + it('should return 400 for amount with too many decimals', async () => { + const response = await request(app).get('/swap').query({ + chain: '1', + fromToken: USDC.addresses[1], + toToken: DAI.addresses[1], + amount: '1000.123456789', // Assuming USDC has 6 decimals + }) + + expect(response.status).toBe(400) + expect(response.body.error).toHaveProperty( + 'message', + expect.stringContaining('Amount has too many decimals') + ) + }, 10000) }) diff --git a/packages/rest-api/src/tests/swapTxInfoRoute.test.ts b/packages/rest-api/src/tests/swapTxInfoRoute.test.ts index 99ea0e0f42..e064b48d7b 100644 --- a/packages/rest-api/src/tests/swapTxInfoRoute.test.ts +++ b/packages/rest-api/src/tests/swapTxInfoRoute.test.ts @@ -89,4 +89,20 @@ describe('Swap TX Info Route with Real Synapse Service', () => { expect(response.status).toBe(400) expect(response.body.error).toHaveProperty('field', 'amount') }, 10_000) + + it('should return 400 for amount with too many decimals', async () => { + const response = await request(app).get('/swapTxInfo').query({ + chain: '1', + fromToken: USDC.addresses[1], + toToken: DAI.addresses[1], + amount: '1000.123456789', // Assuming USDC has 6 decimals + address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e', + }) + + expect(response.status).toBe(400) + expect(response.body.error).toHaveProperty( + 'message', + expect.stringContaining('Amount has too many decimals') + ) + }, 10000) })