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

fix(systemtests): to avoid invalid order_by used in TestGetTxEvents_GRPCGateway #23290

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

Conversation

mmsqe
Copy link
Contributor

@mmsqe mmsqe commented Jan 10, 2025

Description

Closes: #XXXX


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

  • Tests
    • Updated transaction event tests to enhance type safety and error handling.
    • Improved validation for ordering transactions in test cases.
    • Refined test assertions for better readability and consistency.

@mmsqe mmsqe requested a review from a team as a code owner January 10, 2025 02:59
Copy link
Contributor

coderabbitai bot commented Jan 10, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The pull request introduces modifications to the TestGetTxEvents_GRPCGateway function in the system tests for transaction querying. Key updates include the transition from string-based to integer-based enumeration constants for transaction ordering, enhancing type safety. Additionally, new test cases validate ordering by ascending and descending integers, while improved error handling addresses invalid order scenarios. Changes to the createMessage function in the gRPC gateway enhance error handling by allowing specific errors to be ignored, modifying the control flow for more lenient processing.

Changes

File Change Summary
tests/systemtests/tx_test.go - Updated transaction ordering query parameters to use integer constants
- Added test cases for ascending, descending, and invalid order scenarios
- Modified equality checks in test assertions for consistency
server/v2/api/grpcgateway/uri.go - Altered error handling logic in createMessage to ignore specific errors related to "order_by"

Possibly related PRs

Suggested labels

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

Suggested reviewers

  • julienrbrt
  • facundomedica
  • akhilkumarpilli
  • sontrinh16

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.

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 (1)
tests/systemtests/tx_test.go (1)

378-379: Consider using a named constant for the invalid order value.

While the test correctly validates error handling for invalid order values, using a magic number (777) reduces code readability. Consider defining a constant for this test value.

+const invalidOrderBy = 777 // Value outside valid tx.OrderBy range
+
 {
   "invalid request: invalid order by",
-  fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s&query=%s&order_by=%d", baseURL, bankMsgSendEventAction, "message.module='bank'", 777),
+  fmt.Sprintf("%s/cosmos/tx/v1beta1/txs?query=%s&query=%s&order_by=%d", baseURL, bankMsgSendEventAction, "message.module='bank'", invalidOrderBy),
   true,
   "is not a valid tx.OrderBy", 0,
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 517839b and 7aa1040.

📒 Files selected for processing (1)
  • tests/systemtests/tx_test.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
tests/systemtests/tx_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"

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: tests (00)
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (3)
tests/systemtests/tx_test.go (3)

366-367: LGTM! Good use of type-safe constants.

The change from string literals to integer constants (tx.OrderBy_ORDER_BY_ASC) improves type safety and maintainability.


372-373: LGTM! Consistent use of type-safe constants.

The change maintains consistency with the ascending order case by using the integer constant tx.OrderBy_ORDER_BY_DESC.


404-404: LGTM! Clear assertion of expected results.

The assertion correctly validates the number of transactions returned matches the expected length.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

Given that it passes in v0.52 x baseapp, this is IMHO a regression, so we should keep the current behavior in v2 and investigate this.

@mmsqe
Copy link
Contributor Author

mmsqe commented Jan 10, 2025

Given that it passes in v0.52 x baseapp, this is IMHO a regression, so we should keep the current behavior in v2 and investigate this.

v0.52 also use enum for order_by right?

@julienrbrt
Copy link
Member

julienrbrt commented Jan 10, 2025

Given that it passes in v0.52 x baseapp, this is IMHO a regression, so we should keep the current behavior in v2 and investigate this.

v0.52 also use enum for order_by right?

Yeah, it uses the enum name, not its value.

In release/v0.52.x:

simapp

$ go test -mod=readonly -failfast -timeout=15m -tags='system_test' --run TestGetTxEvents_GRPCGateway ./... --wait-time=45s --verbose
PASS

simapp v2

$ go test -mod=readonly -failfast -timeout=15m -tags='system_test' --run TestGetTxEvents_GRPCGateway ./... --wait-time=45s --verbose --binary=simdv2
FAILED

So it is a regression in v2.

@julienrbrt
Copy link
Member

It looks like however it is the same handling:

func parseOrderBy(orderBy txtypes.OrderBy) string {
vs
func parseOrderBy(orderBy txtypes.OrderBy) string {
so a bit confused of the difference in behavior 😅

@julienrbrt
Copy link
Member

Looks like both enum values and enum string works in 0.52 but only enum values work in v2.
While it is the same grpc gateway routes being registered, and it looks like the same grpc service implementation. Very weird

@mmsqe
Copy link
Contributor Author

mmsqe commented Jan 10, 2025

Looks like both enum values and enum string works in 0.52 but only enum values work in v2. While it is the same grpc gateway routes being registered, and it looks like the same grpc service implementation. Very weird

not sure, v2 also don't have swagger yet

@github-actions github-actions bot added C:server/v2 Issues related to server/v2 C:server/v2 api labels Jan 10, 2025
@mmsqe mmsqe marked this pull request as draft January 10, 2025 16:15
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7aa1040 and eb1e0c9.

📒 Files selected for processing (2)
  • server/v2/api/grpcgateway/uri.go (1 hunks)
  • tests/systemtests/tx_test.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/systemtests/tx_test.go
🧰 Additional context used
📓 Path-based instructions (1)
server/v2/api/grpcgateway/uri.go (1)

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

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: tests (00)
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: Summary

Comment on lines +181 to 183
err = decoder.Decode(nestedParams)
if err != nil && !strings.Contains(err.Error(), "order_by") {
return nil, status.Error(codes.InvalidArgument, err.Error())
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 10, 2025

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Critical: Error masking prevents proper enum validation

The verification confirms this is a problematic implementation:

  • It's the only instance in the codebase that silently ignores errors based on error message content
  • The OrderBy enum is properly defined in protobuf, suggesting it should handle both numeric and string values correctly
  • This error masking approach hides potential validation issues instead of properly supporting enum string values

Consider implementing proper enum string support by:

  1. Using protobuf's built-in enum string handling
  2. Adding explicit validation for enum values
  3. Properly documenting supported formats in the API
🔗 Analysis chain

Critical: Avoid masking decoding errors based on error message content

The current change ignores decoding errors that contain "order_by" in their message. This is problematic for several reasons:

  1. It could mask legitimate errors that happen to contain "order_by" in their message
  2. It makes the behavior inconsistent with the documentation
  3. It doesn't address the root cause of why enum strings stopped working in v2 while they work in v0.52

Consider implementing a proper fix that addresses the root cause:

  1. Implement proper enum string support in v2 to maintain compatibility with v0.52
  2. If enum strings must be deprecated, provide clear documentation and migration guide
  3. Add proper validation for enum values instead of relying on error message content

Let's verify if this change affects other enum parameters:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other enum parameters that might be affected
echo "Searching for other enum parameters in proto definitions..."
rg -l "enum.*{" | while read -r file; do
  echo "=== $file ==="
  ast-grep --pattern 'enum $enumName {
    $$$
  }' "$file"
done

echo "Searching for similar error handling patterns..."
rg 'if.*err.*Contains.*\(.*Error.*\).*{' 

Length of output: 523


Script:

#!/bin/bash
# Find proto files and enum definitions
echo "=== Proto files with enums ==="
fd '\.proto$' | xargs rg -l 'enum\s+\w+\s*{'

echo -e "\n=== Enum definitions ==="
fd '\.proto$' | xargs rg -A 5 'enum\s+\w+\s*{'

echo -e "\n=== Similar error handling patterns ==="
# Search for error string checks in Go files
rg -t go 'if.*err.*Contains.*\(' -A 2

echo -e "\n=== Specific file context ==="
# Get more context around the modified code
rg -t go 'decoder\.Decode.*nestedParams' -A 5 server/v2/api/grpcgateway/uri.go

Length of output: 3805


Script:

#!/bin/bash
# Find proto files with enum definitions
echo "=== Proto files with enums ==="
find . -name "*.proto" -type f -exec grep -l "enum" {} \;

echo -e "\n=== Enum definitions ==="
find . -name "*.proto" -type f -exec grep -B1 -A5 "enum.*{" {} \;

echo -e "\n=== Transaction related protos ==="
find . -name "*.proto" -type f -exec grep -l "Transaction\|Order" {} \;

Length of output: 8192

Copy link
Contributor Author

@mmsqe mmsqe Jan 11, 2025

Choose a reason for hiding this comment

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

@julienrbrt seems fixed by PopulateQueryParameters instead of decode now

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

@julienrbrt
Copy link
Member

Looks like both enum values and enum string works in 0.52 but only enum values work in v2. While it is the same grpc gateway routes being registered, and it looks like the same grpc service implementation. Very weird

not sure, v2 also don't have swagger yet

yes, swagger is being added here: #23092

@technicallyty
Copy link
Contributor

i think this may be fixed in #23262. haven't tested yet though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:server/v2 api C:server/v2 Issues related to server/v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants