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

[TRA-530] When changing market pair name, validate that new pair exists in the market map #2151

Merged
merged 7 commits into from
Sep 12, 2024

Conversation

hwray
Copy link
Contributor

@hwray hwray commented Aug 23, 2024

Changelist

  • When changing market pair name, validate that new pair exists in the market map

Test Plan

  • Updated tests in market_param_test.go:
    • Changed "valid" tests to enforce that new pair ticker exists in MarketMap
    • Added new "error" test to ensure the correct error is fired upon failure

Author/Reviewer Checklist

  • [] If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • [] If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • [] If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • [] If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • [] If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced validation for modifying market parameters, ensuring only valid market parameters are processed.
    • Improved error handling when updating market parameters related to tickers.
  • Bug Fixes

    • Expanded test cases for error handling in market parameter modifications to cover scenarios where the ticker is absent in the MarketMap.
  • Tests

    • Updated test cases to ensure robustness in the modification and error handling of market parameters, including new scenarios for invalid pairs.

@hwray hwray added the bug Something isn't working label Aug 23, 2024
Copy link
Contributor

coderabbitai bot commented Aug 23, 2024

Walkthrough

The changes enhance the ModifyMarketParam function within the Keeper struct by adding validation steps to ensure the modified market parameter corresponds to an existing ticker in the MarketMap. The validation process includes converting the market pair and checking its existence in the MarketMap. Additionally, the test cases have been updated to reflect these changes, incorporating new scenarios for error handling and ensuring the proper creation of tickers before updates.

Changes

Files Change Summary
protocol/x/prices/keeper/market_param.go Modified ModifyMarketParam function to return an error, adding validation for the market parameter's ticker and ensuring it exists in the MarketMap.
protocol/x/prices/keeper/market_param_test.go Updated test cases to require ticker creation in the MarketMap before updates and expanded error handling with additional test scenarios for non-existent pairs.

Poem

🐰 In the market where values dance,
The Keeper now takes a careful stance.
Tickers checked, no pair goes amiss,
With every change, a hop of bliss!
So let’s cheer for the code’s fine tune,
A brighter market, beneath the moon! 🌙


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 70f54af and e01f418.

Files selected for processing (2)
  • protocol/x/prices/keeper/market_param.go (2 hunks)
  • protocol/x/prices/keeper/market_param_test.go (5 hunks)
Additional comments not posted (7)
protocol/x/prices/keeper/market_param.go (2)

53-60: LGTM!

The validation steps introduced in this code segment align with the PR objectives and ensure the integrity of the market data. The error handling and messages provide clear information about the validation failures.

The past review comments suggesting validation before conversion, handling specific error types, and optimizing the market map lookup have been addressed in the current implementation.


73-73: LGTM!

The simplification of the caching logic by removing the error handling is a valid assumption since the currency pair has already been validated in the previous code segment. This change improves the readability of the code.

protocol/x/prices/keeper/market_param_test.go (5)

9-9: LGTM!

The import statement for marketmapkeeper is necessary to access the market map functionality in the tests.


80-88: LGTM!

Creating the new ticker in the MarketMap before updating the MarketParam.Pair is the correct approach. This ensures that the necessary condition of having a corresponding ticker in the MarketMap is met before attempting to update the market parameter's pair.


91-92: LGTM!

The market parameter modification using the ModifyMarketParam function is correctly implemented, and the error is properly checked.


109-111: LGTM!

The variable declarations for invalidUpdatePair and invalidUpdateCurrencyPair are correct and will be used in the new test case for error handling.


Line range hint 175-196: LGTM!

The new test case for the error scenario when updating a market parameter with an invalid pair that does not exist in the MarketMap is well-structured and correctly checks the expected error. The error message construction using errorsmod.Wrapf is accurate.

This test case enhances the robustness of the error handling by ensuring that the system correctly identifies and responds to the absence of a ticker in the MarketMap, as mentioned in the AI-generated summary.


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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@hwray hwray marked this pull request as ready for review August 26, 2024 20:11
@hwray hwray requested a review from a team as a code owner August 26, 2024 20:11
Copy link
Contributor

@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 e5a5f06 and bf1da8a.

Files selected for processing (2)
  • protocol/x/prices/keeper/market_param.go (1 hunks)
  • protocol/x/prices/keeper/market_param_test.go (5 hunks)
Additional comments not posted (7)
protocol/x/prices/keeper/market_param.go (2)

53-57: Ensure proper error handling for market pair conversion.

The new validation step correctly checks if the market pair can be converted to a currency pair. However, ensure that the error handling provides sufficient context for debugging.

The code changes are approved.


58-60: Ensure proper error handling for ticker existence check.

The new validation step correctly checks if the ticker exists in the MarketMap. However, ensure that the error handling provides sufficient context for debugging.

The code changes are approved.

protocol/x/prices/keeper/market_param_test.go (5)

80-90: Ensure the new ticker is created in the MarketMap.

The new validation step correctly ensures that the new ticker is created in the MarketMap before updating the MarketParam.

The code changes are approved.


91-92: Ensure proper error handling for market param modification.

The new validation step correctly ensures that the market param modification is handled properly.

The code changes are approved.


109-112: Ensure proper error handling for invalid update pair.

The new test case correctly checks for failures when attempting to update a pair that does not exist in the MarketMap.

The code changes are approved.


186-196: Ensure proper error handling for missing ticker in MarketMap.

The new test case correctly checks for failures when the ticker is not found in the MarketMap.

The code changes are approved.


9-9: Ensure proper import of marketmapkeeper.

The new import statement correctly includes the marketmapkeeper package.

The code changes are approved.

Copy link
Contributor

@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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bf1da8a and 70f54af.

Files selected for processing (1)
  • protocol/x/prices/keeper/market_param.go (2 hunks)
Additional comments not posted (1)
protocol/x/prices/keeper/market_param.go (1)

73-73: Ensure cache consistency.

Ensure that the cache update logic is consistent and handles edge cases, such as concurrent modifications to the market parameters.

Verify that the cache update logic is consistent and handles edge cases. Consider adding tests to cover these scenarios.

protocol/x/prices/keeper/market_param.go Show resolved Hide resolved
protocol/x/prices/keeper/market_param.go Show resolved Hide resolved
protocol/x/prices/keeper/market_param.go Show resolved Hide resolved
Signed-off-by: Harry Wray <[email protected]>
Signed-off-by: Harry Wray <[email protected]>
Signed-off-by: Harry Wray <[email protected]>
Signed-off-by: Harry Wray <[email protected]>
Signed-off-by: Harry Wray <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working protocol
Development

Successfully merging this pull request may close these issues.

4 participants