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-505] Add x/listing testing framework and test for CreateMarket #1974

Merged
merged 11 commits into from
Jul 31, 2024

Conversation

shrenujb
Copy link
Contributor

@shrenujb shrenujb commented Jul 26, 2024

Changelist

[Describe or list the changes made in this PR]

Test Plan

[Describe how this PR was tested (if applicable)]

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

  • New Features

    • Enhanced the listing module with additional functionalities through new dependencies.
    • Introduced a testing framework for listing keepers to improve testing capabilities.
    • Added functionality to better handle market creation logic with specific error messages.
  • Bug Fixes

    • Improved error handling in the CreateMarket function to return a specific error for market not found.
  • Tests

    • Implemented a comprehensive test suite for the market creation functionality, validating both valid and invalid inputs.
  • Documentation

    • Updated error declarations for clearer communication of issues within the listing protocol.

shrenujb added 4 commits July 26, 2024 12:30
Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
Copy link

linear bot commented Jul 26, 2024

Copy link
Contributor

coderabbitai bot commented Jul 26, 2024

Walkthrough

The recent changes enhance modularity and functionality in the blockchain application by integrating additional keepers into the listingModule. This expansion allows for more complex interactions and improved error handling, providing clearer feedback. New testing frameworks have been introduced to rigorously validate the market creation logic. Overall, these enhancements represent a significant architectural improvement, enabling a more robust and flexible application.

Changes

Files Change Summary
protocol/app/app.go, protocol/x/listing/module.go Expanded listingModule instantiation and updated AppModule struct to include new keepers, enhancing module functionality.
protocol/testutil/app/app.go Added support for listingtypes.GenesisState in UpdateGenesisDocWithAppStateForModule, facilitating additional module states.
protocol/testutil/keeper/listing.go Introduced listing.go to manage and test listing keepers, enhancing the testing framework.
protocol/x/listing/keeper/listing.go Improved error handling in CreateMarket, now returning ErrMarketNotFound for better clarity.
protocol/x/listing/keeper/listing_test.go New test suite for market creation, validating functionality against valid and invalid ticker inputs.
protocol/x/listing/types/errors.go Introduced ErrMarketNotFound for more specific error reporting, improving error semantics in the listing protocol.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant ListingModule
    participant MarketKeeper
    participant ErrorHandler

    App->>ListingModule: Create Market
    ListingModule->>MarketKeeper: Validate Ticker
    MarketKeeper-->>ErrorHandler: Ticker Valid?
    alt Valid Ticker
        MarketKeeper->>ListingModule: Market Created
    else Invalid Ticker
        MarketKeeper-->>ErrorHandler: ErrMarketNotFound
        ErrorHandler->>ListingModule: Return Error
    end
Loading

🐰 In fields so bright, the changes take flight,
New keepers and modules, a wondrous delight.
With markets created and errors refined,
The code hops along, leaving worries behind!
Let's celebrate growth, in every line! 🎉


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
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 5613a42 and 1db0f08.

Files selected for processing (7)
  • protocol/app/app.go (1 hunks)
  • protocol/testutil/app/app.go (2 hunks)
  • protocol/testutil/keeper/listing.go (1 hunks)
  • protocol/x/listing/keeper/listing.go (1 hunks)
  • protocol/x/listing/keeper/listing_test.go (1 hunks)
  • protocol/x/listing/module.go (1 hunks)
  • protocol/x/listing/types/errors.go (1 hunks)
Additional comments not posted (10)
protocol/x/listing/types/errors.go (2)

7-11: LGTM!

The new error declaration ErrMarketNotFound is correctly registered and follows the existing pattern.


13-17: LGTM!

The error declaration ErrReferencePriceZero is correctly registered and follows the existing pattern.

protocol/x/listing/keeper/listing_test.go (1)

15-67: LGTM!

The test case TestCreateMarket is correctly implemented, covers the intended scenarios, and follows best practices.

protocol/testutil/keeper/listing.go (2)

25-71: LGTM!

The utility function ListingKeepers is correctly implemented and follows best practices.


74-103: LGTM!

The utility function createListingKeeper is correctly implemented and follows best practices.

protocol/x/listing/keeper/listing.go (1)

45-45: Improved error handling.

The error handling has been made more specific by returning types.ErrMarketNotFound. This improves the clarity of the error.

protocol/x/listing/module.go (2)

101-105: Enhanced functionality with additional keepers.

The AppModule struct now includes four new fields: pricesKeeper, clobKeeper, marketMapKeeper, and perpetualsKeeper. This enhances the module's functionality.


111-122: Proper initialization of new keepers.

The constructor function NewAppModule has been updated to accept and initialize the new keeper parameters. This ensures proper initialization of the new fields.

protocol/testutil/app/app.go (1)

270-271: Extended functionality to support listingtypes.GenesisState.

The function UpdateGenesisDocWithAppStateForModule now includes a case for listingtypes.GenesisState, enhancing its capability to process the listing module's GenesisState.

protocol/app/app.go (1)

1171-1178: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to listingModule match the new signature.

Verification successful

LGTM! But verify the function usage in the codebase.

The code changes are approved.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `listingModule` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'listingmodule.NewAppModule'

Length of output: 307

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 1db0f08 and 1a53135.

Files selected for processing (3)
  • protocol/testutil/keeper/listing.go (1 hunks)
  • protocol/x/listing/keeper/listing.go (5 hunks)
  • protocol/x/listing/keeper/listing_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • protocol/testutil/keeper/listing.go
  • protocol/x/listing/keeper/listing.go
  • protocol/x/listing/keeper/listing_test.go

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 1a53135 and 4d8e718.

Files selected for processing (2)
  • protocol/app/app.go (1 hunks)
  • protocol/x/listing/keeper/listing_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/app/app.go
  • protocol/x/listing/keeper/listing_test.go

shrenujb added 2 commits July 31, 2024 11:10
Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
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 4d8e718 and 4d3d6c5.

Files selected for processing (1)
  • protocol/x/listing/keeper/listing_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/x/listing/keeper/listing_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants