-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat(rest-api): Adds validateRouteExists validation [SLT-260] #3180
Conversation
Note Currently processing new changes in this PR. This may take a few minutes, please wait... Files selected for processing (2)
WalkthroughThe pull request introduces validation enhancements across several files in the REST API. It adds a new function Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Tip CodeRabbit can suggest fixes for GitHub Check annotations.Configure Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Deploying sanguine-fe with Cloudflare Pages
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3180 +/- ##
===================================================
- Coverage 41.54443% 37.95792% -3.58651%
===================================================
Files 460 418 -42
Lines 25770 24240 -1530
Branches 357 82 -275
===================================================
- Hits 10706 9201 -1505
+ Misses 14326 14301 -25
Partials 738 738
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range and nitpick comments (6)
packages/rest-api/src/utils/bridgeRouteMapping.ts (2)
99-99
: Add explanatory comment for BRIDGE_ROUTE_MAPPING_SYMBOLS.The new exported constant
BRIDGE_ROUTE_MAPPING_SYMBOLS
provides direct access to the stringified bridge routes. Consider adding a comment to explain its purpose and the reasoning behind passing an empty array as the second argument toconstructJSON
.Add a comment above the constant declaration:
// Stores the stringified bridge routes without any exclusions // The empty array passed to constructJSON indicates no routes should be excluded export const BRIDGE_ROUTE_MAPPING_SYMBOLS = constructJSON(BRIDGE_MAP, [])
100-102
: Approve the change and suggest minor readability improvement.The modification to
BRIDGE_ROUTE_MAPPING
effectively separates the stringified and transformed versions of the bridge route mapping, aligning with the new return type ofconstructJSON
. This change enhances flexibility in data usage across the codebase.Consider using object shorthand notation for improved readability:
export const BRIDGE_ROUTE_MAPPING = transformBridgeRouteValues(BRIDGE_ROUTE_MAPPING_SYMBOLS)packages/rest-api/src/tests/bridgeLimitsRoute.test.ts (1)
38-50
: LGTM: New test case for unsupported routeThe new test case correctly validates the behavior for an unsupported route, aligning with the PR objective. It properly checks for a 400 status and the expected error message.
Consider adding a comment explaining why this specific combination of tokens (NativeGasAddress to USDC) is expected to be an unsupported route. This would enhance the test's readability and maintainability.
it('should return 400 for unsupported route', async () => { + // Test an unsupported route: bridging native gas token to USDC const response = await request(app).get('/bridgeLimits').query({ fromChain: '1', toChain: '10', fromToken: NativeGasAddress, toToken: USDC.addresses[10], }) expect(response.status).toBe(400) expect(response.body.error).toHaveProperty( 'message', 'No valid route exists for the chain/token combination' ) }, 10_000)
packages/rest-api/src/tests/bridgeRoute.test.ts (1)
Line range hint
1-73
: Consider enhancing overall test suite documentation and consistency.The test suite covers a good range of scenarios, including the newly added test for unsupported routes. To further improve the quality and maintainability of the test suite, consider the following suggestions:
Add brief comments before each test case explaining its purpose and the scenario it's testing. This will make it easier for other developers to understand and maintain the tests.
Standardize the timeout values across test cases. Currently, some tests use 15000ms, while others use 10000ms. Choose a consistent timeout that works for all cases, or justify the differences if they're necessary.
Group related test cases together. For example, you could group all the error cases (400 status codes) together, and all the successful cases (200 status codes) together.
Consider adding more edge cases, such as testing with very large amounts or with different token decimals.
Here's an example of how you could improve the documentation for one of the existing test cases:
+ // Test case for a valid USDC bridge from Ethereum to Optimism + // This tests a common use case with a specific amount it('should return bridge quotes for valid input, 1000 USDC from Ethereum to Optimism', async () => { // ... (existing test code) ... }, 15000)Apply similar documentation improvements to other test cases for consistency and clarity.
packages/rest-api/src/routes/bridgeLimitsRoute.ts (1)
134-140
: Approved: New route validation enhances request processing.The new custom validation check using
validateRouteExists
is a valuable addition that aligns with the PR objectives. It ensures that only requests with valid routes are processed further, enhancing the API's robustness.Consider adding more specific error information to help diagnose issues:
check() .custom((_value, { req }) => { const { fromChain, toChain, fromToken, toToken } = req.query return validateRouteExists(fromChain, fromToken, toChain, toToken) }) - .withMessage('No valid route exists for the chain/token combination'), + .withMessage((_, { req }) => { + const { fromChain, toChain, fromToken, toToken } = req.query + return `No valid route exists for the chain/token combination: ${fromChain}->${toChain}, ${fromToken}->${toToken}` + }),This change would provide more context in the error message, making it easier to identify the specific invalid route.
packages/rest-api/src/routes/bridgeRoute.ts (1)
226-232
: LGTM with suggestions: New custom validation for route existenceThe new validation check for route existence is well-implemented and aligns with the PR objectives. It effectively uses the
validateRouteExists
function to ensure that only valid routes are processed.Suggestions for improvement:
- Consider adding type checks for the query parameters before passing them to
validateRouteExists
to ensure type safety.- The error message could be more specific, potentially including details about which part of the route (fromChain, toChain, fromToken, or toToken) is invalid.
Here's a suggested improvement:
check() .custom((_value, { req }) => { const { fromChain, toChain, fromToken, toToken } = req.query; // Ensure all required parameters are strings if (typeof fromChain !== 'string' || typeof toChain !== 'string' || typeof fromToken !== 'string' || typeof toToken !== 'string') { throw new Error('Invalid parameter types'); } return validateRouteExists(fromChain, fromToken, toChain, toToken); }) .withMessage((_, { req }) => { const { fromChain, toChain, fromToken, toToken } = req.query; return `No valid route exists for the chain/token combination: ${fromChain}-${fromToken} to ${toChain}-${toToken}`; }),This suggestion adds type checking and provides a more detailed error message.
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (7)
- packages/rest-api/src/routes/bridgeLimitsRoute.ts (2 hunks)
- packages/rest-api/src/routes/bridgeRoute.ts (2 hunks)
- packages/rest-api/src/tests/bridgeLimitsRoute.test.ts (2 hunks)
- packages/rest-api/src/tests/bridgeRoute.test.ts (2 hunks)
- packages/rest-api/src/utils/bridgeRouteMapping.ts (3 hunks)
- packages/rest-api/src/validations/validateRouteExists.ts (1 hunks)
- packages/rest-api/src/validations/validateTokens.ts (0 hunks)
Files not reviewed due to no reviewable changes (1)
- packages/rest-api/src/validations/validateTokens.ts
Additional comments not posted (8)
packages/rest-api/src/validations/validateRouteExists.ts (2)
1-2
: LGTM: Imports are relevant and concise.The imported utilities
tokenAddressToToken
andBRIDGE_ROUTE_MAPPING_SYMBOLS
are appropriately used in the function, contributing to its functionality without unnecessary imports.
1-20
: Overall assessment: Good implementation with room for improvement.The
validateRouteExists
function effectively addresses the PR objective of validating routes before forwarding requests to the controller. It makes good use of imported utilities and implements a logical flow for route validation.However, to enhance robustness and maintainability, consider:
- Adding input validation and type checking.
- Implementing more explicit error handling.
- Including function documentation to explain its purpose and usage.
These improvements will make the code more resilient and easier to maintain in the long run.
packages/rest-api/src/utils/bridgeRouteMapping.ts (1)
16-16
: Verify the impact of return type change and update documentation.The return type of
constructJSON
has been changed fromTransformedBridgeRoutes
toStringifiedBridgeRoutes
, and the function now returnsresult
directly. This change aligns with the new implementation but may affect other parts of the codebase.To ensure this change doesn't introduce bugs:
Also, please update the function's documentation to reflect this change in behavior and return type.
Also applies to: 59-59
Verification successful
Return type change verified successfully with no remaining references to TransformedBridgeRoutes. Documentation has been updated accordingly.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any remaining usage of TransformedBridgeRoutes type with constructJSON # Expected: No results, indicating all usages have been updated rg --type typescript "constructJSON.*TransformedBridgeRoutes" # Description: Verify that all calls to constructJSON are handling string arrays # Expected: All results should show string array handling rg --type typescript -A 3 "constructJSON\("Length of output: 179
Script:
#!/bin/bash # Description: Check for any remaining usage of TransformedBridgeRoutes type with constructJSON # Expected: No results, indicating all usages have been updated rg --glob "*.ts" "constructJSON.*TransformedBridgeRoutes" rg --glob "*.tsx" "constructJSON.*TransformedBridgeRoutes" # Description: Verify that all calls to constructJSON are handling string arrays # Expected: All results should show string array handling rg --glob "*.ts" -A 3 "constructJSON\(" rg --glob "*.tsx" -A 3 "constructJSON\("Length of output: 1240
packages/rest-api/src/tests/bridgeLimitsRoute.test.ts (1)
6-6
: LGTM: New import added correctlyThe import for
NativeGasAddress
is correctly placed and is used in the new test case.packages/rest-api/src/routes/bridgeLimitsRoute.ts (2)
11-11
: LGTM: New import for route validation.The import of
validateRouteExists
is correctly placed and aligns with the PR objectives to enhance route validation.
Line range hint
1-140
: Summary: Effective enhancement of route validation.The changes in this file successfully implement the new route validation as described in the PR objectives. The addition of
validateRouteExists
improves the API's robustness by ensuring that only valid routes are processed. This change is well-integrated with the existing validation checks and follows the established coding patterns in the file.To ensure the
validateRouteExists
function is implemented correctly, let's verify its implementation:This will help confirm that the
validateRouteExists
function is properly implemented and exported, supporting the changes made in this file.packages/rest-api/src/routes/bridgeRoute.ts (2)
11-11
: LGTM: New import statement forvalidateRouteExists
The import statement for
validateRouteExists
is correctly added and aligns with the PR objectives.
Line range hint
1-238
: Summary: Effective implementation of route validationThe changes in this file successfully implement the new route validation feature as described in the PR objectives. The addition of
validateRouteExists
enhances the API's robustness by ensuring that only valid routes are processed before reaching the controller.Key points:
- The new import and validation check are correctly implemented.
- The changes integrate well with the existing code structure.
- The implementation aligns with the PR's goal of improving validation mechanisms.
While the implementation is solid, consider the suggestions for improved type safety and more detailed error messages to further enhance the user experience and code reliability.
Overall, these changes contribute positively to the API's functionality and error handling capabilities.
Bundle ReportChanges will increase total bundle size by 247.68kB (0.69%) ⬆️. This is within the configured threshold ✅ Detailed changes
ℹ️ *Bundle size includes cached data from a previous commit |
* update bl * remove global solidity extension settings * use monorepo support in global workspace only * - use Solidity extension for formatting *.sol files - use `forge fmt` as formatter in Solidity extension * REST API Improvements [SLT-179] (#3133) * fix swaptxinfo function * Updates test coverage command * migrating to using token addresses instead of symbols * fix linting errors * fixing swaptxinfocontroller * new tests and new functionality --------- Co-authored-by: abtestingalpha <abtestingalpha@gmail.com> * Publish - @synapsecns/rest-api@1.0.75 - @synapsecns/synapse-interface@0.38.4 * fix harmony proxy (#3149) Co-authored-by: Trajan0x <trajan0x@users.noreply.github.com> * merging rfq indexer into monorepo [SLT-164] [SLT-176] (#3136) * merging rfq indexer into monorepo * nuke .env * fix commands * fix package name * test coverage script * rough pass at docs and some linting and fixes yarn * Upgrades wagmi & rainbowkit * indxer * Adds invisible but used packages * +recent-invalid-fills [SLT-188] * Moves wagmi to root * new endpoints and clean up linting --------- Co-authored-by: Trajan0x <trajan0x@users.noreply.github.com> Co-authored-by: abtestingalpha <abtestingalpha@gmail.com> Co-authored-by: parodime <jordan@protochainresearch.com> * Publish - @synapsecns/synapse-interface@0.38.5 - @synapsecns/rfq-indexer-api@1.0.2 - @synapsecns/rfq-indexer@0.0.2 * Adds /destinationTokens route [SLT-204] (#3151) * Adds /destinationTokens route * ZeroAddress & NativeGasAddress * Adds test for native gas tokens * Checksums incoming token address params * Publish - @synapsecns/rest-api@1.0.76 * boba pause (#3150) * boba pause * only boba to txns * Publish - @synapsecns/synapse-interface@0.38.6 * fix(synapse-interface): Reorders validation to check existence first (#3156) * Reorders validation to check existence first * Removes duplicates * Publish - @synapsecns/rest-api@1.0.77 * Fix boba pause (#3158) * Publish - @synapsecns/synapse-interface@0.38.7 * update bl * feat(rest-api): Adds Swagger for api docs [SLT-205] (#3159) * Adds Swagger for api docs * Replace prepended verb Get routes with nouns * Adds dev flag for swagger serverUrl * Publish - @synapsecns/rest-api@1.1.0 - @synapsecns/synapse-interface@0.38.8 - @synapsecns/rfq-indexer-api@1.0.3 - @synapsecns/rfq-indexer@0.0.3 * Pulls version from package json (#3160) * Publish - @synapsecns/rest-api@1.1.1 * Require vs import due to file location (#3161) * Require vs import due to file location * Publish - @synapsecns/rest-api@1.1.2 * Prevent caching of api docs (#3162) * Publish - @synapsecns/rest-api@1.1.3 * feat(contracts-rfq): relay/prove/claim with different address [SLT-130] (#3138) * init. solidity ^. FbV2 relay/prove/claim overloads * +IFastBridgeV2, explicit address0 cast, func scope & inheritdoc fixes * pragma lock, contract relabel * feat: start scoping V2 tests * test: override relayer role scenarios, no longer enforced by V2 * test: finish the parity test * test: the management methods * test: dst chain scenarios * test: bridge * test: prove * test: claim * test: dispute * test: refund * test: bridge reverts * remove redundant extend. rearrange inherit list * revert 0.8.20 in favor of user (non-ws) setting --------- Co-authored-by: ChiTimesChi <88190723+ChiTimesChi@users.noreply.github.com> * Publish - FastBridge@0.4.0 * fix(promexporter): make spans better (#3164) * move the errors * [goreleaser] * fix v to w * changing native token address standard [SLT-210] (#3157) * changing native token address standard * fixing tests * normalizeNativeTokenAddress middleware, additional tests --------- Co-authored-by: abtestingalpha <abtestingalpha@gmail.com> * Publish - @synapsecns/rest-api@1.1.4 * Refactoring rfq-indexer API and adding swagger docs [SLT-228] (#3167) * refactoring and adding swagger * remove testing scripts * fix typos and consistency with 404 errors * Publish - @synapsecns/rfq-indexer-api@1.0.4 * fix read mes (#3168) * Publish - @synapsecns/contracts-core@1.0.32 - FastBridge@0.4.1 - @synapsecns/solidity-devops@0.4.5 * fix(opbot): use submitter get tx status [SLT-158] (#3134) * use experimental logger to debug * fix lint * [goreleaser] * use submitter instead of client * [goreleaser] * [goreleaser] * fix(synapse-interface): Additional checks on screen [SLT-166] (#3152) * Additional checks on screen * Adds checks on chain/token changes * Publish - @synapsecns/synapse-interface@0.38.9 * feat(synapse-interface): confirm new price [SLT-150] (#3084) * add bridge quote history middleware * request user confirm changes when quoted price updates * add conditions for displaying confirm change state * track initial quote initializing confirm change state * specify output delta threshold * callback functions to handle initialize/accept/reset confirm changes flow * quote countdown timer animation to signal refresh * implement automatic refresh intervals * mouse move to refresh automatic intervals * add i8n translations for button text --------- Co-authored-by: abtestingalpha <abtestingalpha@gmail.com> * Publish - @synapsecns/synapse-interface@0.39.0 * fix: formatted bridge fee amount (#3165) * Publish - @synapsecns/rest-api@1.1.5 * fix(contracts-rfq): CI workflows [SLT-245] (#3178) * fix: license, files * fix: package name * build: update solhint to latest * build: remove prettier dependencies * fix: solhint workflows * build: update solhint in other packages as well * chore: solhint rules, exceptions * fix: silence linter warnings in tests * chore: forge fmt * add variable to test linter CI * Revert "add variable to test linter CI" This reverts commit 0629309. * Publish - @synapsecns/contracts-core@1.0.33 - @synapsecns/contracts-rfq@0.5.0 - @synapsecns/solidity-devops@0.4.6 * feat(api): bridge limits [SLT-165] (#3179) * adds `/bridgeLimits` route, controller * fetch best sdk quote for min/max origin amounts * add tests * implement middleware to normalize addresses * adds swagger doc * Publish - @synapsecns/rest-api@1.2.0 * fix(contracts-rfq): limit the amount of solhint warnings [SLT-245] (#3182) * ci: limit the amount of solhint warnings * refactor: move the errors into the separate interface * refactor: errors imports in tests * Publish - @synapsecns/contracts-rfq@0.5.1 * ci: Solidity gas diff [SLT-259] (#3181) * ci: run tests w/o coverage first for better visibility * test: malform the test to check the adjusted workflow * Revert "test: malform the test to check the adjusted workflow" This reverts commit e7db6e1. * ci: add gas-diff workflow * try changing the contract to trigger gas diffs * retrigger the workflow * ci: provide the correct report path * ci: run on pull requests only * ci: save gas reports in monorepo root * Revert "ci: run on pull requests only" This reverts commit 0a01d60. * Revert "try changing the contract to trigger gas diffs" This reverts commit 91bc03e. * refactor: wrap if statement * refactor: exclude `solidity-devops` package in a more generic way * ci: run tests w/o coverage for `solidity-devops`, add comments * add generic comment to trigger `solidity-devops` workflows * Revert "add generic comment to trigger `solidity-devops` workflows" This reverts commit cc35a43. * Publish - @synapsecns/contracts-rfq@0.5.2 * fix(contracts-core): set very high gas limit for intensive tests [SLT-259] (#3186) * fix: set very high gas limit for intensive tests * ci: speed up solidity coverage * Publish - @synapsecns/contracts-core@1.0.34 * feat(rest-api): Adds validateRouteExists validation [SLT-260] (#3180) * Adds validateRouteExists validation * Remove timeouts for 400s * Publish - @synapsecns/rest-api@1.3.0 * add duplicate command warning (#3174) Co-authored-by: Trajan0x <trajan0x@users.noreply.github.com> * reduce solhint warnings on FbV2 (#3189) * reduce solhint warnings on FbV2 * fix whitespace * Publish - @synapsecns/contracts-rfq@0.5.3 * ci: solidity gas diff options [SLT-267] (#3193) * ci: ignore test files in gas diff report * add some changes to the test files * ci: define some options for gas-diff * try changing the contract to trigger gas diffs * Revert "try changing the contract to trigger gas diffs" This reverts commit 4504e3c. * Revert "add some changes to the test files" This reverts commit 7e7d6cb. * prove w/ tx id [SLT-181] (#3169) * prove w/ tx id SLT-181 * +proveOther tests, forge fmt * fmt * fmt * Publish - @synapsecns/contracts-rfq@0.5.4 * fix(sdk-router): disable ARB airdrop tests (#3195) * Publish - @synapsecns/rest-api@1.3.1 - @synapsecns/sdk-router@0.11.2 - @synapsecns/synapse-interface@0.39.1 - @synapsecns/widget@0.7.2 * Fixing issue for wallet integration [SLT-270] (#3194) * slight modification to graphql call * fixing explorer frontend as well * Publish - @synapsecns/explorer-ui@0.3.3 - @synapsecns/rest-api@1.3.2 * store relayer on relay [SLT-182] (#3170) * store relayer on relay [SLT-182] * +tests, zeroAddr check, fmt * Publish - @synapsecns/contracts-rfq@0.5.5 * Adjust text to trigger build (#3199) * Publish - @synapsecns/synapse-interface@0.39.2 * feat(synapse-interface): refund RFQ transaction [SLT-272] (#3197) * Txn transaction refund tracking * Update store to support tracking * Query FastBridge contract for `bridgeStatuses` to find refund status * Track bridge transaction `bridgeQuote.routerAddress` in store * Fetch FastBridge contract address when only provided router address * add translations --------- Co-authored-by: aureliusbtc <82057759+aureliusbtc@users.noreply.github.com> Co-authored-by: ChiTimesChi <88190723+ChiTimesChi@users.noreply.github.com> Co-authored-by: abtestingalpha <abtestingalpha@gmail.com> Co-authored-by: Defi-Moses <Defi-Moses@users.noreply.github.com> Co-authored-by: trajan0x <83933037+trajan0x@users.noreply.github.com> Co-authored-by: Trajan0x <trajan0x@users.noreply.github.com> Co-authored-by: parodime <jordan@protochainresearch.com> Co-authored-by: abtestingalpha <104046418+abtestingalpha@users.noreply.github.com> Co-authored-by: abtestingalpha <abtestingalpha@users.noreply.github.com> Co-authored-by: parodime <parodime@users.noreply.github.com> Co-authored-by: vro <168573323+golangisfun123@users.noreply.github.com> Co-authored-by: ChiTimesChi <ChiTimesChi@users.noreply.github.com> Co-authored-by: bigboydiamonds <57741810+bigboydiamonds@users.noreply.github.com> Co-authored-by: bigboydiamonds <bigboydiamonds@users.noreply.github.com>
Description
validateTokens
validateRouteExists
to check for route existence before passing request params to controllerSummary by CodeRabbit
New Features
Bug Fixes
Tests
Chores