Skip to content
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

Refactor code reported by Sonarqube #299

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Refactor code reported by Sonarqube #299

wants to merge 15 commits into from

Conversation

trungbach
Copy link
Collaborator

@trungbach trungbach commented Jul 18, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a "Reusable SonarQube" workflow for enhanced code quality checks.
  • Improvements

    • Enhanced import organization in the code editor to optimize the development experience.
    • Refactored chart container logic for better readability and maintainability.
    • Updated network configurations with new constants for improved token handling.
    • Improved simulated amount handling for token swaps to automatically simulate if not explicitly provided.
    • Expanded file exclusion patterns in the SonarQube configuration to improve analysis relevance.
  • Tests

    • Adjusted unit tests and mocking for better coverage and reliability.

Copy link

coderabbitai bot commented Jul 18, 2024

Walkthrough

This update enhances the project with a new SonarQube workflow, refines the oraidex-common-ui components, and applies various optimizations across multiple files. Key changes include improved import organization, updated error handling, and the addition of coding standards in the VS Code settings. The exclusions in the Sonar configuration have also been broadened to improve analysis relevance.

Changes

File Path Change Summary
.github/workflows/reusable-sonar.yml Introduced a new workflow for SonarQube analysis triggered by dispatch, pull requests, and pushes to a specific branch.
.vscode/settings.json Added setting to organize imports explicitly on save.
...TVChartContainer/TVChartContainer.tsx Refactored handleChartReady function and modified chart setup logic.
...rtContainer/helpers/useTVDatafeed.ts Updated pairsChart prop syntax and removed commented-out code.
...artContainer/helpers/utils.spec.ts Cleaned up imports and commented out a test case.
...oraidex-common/src/helper.ts Adjusted imports, reordered functions, and refactored error handling.
...oraidex-common/src/network.ts Updated token contract imports and rearranged import statements.
...oraidex-common/tests/helper.spec.ts Added new imports, removed unnecessary imports, and made formatting adjustments.
...iversal-swap/src/handler.ts Reorganized imports, updated function signatures, and refactored IBC transfer logic; added new constants and functions.
...iversal-swap/src/helper.ts Updated imports and modified functions related to token swapping logic.
...iversal-swap/src/types.ts Updated comment for simulateAmount property in UniversalSwapData interface.
...iversal-swap/tests/index.spec.ts Introduced new imports, rearranged existing ones, and modified test setup and mocking behavior.
sonar-project.properties Updated sonar.exclusions to exclude additional paths using wildcards and included *.spec.ts files in all subdirectories.

Poem

In the code's vast labyrinth, a change does bloom,
Refactors and workflows dispel the gloom.
Imports reordered, functions refined,
A smoother flow, in logic aligned.
The rabbit hops with joy, oh so spry,
For now the codebase reaches the sky! 🌟🐇


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
packages/universal-swap/src/handler.ts (1)

99-111: New method getIbcReceiveAddr looks good but consider adding error handling.

The method implementation looks correct. However, consider adding more detailed error handling or logging to capture specific issues that might arise.

-  if (!ibcReceiveAddr) throw generateError("Please login cosmos wallet!");
+  if (!ibcReceiveAddr) {
+    console.error("IBC receive address is empty.");
+    throw generateError("Please login cosmos wallet!");
+  }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b2a0952 and b559194.

Files selected for processing (13)
  • .github/workflows/reusable-sonar.yml (1 hunks)
  • .vscode/settings.json (1 hunks)
  • packages/oraidex-common-ui/src/components/TVChartContainer/TVChartContainer.tsx (1 hunks)
  • packages/oraidex-common-ui/src/components/TVChartContainer/helpers/useTVDatafeed.ts (2 hunks)
  • packages/oraidex-common-ui/src/components/TVChartContainer/helpers/utils.spec.ts (3 hunks)
  • packages/oraidex-common/src/helper.ts (4 hunks)
  • packages/oraidex-common/src/network.ts (4 hunks)
  • packages/oraidex-common/tests/helper.spec.ts (4 hunks)
  • packages/universal-swap/src/handler.ts (4 hunks)
  • packages/universal-swap/src/helper.ts (5 hunks)
  • packages/universal-swap/src/types.ts (1 hunks)
  • packages/universal-swap/tests/index.spec.ts (7 hunks)
  • sonar-project.properties (1 hunks)
Additional comments not posted (45)
sonar-project.properties (1)

3-3: LGTM! Verify the excluded paths.

The changes to the sonar.exclusions property look good. Ensure that the specified paths are correct and intended to be excluded from SonarQube analysis.

Verification successful

The excluded paths in the sonar-project.properties file are correct. All specified directories exist in the repository.

  • docs
  • packages/contracts-sdk
  • packages/oraidex-common/src/typechain-types
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the excluded paths in the repository.

# Test: List the directories to ensure they exist. Expect: Directories should be present.
fd --type d --max-depth 1 --exec echo {} \; docs packages/contracts-sdk packages/oraidex-common/src/typechain-types

Length of output: 120


Script:

#!/bin/bash
# Description: Verify the excluded paths in the repository.

# Test: Check if each directory exists and print a message accordingly.
for dir in docs packages/contracts-sdk packages/oraidex-common/src/typechain-types; do
  if [ -d "$dir" ]; then
    echo "Directory exists: $dir"
  else
    echo "Directory does not exist: $dir"
  fi
done

Length of output: 644

.vscode/settings.json (1)

16-17: LGTM!

The new configuration setting for organizing imports on save looks good and will help maintain clean and organized import statements.

.github/workflows/reusable-sonar.yml (1)

1-22: LGTM!

The new GitHub Actions workflow for SonarQube analysis looks good. It includes necessary steps for triggering the workflow, checking out the repository, and running the SonarCloud scan.

packages/oraidex-common-ui/src/components/TVChartContainer/helpers/utils.spec.ts (2)

1-1: LGTM!

The changes to the import statements look good. Necessary imports have been added, and unused imports have been removed.


Line range hint 6-6:
Verify the commented-out test case.

The test case for parseChannelFromPair is commented out. Ensure that this is intentional and consider adding a TODO comment if it needs to be revisited.

packages/oraidex-common-ui/src/components/TVChartContainer/helpers/useTVDatafeed.ts (1)

29-29: LGTM! Correct array syntax for pairsChart.

The change to the pairsChart prop to include proper array syntax is correct and consistent with TypeScript conventions.

packages/universal-swap/src/types.ts (1)

48-48: LGTM! Updated comment for simulateAmount.

The updated comment accurately reflects the behavior of the simulateAmount property, indicating that it will auto simulate if not passed.

packages/oraidex-common-ui/src/components/TVChartContainer/TVChartContainer.tsx (1)

116-134: LGTM! Refactor of handleChartReady function.

The extraction of the handleChartReady function from the onChartReady callback to a standalone function is well-implemented and improves code readability and maintainability.

packages/oraidex-common/src/helper.ts (5)

4-14: LGTM! Import modifications.

The additions of defaultStargateTypes, logs, TextProposal, and BigDecimal are correct. The reordering of imports is also appropriate for consistency.


17-19: LGTM! Modifications to constants.

The modifications and additions to constants like AVERAGE_COSMOS_GAS_PRICE, CW20_DECIMALS, GAS_ESTIMATION_BRIDGE_DEFAULT, and MULTIPLIER are correct and consistent with the rest of the code.


163-166: LGTM! Refactor of buildMultipleExecuteMessages function.

The refactor of the buildMultipleExecuteMessages function to include error handling is well-implemented and improves code robustness.


290-294: LGTM! Refactor of parseTxToMsgExecuteContractMsgs function.

The refactor of the parseTxToMsgExecuteContractMsgs function to include better error handling and logging is well-implemented and improves code robustness.


451-451: LGTM! Refactor of decodeProto function.

The refactor of the decodeProto function to include better error handling and support for TextProposal is well-implemented and improves code robustness.

packages/oraidex-common/tests/helper.spec.ts (4)

5-7: LGTM!

The added imports for fs, path, and fileURLToPath are necessary for file operations in the test cases.


8-8: LGTM!

The added imports for describe, expect, and it from "vitest" are necessary for writing test cases.


26-26: LGTM!

The added import for parseAssetInfoFromContractAddrOrDenom is necessary for testing this function.


1-1: LGTM!

The removal of the unused import for StargateClient helps clean up the code.

packages/oraidex-common/src/network.ts (3)

7-7: LGTM!

The added imports for BTC_CONTRACT, NEUTARO_ORAICHAIN_DENOM, OCH_CONTRACT, OCH_ETH_CONTRACT, ORAIDEX_BID_POOL_CONTRACT, and ORAIX_ETH_CONTRACT are necessary for the network configuration.

Also applies to: 25-27, 29-29, 33-33


50-50: LGTM!

The removal of imports for USDT_ETH_CONTRACT, BTC_CONTRACT, NEUTARO_ORAICHAIN_DENOM, OCH_ETH_CONTRACT, OCH_CONTRACT, and ORAIX_ETH_CONTRACT helps clean up the code.


2-2: LGTM!

The reordering of the import for listOsmosisToken improves the organization and readability of the code.

packages/universal-swap/src/helper.ts (17)

1-60: Ensure all new imports are necessary and correctly used.

The import statements have been significantly modified. Ensure that all added imports are necessary and correctly used in the code. Verify that removed imports are no longer needed.


Line range hint 316-324:
Ensure comprehensive test coverage for addOraiBridgeRoute.

The method addOraiBridgeRoute has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

Verified: Comprehensive test coverage for addOraiBridgeRoute.

The method addOraiBridgeRoute is adequately covered by unit tests in index.spec.ts and helper.spec.ts, ensuring its functionality is verified under various scenarios.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `addOraiBridgeRoute` is covered by unit tests.

# Test: Search for test cases covering `addOraiBridgeRoute`. Expect: Test cases should be present.
rg --type ts -A 5 'addOraiBridgeRoute'

Length of output: 3621


Line range hint 245-315:
Ensure comprehensive test coverage for getRoute.

The method getRoute has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

Ensure comprehensive test coverage for getRoute.

The method getRoute is covered by unit tests in packages/universal-swap/tests/helper.spec.ts. The tests verify various scenarios, ensuring the method's functionality.

  • Location of tests: packages/universal-swap/tests/helper.spec.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `getRoute` is covered by unit tests.

# Test: Search for test cases covering `getRoute`. Expect: Test cases should be present.
rg --type ts -A 5 'getRoute'

Length of output: 9697


Line range hint 385-414:
Ensure comprehensive test coverage for generateSwapOperationMsgs.

The method generateSwapOperationMsgs has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

Ensure comprehensive test coverage for generateSwapOperationMsgs.

The method generateSwapOperationMsgs is confirmed to be covered by unit tests in helper.spec.ts. The test case test-generateSwapOperationMsgs verifies its functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `generateSwapOperationMsgs` is covered by unit tests.

# Test: Search for test cases covering `generateSwapOperationMsgs`. Expect: Test cases should be present.
rg --type ts -A 5 'generateSwapOperationMsgs'

Length of output: 3218


Line range hint 325-360:
Ensure comprehensive test coverage for unmarshalOraiBridgeRoute.

The method unmarshalOraiBridgeRoute has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

Ensure comprehensive test coverage for unmarshalOraiBridgeRoute.

The method unmarshalOraiBridgeRoute is covered by unit tests as seen in packages/universal-swap/tests/helper.spec.ts. The test case test-unmarshalOraiBridgeRoute-%s verifies the method's functionality.

  • packages/universal-swap/tests/helper.spec.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `unmarshalOraiBridgeRoute` is covered by unit tests.

# Test: Search for test cases covering `unmarshalOraiBridgeRoute`. Expect: Test cases should be present.
rg --type ts -A 5 'unmarshalOraiBridgeRoute'

Length of output: 2411


Line range hint 460-486:
Ensure comprehensive test coverage for simulateSwapEvm.

The method simulateSwapEvm has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

Comprehensive test coverage for simulateSwapEvm verified.

The method simulateSwapEvm is covered by unit tests in the file packages/universal-swap/tests/index.spec.ts.

  • packages/universal-swap/tests/index.spec.ts: Verified usage of simulateSwapEvm in unit tests.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `simulateSwapEvm` is covered by unit tests.

# Test: Search for test cases covering `simulateSwapEvm`. Expect: Test cases should be present.
rg --type ts -A 5 'simulateSwapEvm'

Length of output: 2554


Line range hint 549-566:
Ensure comprehensive test coverage for checkFeeRelayerNotOrai.

The method checkFeeRelayerNotOrai has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

The method checkFeeRelayerNotOrai is covered by unit tests.

The search results indicate that checkFeeRelayerNotOrai is tested in packages/universal-swap/tests/index.spec.ts.

  • File: packages/universal-swap/tests/index.spec.ts
  • Lines: The method is imported and tested around lines 10 and 20.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `checkFeeRelayerNotOrai` is covered by unit tests.

# Test: Search for test cases covering `checkFeeRelayerNotOrai`. Expect: Test cases should be present.
rg --type ts -A 5 'checkFeeRelayerNotOrai'

Length of output: 2848


Line range hint 361-384:
Ensure comprehensive test coverage for generateSwapRoute.

The method generateSwapRoute has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

Comprehensive test coverage for generateSwapRoute confirmed.

The method generateSwapRoute is covered by unit tests, as evidenced by the presence of the test-generateSwapRoute test case in helper.spec.ts.

  • packages/universal-swap/tests/helper.spec.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `generateSwapRoute` is covered by unit tests.

# Test: Search for test cases covering `generateSwapRoute`. Expect: Test cases should be present.
rg --type ts -A 5 'generateSwapRoute'

Length of output: 3683


Line range hint 487-530:
Ensure comprehensive test coverage for handleSimulateSwap.

The method handleSimulateSwap has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

Verified: handleSimulateSwap is covered by unit tests.

The method handleSimulateSwap is referenced and tested in packages/universal-swap/tests/index.spec.ts, ensuring its functionality is verified through unit tests.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `handleSimulateSwap` is covered by unit tests.

# Test: Search for test cases covering `handleSimulateSwap`. Expect: Test cases should be present.
rg --type ts -A 5 'handleSimulateSwap'

Length of output: 2499


Line range hint 415-437:
Ensure comprehensive test coverage for simulateSwap.

The method simulateSwap has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

Ensure comprehensive test coverage for simulateSwap.

The method simulateSwap is well-covered by unit tests in the packages/universal-swap/tests/index.spec.ts file. The tests include direct calls, mocks, and spies, ensuring various scenarios are tested.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `simulateSwap` is covered by unit tests.

# Test: Search for test cases covering `simulateSwap`. Expect: Test cases should be present.
rg --type ts -A 5 'simulateSwap'

Length of output: 12629


Line range hint 627-654:
Ensure comprehensive test coverage for checkBalanceIBCOraichain.

The method checkBalanceIBCOraichain has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

Test coverage verified for checkBalanceIBCOraichain.

The method checkBalanceIBCOraichain is covered by unit tests as evidenced by the references found in packages/universal-swap/tests/index.spec.ts.

  • packages/universal-swap/tests/index.spec.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `checkBalanceIBCOraichain` is covered by unit tests.

# Test: Search for test cases covering `checkBalanceIBCOraichain`. Expect: Test cases should be present.
rg --type ts -A 5 'checkBalanceIBCOraichain'

Length of output: 2661


Line range hint 612-626:
Ensure comprehensive test coverage for getBalanceIBCOraichain.

The method getBalanceIBCOraichain has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

Ensure comprehensive test coverage for getBalanceIBCOraichain.

The method getBalanceIBCOraichain is adequately covered by unit tests in packages/universal-swap/tests/index.spec.ts. The tests include direct calls to the method and mock implementations, ensuring its functionality is verified.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `getBalanceIBCOraichain` is covered by unit tests.

# Test: Search for test cases covering `getBalanceIBCOraichain`. Expect: Test cases should be present.
rg --type ts -A 5 'getBalanceIBCOraichain'

Length of output: 3929


Line range hint 567-611:
Ensure comprehensive test coverage for checkBalanceChannelIbc.

The method checkBalanceChannelIbc has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

Ensure comprehensive test coverage for checkBalanceChannelIbc.

The method checkBalanceChannelIbc is covered by unit tests in index.spec.ts. This confirms that the functionality of the method is being tested.

  • File: packages/universal-swap/tests/index.spec.ts
  • Lines: References to checkBalanceChannelIbc found in multiple locations within the file.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `checkBalanceChannelIbc` is covered by unit tests.

# Test: Search for test cases covering `checkBalanceChannelIbc`. Expect: Test cases should be present.
rg --type ts -A 5 'checkBalanceChannelIbc'

Length of output: 2698


Line range hint 531-548:
Ensure comprehensive test coverage for checkFeeRelayer.

The method checkFeeRelayer has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

Comprehensive test coverage for checkFeeRelayer is confirmed.

The method checkFeeRelayer is covered by unit tests in packages/universal-swap/tests/index.spec.ts.

  • File: packages/universal-swap/tests/index.spec.ts
  • References: checkFeeRelayer
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `checkFeeRelayer` is covered by unit tests.

# Test: Search for test cases covering `checkFeeRelayer`. Expect: Test cases should be present.
rg --type ts -A 5 'checkFeeRelayer'

Length of output: 4972


Line range hint 438-459:
Ensure comprehensive test coverage for simulateSwapUsingSmartRoute.

The method simulateSwapUsingSmartRoute has been added. Ensure that it is covered by unit tests to verify its functionality.

Verification successful

The simulateSwapUsingSmartRoute method is covered by unit tests.

The unit tests for simulateSwapUsingSmartRoute are present in the packages/universal-swap/tests/index.spec.ts file, ensuring that its functionality is verified.

  • File: packages/universal-swap/tests/index.spec.ts
  • Lines: Tests for simulateSwapUsingSmartRoute are found.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `simulateSwapUsingSmartRoute` is covered by unit tests.

# Test: Search for test cases covering `simulateSwapUsingSmartRoute`. Expect: Test cases should be present.
rg --type ts -A 5 'simulateSwapUsingSmartRoute'

Length of output: 2868


228-244: Ensure comprehensive test coverage for getRouteFromOtherToOrai.

The method getRouteFromOtherToOrai has been added. Ensure that it is covered by unit tests to verify its functionality.


222-226: Ensure comprehensive test coverage for getRouteFromOraiToOther.

The method getRouteFromOraiToOther has been added. Ensure that it is covered by unit tests to verify its functionality.

packages/universal-swap/src/handler.ts (3)

2-4: Reordered imports and added new ones.

The imports have been reordered and new imports have been added. Ensure that these changes are necessary and do not introduce any issues.

Verification successful

Reordered imports and added new ones.

The imports have been reordered and new imports have been added. The GasPrice module is used multiple times in packages/universal-swap/src/handler.ts, confirming its necessity. No issues were found with the reordering or addition of this import.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of newly imported modules to ensure they are necessary.

# Test: Search for the usage of newly imported modules. Expect: At least one usage for each new import.
rg --type python -A 5 $'GasPrice'

Length of output: 63


Script:

#!/bin/bash
# Description: Verify the usage of newly imported modules to ensure they are necessary.

# Test: Search for the usage of newly imported modules. Expect: At least one usage for each new import.
rg --type typescript -A 5 'GasPrice'

Length of output: 71


Script:

#!/bin/bash
# Description: Verify the usage of newly imported modules to ensure they are necessary.

# Test: Search for the usage of newly imported modules. Expect: At least one usage for each new import.
rg --type ts -A 5 'GasPrice'

Length of output: 5635


128-128: Ensure the new method call getIbcReceiveAddr is correctly integrated.

The new method call to getIbcReceiveAddr seems correctly integrated. Verify that it does not introduce any issues.

Verification successful

The integration of getIbcReceiveAddr in the method combineSwapMsgOraichain is correctly implemented.

  • The method getIbcReceiveAddr is defined and used appropriately in packages/universal-swap/src/handler.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `getIbcReceiveAddr`.

# Test: Search for the usage of `getIbcReceiveAddr`. Expect: Proper usage in the code.
rg --type python -A 5 $'getIbcReceiveAddr'

Length of output: 72


Script:

#!/bin/bash
# Description: Verify the integration of `getIbcReceiveAddr`.

# Test: Search for the usage of `getIbcReceiveAddr`. Expect: Proper usage in the code.
rg --type typescript -A 5 'getIbcReceiveAddr'

Length of output: 80


Script:

#!/bin/bash
# Description: Verify the integration of `getIbcReceiveAddr`.

# Test: Search for the usage of `getIbcReceiveAddr`. Expect: Proper usage in the code.
rg --type ts -A 5 'getIbcReceiveAddr'

Length of output: 1217


592-592: Ensure the new method call getMessagesAndMsgTransfers is correctly integrated.

The new method call to getMessagesAndMsgTransfers seems correctly integrated. Verify that it does not introduce any issues.

Verification successful

The new method call getMessagesAndMsgTransfers is correctly integrated and does not introduce any issues.

  • The method getMessagesAndMsgTransfers is defined and used appropriately in packages/universal-swap/src/handler.ts.
  • It is also referenced in the test file packages/universal-swap/tests/index.spec.ts, ensuring its functionality is tested.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `getMessagesAndMsgTransfers`.

# Test: Search for the usage of `getMessagesAndMsgTransfers`. Expect: Proper usage in the code.
rg --type python -A 5 $'getMessagesAndMsgTransfers'

Length of output: 81


Script:

#!/bin/bash
# Description: Verify the integration of `getMessagesAndMsgTransfers`.

# Test: Search for the usage of `getMessagesAndMsgTransfers`. Expect: Proper usage in the code.
rg --type typescript -A 5 'getMessagesAndMsgTransfers'

Length of output: 89


Script:

#!/bin/bash
# Description: Verify the integration of `getMessagesAndMsgTransfers`.

# Test: Search for the usage of `getMessagesAndMsgTransfers`. Expect: Proper usage in the code.
rg --type ts -A 5 'getMessagesAndMsgTransfers'

Length of output: 1392

packages/universal-swap/tests/index.spec.ts (5)

Line range hint 61-153: Verify the correctness of constants and class definitions.

Ensure that the constants are correctly defined and used. Verify the logic and correctness of the class definitions.


Line range hint 270-1049: Verify the correctness and completeness of test cases.

Ensure that the test cases are correctly defined and cover all necessary scenarios. Verify the correctness of the test logic and assertions.


Line range hint 154-269: Verify the correctness of beforeAll and beforeEach setup.

Ensure that the setup is correctly performed and that there are no issues with the deployment of contracts or initialization of variables.


Line range hint 1050-1054: Verify the correctness of utility functions and helpers.

Ensure that the utility functions and helpers are correctly defined and used. Verify the logic and correctness of the utility functions and helpers.

Verification successful

The utility functions and helpers are correctly defined and used.

  • isEvmSwappableSpy is correctly defined as a spy using vi.spyOn.
  • handleSimulateSwap is correctly defined in UniversalSwapHelper and properly imported and used.
  • oraichainTokens is correctly imported from @oraichain/oraidex-common.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of utility functions and helpers.

# Test: Search for the usage of each utility function and helper. Expect: Each utility function and helper should be correctly defined and used.
rg --type typescript -A 5 $'function'

Length of output: 71


Script:

#!/bin/bash
# Description: Verify the correctness of utility functions and helpers.

# Test: Search for the definitions and usages of utility functions and helpers used in the provided snippet.

# Search for the definition of `isEvmSwappableSpy`
rg 'isEvmSwappableSpy' -t ts -A 5

# Search for the definition of `handleSimulateSwap`
rg 'handleSimulateSwap' -t ts -A 5

# Search for the definition of `oraichainTokens`
rg 'oraichainTokens' -t ts -A 5

Length of output: 16301


Line range hint 1-60: Verify the correctness and necessity of import statements.

Ensure that all imported modules are necessary and correctly used in the file. Verify that the import paths are correct and that there are no unused imports.

Verification successful

All imported modules are correctly used in the file.

The verification confirms that each imported module in packages/universal-swap/tests/index.spec.ts is necessary and correctly used in the file.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness and necessity of import statements.

# Test: Search for the usage of each imported module. Expect: Each imported module should be used in the file.
rg --type typescript -A 5 $'import'

Length of output: 69


Script:

#!/bin/bash
# Description: Verify the correctness and necessity of import statements.

# Test: Search for the usage of each imported module in the TypeScript file.
rg 'DirectSecp256k1HdWallet|EncodeObject|OfflineSigner|JsonRpcProvider|JsonRpcSigner|AIRI_BSC_CONTRACT|AIRI_CONTRACT|BigDecimal|CoinGeckoId|CosmosWallet|EvmWallet|IBC_TRANSFER_TIMEOUT|IBC_WASM_CONTRACT|IBC_WASM_CONTRACT_TEST|NetworkChainId|ORAI_BRIDGE_EVM_DENOM_PREFIX|ORAI_BRIDGE_EVM_TRON_DENOM_PREFIX|OSMOSIS_ORAICHAIN_DENOM|OSMOSIS_ROUTER_CONTRACT|ROUTER_V2_CONTRACT|TokenItemType|USDC_CONTRACT|USDT_CONTRACT|calculateTimeoutTimestamp|flattenTokens|oraichain2osmosis|oraichainTokens|toDisplay|toTokenInfo|dexCommonHelper|toBinary|fromUtf8|toUtf8|CwIcs20LatestClient|CWSimulateApp|GenericError|IbcOrder|IbcPacket|SimulateCosmWasmClient|ibcInfos|oraichain2oraib|oraidexArtifacts|OraiswapFactoryClient|OraiswapOracleClient|OraiswapRouterClient|OraiswapRouterQueryClient|OraiswapTokenClient|readFileSync|Long|TronWeb|beforeAll|beforeEach|describe|expect|it|vi|UniversalSwapHandler|UniversalSwapHelper|checkBalanceChannelIbc|checkBalanceIBCOraichain|checkFeeRelayer|checkFeeRelayerNotOrai|getBalanceIBCOraichain|getIbcInfo|handleSimulateSwap|simulateSwap|Routes|UniversalSwapConfig|UniversalSwapData|UniversalSwapType' packages/universal-swap/tests/index.spec.ts

Length of output: 31675

Copy link

sonarcloud bot commented Jul 19, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b559194 and 2fdb57e.

Files selected for processing (1)
  • sonar-project.properties (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sonar-project.properties

@trungbach trungbach changed the title Feat/odex 974 Refactor code reported by Sonarqube Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants