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(server/v2/cometbft): Add Consensus query p2p, app, grpc #22771

Merged
merged 8 commits into from
Dec 5, 2024

Conversation

hieuvubk
Copy link
Contributor

@hieuvubk hieuvubk commented Dec 5, 2024

Description

Closes: #21475

  • expand abci test
  • update SimulationResponse

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

  • New Features
    • Introduced new test functions for validating gRPC, P2P, and application-specific query mechanisms.
  • Bug Fixes
    • Enhanced error handling in the simulation response to prevent nil pointer dereference issues.
  • Refactor
    • Renamed existing test function for clarity and improved focus on state storage querying.
  • Chores
    • Improved the structure and maintainability of the testing suite for consensus functionalities.

@hieuvubk hieuvubk requested review from facundomedica, sontrinh16 and a team as code owners December 5, 2024 08:32
Copy link
Contributor

coderabbitai bot commented Dec 5, 2024

Caution

Review failed

The head commit changed during the review from 358bebb to 13128cb.

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request enhance the testing framework for consensus-related functionalities in the server/v2/cometbft/abci_test.go file by adding new test functions for gRPC, P2P, and application-specific queries. The existing query test function has been renamed for clarity. Additionally, improvements in error handling have been made in the server/v2/cometbft/utils.go file to prevent potential nil pointer dereference issues. Overall, these modifications aim to ensure comprehensive validation of query handling within the consensus mechanism.

Changes

Files Change Summary
server/v2/cometbft/abci_test.go Added new test functions: TestConsensus_GRPCQuery, TestConsensus_P2PQuery, TestConsensus_AppQuery. Renamed TestConsensus_Query to TestConsensus_QueryStore. Updated setup function to include queryHandlersMap. Enhanced query handling logic.
server/v2/cometbft/utils.go Modified intoABCISimulationResponse to improve error handling by introducing errMsg.

Assessment against linked issues

Objective Addressed Explanation
Cover GRPC request in tests (#21475)
Cover app request in tests (#21475)
Cover p2p request in tests (#21475)

Possibly related PRs

  • test(server/v2/cometbft): Add abci unit tests #21020: This PR adds unit tests for the ABCI functionalities in server/v2/cometbft/abci_test.go, which is directly related to the modifications made in the main PR that enhance the testing framework for consensus-related functionalities in the same file.
  • ci: actually enable v2 system test #21539: This PR includes changes to the CheckTx function in server/v2/cometbft/abci.go, which is relevant as the main PR also modifies the testing of consensus functionalities, potentially impacting how queries and transactions are validated.
  • chore: remove consensus authority  #21734: This PR modifies the server/v2/cometbft/abci.go file, including changes to the NewConsensus function and related methods, which could affect the tests added in the main PR that validate consensus functionalities.
  • chore(server/v2/cometbft): improve code check #21955: This PR refines error handling in the CheckTx and Info methods in server/v2/cometbft/abci.go, which is relevant to the main PR's focus on enhancing the testing framework for consensus functionalities.
  • refactor(serevr/v2/cometbft): update RegisterQueryHandlers and GRPC queries #22403: This PR updates the RegisterQueryHandlers and GRPC queries in the server/v2/cometbft files, which may relate to the query handling tests introduced in the main PR.
  • fix(server/v2/cometbft): proper query error #22746: This PR addresses error handling in the server/v2/cometbft/abci.go file, which is directly relevant to the main PR's focus on enhancing the testing framework for consensus functionalities, particularly in how errors are reported during queries.

Suggested labels

Type: CI

Suggested reviewers

  • kocubinski
  • sontrinh16
  • tac0turtle

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 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: 1

🧹 Outside diff range and nitpick comments (3)
server/v2/cometbft/abci_test.go (3)

21-22: Fix import order to comply with Go and project conventions

The import statements are not properly grouped and ordered, as indicated by the gci linter. Standard library imports should be separated from third-party and project-specific imports. Please organize the imports to meet the project's import conventions.

🧰 Tools
🪛 golangci-lint (1.62.2)

21-21: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)


38-40: Ensure imports are grouped and sorted correctly

The imports are not grouped according to the conventions specified in the Uber Go Style Guide. Please group standard library, third-party, and project-specific imports separately and ensure they are alphabetically sorted within each group.

🧰 Tools
🪛 golangci-lint (1.62.2)

40-40: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)


813-813: Format the code with gofumpt -extra for consistency

The code is not formatted according to the gofumpt -extra style guidelines, as indicated by the gofumpt linter. Please format the code to improve readability and maintain consistency across the codebase.

🧰 Tools
🪛 golangci-lint (1.62.2)

813-813: File is not gofumpt-ed with -extra

(gofumpt)

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ec5225c and 07ad8ae.

📒 Files selected for processing (2)
  • server/v2/cometbft/abci_test.go (8 hunks)
  • server/v2/cometbft/utils.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
server/v2/cometbft/utils.go (1)

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

server/v2/cometbft/abci_test.go (2)

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


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

🪛 golangci-lint (1.62.2)
server/v2/cometbft/abci_test.go

21-21: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)


40-40: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)


824-824: Error return value of queryRouterBuilder.RegisterHandler is not checked

(errcheck)


813-813: File is not gofumpt-ed with -extra

(gofumpt)

🔇 Additional comments (2)
server/v2/cometbft/abci_test.go (1)

654-709: Unit tests enhance coverage for new query functionalities

The new test functions TestConsensus_GRPCQuery, TestConsensus_P2PQuery, and TestConsensus_AppQuery appropriately test the added query functionalities, covering scenarios for valid and invalid requests, error handling, and response validation. These tests enhance the robustness of the testing suite.

Also applies to: 711-749, 750-790

server/v2/cometbft/utils.go (1)

193-197: Prevent potential nil pointer dereference in error handling

The added nil check for txRes.Error before accessing Error() ensures that there is no nil pointer dereference when constructing the error message. This change improves the robustness of the error handling logic.

Comment on lines +824 to +827
queryRouterBuilder.RegisterHandler(
proto.MessageName(&testdata.SayHelloRequest{}),
helloFooHandler,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Check the error return value of RegisterHandler

The call to queryRouterBuilder.RegisterHandler does not check the returned error. Ignoring errors may lead to unexpected behavior or panics during runtime. Please handle the error appropriately.

Apply the following fix to handle the error:

+	err := queryRouterBuilder.RegisterHandler(
 		proto.MessageName(&testdata.SayHelloRequest{}),
 		helloFooHandler,
 	)
+	require.NoError(t, err)
 	
-	queryRouterBuilder.RegisterHandler(
-		proto.MessageName(&testdata.SayHelloRequest{}),
-		helloFooHandler,
-	)

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 golangci-lint (1.62.2)

824-824: Error return value of queryRouterBuilder.RegisterHandler is not checked

(errcheck)

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

🧹 Outside diff range and nitpick comments (4)
server/v2/cometbft/abci_test.go (4)

21-22: Organize imports according to Go conventions

The import statements are not properly grouped and ordered. According to the Uber Golang style guide, imports should be grouped in the following order:

  1. Standard library packages.
  2. Third-party packages.
  3. Local packages.

Apply this diff to organize the imports:

 import (
+	"context"
+	"crypto/sha256"
+	"encoding/json"
+	"errors"
+	"io"
+	"reflect"
+	"strings"
+	"sync"
+	"testing"
+	"time"

 	abci "github.com/cometbft/cometbft/abci/types"
 	abciproto "github.com/cometbft/cometbft/api/cometbft/abci/v1"
 	v1 "github.com/cometbft/cometbft/api/cometbft/types/v1"
 	"github.com/cosmos/gogoproto/proto"
 	gogotypes "github.com/cosmos/gogoproto/types"
 	"github.com/stretchr/testify/require"
+	"github.com/cosmos/cosmos-sdk/testutil/testdata"
+	sdk "github.com/cosmos/cosmos-sdk/types"
+	gogoproto "github.com/cosmos/gogoproto/proto"

 	appmodulev2 "cosmossdk.io/core/appmodule/v2"
 	"cosmossdk.io/core/server"
 	"cosmossdk.io/core/store"
 	"cosmossdk.io/core/transaction"
 	"cosmossdk.io/log"
 	"cosmossdk.io/server/v2/appmanager"
 	"cosmossdk.io/server/v2/cometbft/handlers"
 	cometmock "cosmossdk.io/server/v2/cometbft/internal/mock"
 	"cosmossdk.io/server/v2/cometbft/mempool"
 	"cosmossdk.io/server/v2/cometbft/oe"
 	"cosmossdk.io/server/v2/cometbft/types"
 	"cosmossdk.io/server/v2/stf"
 	"cosmossdk.io/server/v2/stf/branch"
 	"cosmossdk.io/server/v2/stf/mock"
 	consensustypes "cosmossdk.io/x/consensus/types"
 )

Also applies to: 38-40

🧰 Tools
🪛 golangci-lint (1.62.2)

21-21: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)


654-709: Enhance assertions in TestConsensus_GRPCQuery

While the test covers basic success and failure cases, adding more detailed assertions can improve test robustness:

  • Verify the exact contents of the successful response to ensure it matches expected values.
  • Consider testing additional edge cases, such as malformed requests or unexpected data.

711-749: Expand error handling tests in TestConsensus_P2PQuery

To strengthen the test suite:

  • Include test cases for invalid input scenarios, such as incorrect paths or missing parameters.
  • Confirm that appropriate error codes and messages are returned for different failure cases.

813-813: Format code with gofumpt

The code is not formatted according to gofumpt standards. Formatting the code enhances readability and maintains consistency.

Run the following command to format the code:

gofumpt -w ./server/v2/cometbft/abci_test.go
🧰 Tools
🪛 golangci-lint (1.62.2)

813-813: File is not gofumpt-ed with -extra

(gofumpt)

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ec5225c and 07ad8ae.

📒 Files selected for processing (2)
  • server/v2/cometbft/abci_test.go (8 hunks)
  • server/v2/cometbft/utils.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
server/v2/cometbft/utils.go (1)

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

server/v2/cometbft/abci_test.go (2)

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


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

🪛 golangci-lint (1.62.2)
server/v2/cometbft/abci_test.go

21-21: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)


40-40: File is not gci-ed with --skip-generated -s standard -s default -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) --custom-order

(gci)


824-824: Error return value of queryRouterBuilder.RegisterHandler is not checked

(errcheck)


813-813: File is not gofumpt-ed with -extra

(gofumpt)

🔇 Additional comments (3)
server/v2/cometbft/abci_test.go (2)

593-593: Ensure sufficient test coverage in TestConsensus_QueryStore

The renaming of TestConsensus_Query to TestConsensus_QueryStore improves clarity. Please verify that all scenarios related to store queries are adequately tested to maintain comprehensive coverage.


750-790: ⚠️ Potential issue

Handle error return value of queryRouterBuilder.RegisterHandler

At line 824, the error returned by queryRouterBuilder.RegisterHandler is not checked. Ignoring errors can lead to unexpected behavior if the handler fails to register.

Apply this diff to handle the potential error:

 queryRouterBuilder.RegisterHandler(
     proto.MessageName(&testdata.SayHelloRequest{}),
     helloFooHandler,
 )
+err = queryRouterBuilder.RegisterHandler(
+    proto.MessageName(&testdata.SayHelloRequest{}),
+    helloFooHandler,
+)
+if err != nil {
+    t.Fatalf("failed to register handler: %v", err)
+}

Likely invalid or redundant comment.

server/v2/cometbft/utils.go (1)

193-197: Prevent potential nil pointer dereference

Good enhancement in intoABCISimulationResponse function. By checking if txRes.Error is not nil before calling Error(), you prevent a possible nil pointer dereference, improving the robustness of the error handling.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Dec 5, 2024
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.

nice! One nit.

@@ -18,6 +18,8 @@ import (
gogotypes "github.com/cosmos/gogoproto/types"
"github.com/stretchr/testify/require"

"reflect"
Copy link
Member

Choose a reason for hiding this comment

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

Could you run the linter? Weird that it doesn't fail, but the import sorting is wrong

@julienrbrt julienrbrt changed the title test(server/v2/comet): Add Consensus query p2p, app, grpc test(server/v2/cometbft): Add Consensus query p2p, app, grpc Dec 5, 2024
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

thank you

@hieuvubk hieuvubk enabled auto-merge December 5, 2024 10:09
@hieuvubk hieuvubk added this pull request to the merge queue Dec 5, 2024
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

📥 Commits

Reviewing files that changed from the base of the PR and between 07ad8ae and 13128cb.

📒 Files selected for processing (2)
  • server/v2/cometbft/abci_test.go (9 hunks)
  • server/v2/cometbft/utils.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/v2/cometbft/utils.go
🧰 Additional context used
📓 Path-based instructions (1)
server/v2/cometbft/abci_test.go (2)

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


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

🪛 golangci-lint (1.62.2)
server/v2/cometbft/abci_test.go

19-19: ST1019(related information): other import of "github.com/cosmos/gogoproto/proto"

(stylecheck)


824-824: Error return value of queryRouterBuilder.RegisterHandler is not checked

(errcheck)

🔇 Additional comments (6)
server/v2/cometbft/abci_test.go (6)

Line range hint 593-653: LGTM! Well-structured store query tests

The renamed test function provides clear separation of store-specific query tests with good coverage of both successful and error scenarios.


654-709: LGTM! Comprehensive GRPC query tests

The test covers:

  • Empty request validation
  • Invalid query handler scenarios
  • Successful query execution with response validation

711-748: LGTM! Well-implemented P2P query tests

The test effectively validates P2P filtering functionality for both address and ID-based queries.


750-789: LGTM! Good coverage of App query scenarios

The test thoroughly covers:

  • Transaction simulation
  • Version query functionality

Line range hint 879-902: LGTM! Well-structured mock implementations

The setup includes well-implemented mock filters for P2P address and ID validation, along with proper version string handling.


824-827: ⚠️ Potential issue

Check error return value from RegisterHandler

The error returned by queryRouterBuilder.RegisterHandler should be checked to ensure proper error handling.

Apply this fix:

-queryRouterBuilder.RegisterHandler(
+err := queryRouterBuilder.RegisterHandler(
   proto.MessageName(&testdata.SayHelloRequest{}),
   helloFooHandler,
 )
+require.NoError(t, err)

Likely invalid or redundant comment.

🧰 Tools
🪛 golangci-lint (1.62.2)

824-824: Error return value of queryRouterBuilder.RegisterHandler is not checked

(errcheck)

@@ -15,6 +16,7 @@ import (
abciproto "github.com/cometbft/cometbft/api/cometbft/abci/v1"
v1 "github.com/cometbft/cometbft/api/cometbft/types/v1"
"github.com/cosmos/gogoproto/proto"
gogoproto "github.com/cosmos/gogoproto/proto"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove duplicate import of gogoproto/proto

There's a duplicate import of github.com/cosmos/gogoproto/proto. This can lead to confusion and potential issues.

Apply this fix:

-gogoproto "github.com/cosmos/gogoproto/proto"
🧰 Tools
🪛 golangci-lint (1.62.2)

19-19: ST1019(related information): other import of "github.com/cosmos/gogoproto/proto"

(stylecheck)

Merged via the queue into main with commit 9f7f17b Dec 5, 2024
72 of 73 checks passed
@hieuvubk hieuvubk deleted the hieu/comet_query branch December 5, 2024 10:34
mergify bot pushed a commit that referenced this pull request Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:server/v2 cometbft C:server/v2 Issues related to server/v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test(server/v2): Expand abci Query tests.
5 participants