Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Defi-Moses committed Nov 7, 2024
1 parent 48c47b9 commit 2e825ad
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 28 deletions.
10 changes: 3 additions & 7 deletions packages/rest-api/src/routes/bridgeRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions packages/rest-api/src/routes/bridgeTxInfoRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
10 changes: 3 additions & 7 deletions packages/rest-api/src/routes/swapRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions packages/rest-api/src/routes/swapTxInfoRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
16 changes: 16 additions & 0 deletions packages/rest-api/src/tests/bridgeRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
17 changes: 17 additions & 0 deletions packages/rest-api/src/tests/bridgeTxInfoRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
15 changes: 15 additions & 0 deletions packages/rest-api/src/tests/swapRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
16 changes: 16 additions & 0 deletions packages/rest-api/src/tests/swapTxInfoRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit 2e825ad

Please sign in to comment.