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: e2e/client to system tests #21981

Merged
merged 5 commits into from
Sep 30, 2024
Merged

test: e2e/client to system tests #21981

merged 5 commits into from
Sep 30, 2024

Conversation

JulianToledano
Copy link
Contributor

@JulianToledano JulianToledano commented Sep 30, 2024

Description

Closes:
#21923


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 a comprehensive suite of system tests for gRPC and CometBFT client functionalities, validating key operations such as querying node information, syncing status, and retrieving block details.
    • Added a new method in the RPC client to invoke RPC methods with enhanced error handling and context management.
  • Bug Fixes

    • Improved error handling for nil requests and validation of block heights in RPC methods.
  • Chores

    • Updated dependencies in the module configuration to include a new dependency and adjust the status of an existing one.

@JulianToledano JulianToledano requested a review from a team as a code owner September 30, 2024 11:07
Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request involves the deletion of an end-to-end test suite for the gRPC service in the Cosmos SDK's cmtservice module and introduces new system tests for the gRPC client functionalities and the CometBFT client. Additionally, the go.mod file has been updated to include a new dependency and adjust the status of an existing one. New methods have also been added to the RPCClient struct to enhance its functionality.

Changes

Files Change Summary
tests/e2e/client/grpc/cmtservice/service_test.go Deleted end-to-end test suite for the gRPC service, which included various test cases for querying node information, syncing status, and error handling.
tests/systemtests/client_test.go New file introducing system tests for gRPC client functionalities, validating interactions such as querying node info, syncing status, latest blocks, and executing ABCI queries.
tests/systemtests/cometbft_client_test.go New file introducing system tests for the CometBFT client, validating functionalities like querying node info, syncing status, and latest blocks, ensuring consistency between direct service calls and REST API requests.
tests/systemtests/go.mod Updated go.mod to add a new dependency (github.com/cometbft/cometbft/api v1.0.0-rc.1) and changed the status of google.golang.org/grpc from indirect to direct.
tests/systemtests/rpc_client.go Added methods Invoke and NewStream to the RPCClient struct, enhancing RPC method invocation with error handling and gRPC metadata management.

Possibly related PRs

Suggested labels

C:server/v2, C:server/v2 cometbft, C:CLI, C:x/auth, Type: CI

Suggested reviewers

  • julienrbrt
  • sontrinh16
  • tac0turtle
  • aaronc
  • facundomedica

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 94945b8 and c2d6ed7.

📒 Files selected for processing (1)
  • tests/systemtests/cometbft_client_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/systemtests/cometbft_client_test.go

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.

@JulianToledano JulianToledano linked an issue Sep 30, 2024 that may be closed by this pull request
@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Sep 30, 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: 4

🧹 Outside diff range and nitpick comments (4)
tests/systemtests/rpc_client.go (1)

111-113: Refine the error handling in NewStream method

The NewStream method currently returns a generic error message "not implemented". Consider returning a more specific gRPC status error to clearly indicate that streaming is not supported.

Apply this diff to refine the error returned:

 func (r RPCClient) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) {
-	return nil, errors.New("not implemented")
+	return nil, status.Errorf(codes.Unimplemented, "streaming is not supported")
 }

Ensure that you import the necessary packages:

+	"google.golang.org/grpc/codes"
+	"google.golang.org/grpc/status"
tests/systemtests/client_test.go (3)

27-32: Consider using more descriptive variable names for clarity

In accordance with the Uber Go Style Guide, using more descriptive variable names can improve code readability. Consider renaming qc to client, res to nodeInfo, and v to cliVersion.

Apply this diff to improve variable naming:

-qc := cmtservice.NewServiceClient(sut.RPCClient(t))
-res, err := qc.GetNodeInfo(context.Background(), &cmtservice.GetNodeInfoRequest{})
+client := cmtservice.NewServiceClient(sut.RPCClient(t))
+nodeInfo, err := client.GetNodeInfo(context.Background(), &cmtservice.GetNodeInfoRequest{})

...

-v := NewCLIWrapper(t, sut, true).Version()
+cliVersion := NewCLIWrapper(t, sut, true).Version()

-assert.Equal(t, res.ApplicationVersion.Version, v)
+assert.Equal(t, nodeInfo.ApplicationVersion.Version, cliVersion)

99-99: Remove unnecessary fmt.Printf statement

The fmt.Printf("%v", res) statement on line 99 may be unnecessary in the test and can clutter the test output. Consider removing it or using proper logging if needed.

Apply this diff to remove the unnecessary print statement:

-	fmt.Printf("%v", res)

255-256: Consider removing expectedCode field if it's not used

The expectedCode field in the test case struct is not set or used in the test cases. If it's not needed, consider removing it to simplify the test code.

Apply this diff to remove the unused field:

 type testCase struct {
 	name         string
 	req          *cmtservice.ABCIQueryRequest
 	expectErr    bool
-	expectedCode uint32
 	validQuery   bool
 }

And remove the corresponding assertion in line 320:

-	assert.Equal(t, res.Code, tc.expectedCode)
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 968bc7c and 1ea1a81.

⛔ Files ignored due to path filters (1)
  • tests/systemtests/go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • tests/e2e/client/grpc/cmtservice/service_test.go (0 hunks)
  • tests/systemtests/client_test.go (1 hunks)
  • tests/systemtests/go.mod (1 hunks)
  • tests/systemtests/rpc_client.go (2 hunks)
💤 Files with no reviewable changes (1)
  • tests/e2e/client/grpc/cmtservice/service_test.go
🧰 Additional context used
📓 Path-based instructions (3)
tests/systemtests/client_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/systemtests/go.mod (1)

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

tests/systemtests/rpc_client.go (2)

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"

🔇 Additional comments (3)
tests/systemtests/go.mod (2)

29-29: LGTM: Addition of CometBFT API dependency

The addition of github.com/cometbft/cometbft/api v1.0.0-rc.1 is appropriate for implementing e2e tests that interact with or simulate CometBFT components. This aligns well with the PR objective of introducing end-to-end tests for client to system interactions.


23-23: Verify direct usage of gRPC in system tests

The google.golang.org/grpc v1.67.0 dependency has been moved from indirect to direct. This suggests that the system tests now directly use gRPC, possibly for client-server communication in the e2e tests.

Please ensure that the gRPC package is being used appropriately in the newly added or modified system tests. You can verify this by running the following command:

This will help confirm that the change in dependency status is justified by actual usage in the test code.

✅ Verification successful

Verification Successful: Direct gRPC usage confirmed in system tests

  • tests/systemtests/rpc_client.go: Utilizes gRPC for invoking methods and creating streams.
  • tests/systemtests/system.go: Configures gRPC addresses for system components.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for gRPC usage in system test files
rg --type go 'grpc\.' tests/systemtests

Length of output: 537

tests/systemtests/rpc_client.go (1)

47-109: Well-implemented Invoke method

The Invoke method is implemented correctly, handling serialization, context metadata extraction, error checking, and response unmarshalling appropriately.

tests/systemtests/rpc_client.go Outdated Show resolved Hide resolved
tests/systemtests/client_test.go Outdated Show resolved Hide resolved
tests/systemtests/client_test.go Outdated Show resolved Hide resolved
tests/systemtests/client_test.go Outdated Show resolved Hide resolved
@@ -2,11 +2,23 @@

import (
"context"
"errors"
"reflect"

Check notice

Code scanning / CodeQL

Sensitive package import Note test

Certain system packages contain functions which may be a possible source of non-determinism
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.

lgtm! one nit about the file name.

Copy link
Member

Choose a reason for hiding this comment

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

let's rename this to cometbft_client_test.go

v := NewCLIWrapper(t, sut, true).Version()
assert.Equal(t, res.ApplicationVersion.Version, v)

restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/node_info", baseurl))
Copy link
Member

@julienrbrt julienrbrt Sep 30, 2024

Choose a reason for hiding this comment

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

For later, we should be adding a way to distinguish a v2 app with comet and one without.
Nothing to do here, but eventually we should skip some v2 system test depending on the consensus engine we want to test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add a todo

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

🧹 Outside diff range and nitpick comments (3)
tests/systemtests/cometbft_client_test.go (3)

34-34: Address the TODO comment to distinguish version v2 in tests

The TODO comment indicates a need to add logic to distinguish version v2 and potentially skip certain system tests depending on the consensus engine being tested. Implementing this functionality will ensure that tests are run appropriately for different consensus engines.

Would you like assistance in implementing this logic or creating a GitHub issue to track this task?


49-51: Add assertions to validate response content

In the TestQuerySyncing function, the test checks that no error occurs when making the REST API request but does not assert the actual syncing status returned. Consider adding an assertion to verify that the REST API response syncing status matches the gRPC client's syncing status.


64-66: Add assertions to validate REST API response in TestQueryLatestBlock

The test checks for errors when requesting the latest block via REST API but does not verify the content of the response. Adding assertions to confirm that the REST API response contains the expected block data will improve test coverage.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1ea1a81 and 94945b8.

📒 Files selected for processing (2)
  • tests/systemtests/cometbft_client_test.go (1 hunks)
  • tests/systemtests/rpc_client.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/systemtests/rpc_client.go
🧰 Additional context used
📓 Path-based instructions (1)
tests/systemtests/cometbft_client_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 (1)
tests/systemtests/cometbft_client_test.go (1)

260-266: Ensure error handling for marshaling in TestABCIQuery

In the test case "request with invalid path recursive," the Data field is set by marshaling another ABCIQueryRequest. Ensure that any errors occurring during marshaling are properly handled, and that the test effectively validates the behavior when an invalid recursive path is provided.

Comment on lines +115 to +146
func TestLatestValidatorSet(t *testing.T) {
sut.ResetChain(t)
sut.StartChain(t)

vals := sut.RPCClient(t).Validators()

qc := cmtservice.NewServiceClient(sut.RPCClient(t))
testCases := []struct {
name string
req *cmtservice.GetLatestValidatorSetRequest
expErr bool
expErrMsg string
}{
{"nil request", nil, true, "cannot be nil"},
{"no pagination", &cmtservice.GetLatestValidatorSetRequest{}, false, ""},
{"with pagination", &cmtservice.GetLatestValidatorSetRequest{Pagination: &qtypes.PageRequest{Offset: 0, Limit: uint64(len(vals))}}, false, ""},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
res, err := qc.GetLatestValidatorSet(context.Background(), tc.req)
if tc.expErr {
assert.Error(t, err)
assert.Contains(t, err.Error(), tc.expErrMsg)
} else {
assert.NoError(t, err)
assert.Equal(t, len(res.Validators), len(vals))
content, ok := res.Validators[0].PubKey.GetCachedValue().(cryptotypes.PubKey)
assert.True(t, ok)
assert.Equal(t, content.Address(), vals[0].PubKey.Address())
}
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance assertions in TestLatestValidatorSet

The test cases check for various scenarios when querying the latest validator set. Consider adding additional assertions to validate the contents of the returned validators, such as checking individual validator fields or properties, to enhance test robustness.

tests/systemtests/cometbft_client_test.go Outdated Show resolved Hide resolved
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.

nice job

@julienrbrt julienrbrt added this pull request to the merge queue Sep 30, 2024
Merged via the queue into main with commit 91b47cb Sep 30, 2024
74 of 75 checks passed
@julienrbrt julienrbrt deleted the julian/client-system-test branch September 30, 2024 14:17
mergify bot pushed a commit that referenced this pull request Sep 30, 2024
(cherry picked from commit 91b47cb)

# Conflicts:
#	tests/systemtests/go.mod
#	tests/systemtests/go.sum
alpe added a commit that referenced this pull request Oct 1, 2024
* main:
  docs: amend docs for 52 changes  (#21992)
  test: migrate e2e/authz to system tests (#21819)
  refactor(runtime/v2): use StoreBuilder (#21989)
  feat(schema): add API descriptors, struct, oneof & list types, and wire encoding spec (#21482)
  docs: add instructions to change DefaultGenesis (#21680)
  feat(x/staking)!: Add metadata field to validator info (#21315)
  chore(x/authz)!: Remove account keeper dependency (#21632)
  chore(contributing): delete link (#21990)
  test(gov): Migrate e2e to system test (#21927)
  test: e2e/client to system tests (#21981)
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tests/e2e/client to system tests
4 participants