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

test(integration): port types tests to server v2 #22981

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

Conversation

akhilkumarpilli
Copy link
Contributor

@akhilkumarpilli akhilkumarpilli commented Dec 18, 2024

Description

ref: #20799


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • Refactoring

    • Updated test suite for pagination functionality
    • Transitioned from store-based to context and bank keeper-based approach
    • Simplified pagination logic using collection-based methods
  • Tests

    • Improved test coverage for pagination operations
    • Updated test methods to use new context and query mechanisms
  • Code Structure

    • Renamed package from query_test to types
    • Modified import statements and function signatures
    • Introduced new query client and updated keeper types

Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

📝 Walkthrough

Walkthrough

This pull request focuses on refactoring pagination-related test files in the tests/integration/v2/types/ directory. The changes involve transitioning from a store-based to a context and bank keeper-based approach for pagination operations. The package name has been changed from query_test to types, and import statements have been updated. The modifications streamline the pagination logic by utilizing query.CollectionFilteredPaginate and query.CollectionPaginate, simplifying the filtering and pagination processes across multiple test files.

Changes

File Change Summary
tests/integration/v2/types/filtered_pagination_test.go - Transitioned from store-based to context and bank keeper-based pagination
- Updated execFilterPaginate function signature
- Simplified filtering logic using query.CollectionFilteredPaginate
tests/integration/v2/types/fuzz_test.go - Refactored FuzzPagination function
- Replaced manual pagination with query.CollectionPaginate
- Changed package name from query_test to types
tests/integration/v2/types/pagination_test.go - Updated package name to types
- Modified paginationTestSuite structure
- Replaced sdk.Context with context.Context
- Updated SetupTest and test methods to use new pagination approach

Sequence Diagram

sequenceDiagram
    participant Test as Test Function
    participant Keeper as Bank Keeper
    participant Query as Collection Query
    participant Context as Context

    Test->>Context: Create Context
    Test->>Keeper: Initialize Bank Keeper
    Test->>Query: CollectionPaginate/CollectionFilteredPaginate
    Query-->>Keeper: Request Paginated Results
    Keeper-->>Query: Return Paginated Data
    Query-->>Test: Provide Paginated Results
Loading

Possibly related PRs

Suggested labels

C:server/v2, backport/v0.52.x

Suggested reviewers

  • kocubinski
  • tac0turtle
  • julienrbrt
  • hieuvubk

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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.

@akhilkumarpilli akhilkumarpilli marked this pull request as ready for review January 2, 2025 05:28
@akhilkumarpilli akhilkumarpilli requested a review from a team as a code owner January 2, 2025 05:28
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

🧹 Nitpick comments (7)
tests/integration/v2/types/filtered_pagination_test.go (5)

45-45: Repeated pagination call
This appears to replicate the same query. If the purpose is to state that repeated calls yield the same result, consider clarifying via comments or removing duplication.


85-85: Offset-based pagination
It’s good to observe offset usage. Consider also testing offset that exactly equals total to ensure no off-by-one.


192-193: Fuzz output logging
Printing partial results is useful for debugging. Verify if structured logging might improve clarity.


222-228: Inlined function within the test
This local definition is short and specialized, which can be fine. If you need repeated usage, consider refactoring out to avoid duplication.


242-242: Boundary condition
Consider verifying the boundary offset precisely equals total balances to ensure no out-of-bounds.

tests/integration/v2/types/pagination_test.go (2)

114-114: Local alias for s.queryClient
Capturing queryClient := s.queryClient might improve legibility.


223-223: Separate queryClient reference
Reassigning queryClient := s.queryClient is optional but can be more readable.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d39d0bc and 74ae5fb.

📒 Files selected for processing (3)
  • tests/integration/v2/types/filtered_pagination_test.go (11 hunks)
  • tests/integration/v2/types/fuzz_test.go (2 hunks)
  • tests/integration/v2/types/pagination_test.go (22 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
tests/integration/v2/types/fuzz_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/v2/types/filtered_pagination_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

tests/integration/v2/types/pagination_test.go (3)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

🔇 Additional comments (45)
tests/integration/v2/types/fuzz_test.go (3)

1-1: Use of the types package name
This change from query_test to types is consistent with the new layout. Ensure any references to the old name are removed from docstrings and comments.


9-9: Imports for collection-based pagination
The newly added imports from cosmossdk.io/collections, cosmossdk.io/math, and cosmossdk.io/x/bank/testutil align with your transition to the collection-based approach.


85-88: Recheck error handling in fuzz scenario
Currently, _ = query.CollectionPaginate(...) discards any error. If not intentional, consider at least logging or asserting errors to help diagnose unexpected issues in the fuzz environment.

tests/integration/v2/types/filtered_pagination_test.go (15)

1-9: Switch to types package and updated imports
Shifting the package name from query_test to types and introducing packages like context, bankkeeper, and collections is consistent with your new architecture. Verify that all references to the old package name are indeed updated.


39-39: Pagination limit check
Verifying behavior when limit exceeds total. Good to confirm the function returns only available items.


54-54: Confirm nextKey presence
Checking res.NextKey ensures multi-page coverage. This test guards against pagination boundary mishaps.


64-64: Assert invalid request
Good to see you’re testing error handling when both key and offset are provided.


69-69: Valid nextKey usage
Probing the scenario of a remaining page helps ensure correct multi-page continuity.


77-77: Default limit on zero
Verifying that a limit of 0 triggers default behavior. Helpful coverage.


111-111: Reverse pagination with limit > total
Ensuring it defaults to the total record count is a valuable check.


117-117: Nil PageRequest
Testing the null request scenario helps ensure robust default logic.


126-126: Reverse default limit
Confirming consistency in reverse mode.


134-134: Partial results in reverse
This test ensures partial retrieval logic is correct when reversed.


144-144: Error path for reverse
Confirming that specifying both key and offset in reverse also produces an error.


149-149: Continuing reversed pagination
Ensures multi-chunk query flow works correctly.


158-158: Reversed final page
Checks no NextKey is provided when returning the last chunk in reverse.


199-206: execFilterPaginate with CollectionFilteredPaginate
This function properly demonstrates filtered collection pagination. Consider advanced filters for negative or zero amounts if needed.


233-233: Offset usage check
Testing multiple offset scenarios ensures broad coverage.

tests/integration/v2/types/pagination_test.go (27)

1-30: Package and imports update
Transitioning from query_test to types while introducing multiple new imports is consistent with the new v2 test structure. Make sure all references to the old package name are removed throughout.


46-53: paginationTestSuite fields
Adding ctx, bankKeeper BaseKeeper, and queryClient bankkeeper.Querier aligns with the shift to the new application design. Confirm each field is exercised in your tests.


61-85: SetupTest with integration.NewApp
Refactoring the setup via module config and app creation simplifies the environment. Confirm modules listed in moduleConfigs are all necessary.


87-87: Context from StateLatestContext
Fetching the latest context ensures tests align with the most recent chain state.


89-89: Query client initialization
bankkeeper.NewQuerier integrally ties into the new system.


135-135: Checking CountTotal
Verifies total record count is exposed properly when requested.


144-144: Over-limit boundary
Ensures retrieving more records than allowed gracefully caps at the expected maximum.


153-153: Partial retrieval test
Testing partial page requests with CountTotal = true clarifies the total count in truncated responses.


162-162: Disable total
Correctly verifying that Total is zero when CountTotal is false.


171-171: Key-based follow-up
Leveraging NextKey from the prior response is essential for multi-page verification.


180-180: Last page check
Ensures final chunk is smaller than the limit and NextKey is nil.


190-190: Offset-based scenario
Skipping records with offset coverage is well tested.


200-200: Detect conflicting offset and key
Helps capture invalid usage early.


209-209: Error scenario
Produces the expected error message for offset + nextKey usage.


216-216: Offset beyond total
Verifies zero records are returned when offset is out of range.


244-244: Reverse partial retrieval
Ensures reversed queries respect the limit and produce a valid NextKey if records remain.


252-252: High limit reversed
Testing large-limits in reverse checks boundary correctness.


261-261: Key-based reverse
Shows usage of NextKey in reverse mode.


270-270: Offset in reverse
Tests offset interplay with reversed pagination logic.


279-279: Last page reverse
Ensures final chunk is smaller than the limit with no NextKey.


288-288: Over-limit reversed
Confirms limit is enforced in reverse.


297-297: Multi-page reverse
Repeated calls with NextKey and CountTotal=false confirm multi-page retrieval.


309-309: Chaining reversed pages
Ensures continuity of NextKey across multiple reverse requests.


321-321: Reverse final chunk
Verifies the last chunk is returned and NextKey is nil in reverse pagination.


333-333: Invalid combination in reverse
Ensures consistent error for offset+NextKey usage in reverse mode.


340-340: Empty result on out-of-bound offset
Correct reverse logic for offset greater than total.


369-373: Manual CollectionPaginate snippet
This example highlights advanced usage of the collection-based pagination in integration tests.

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.

3 participants