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

Remove x/* from testutil #20121

Closed
wants to merge 25 commits into from
Closed

Remove x/* from testutil #20121

wants to merge 25 commits into from

Conversation

hieuvubk
Copy link
Collaborator

@hieuvubk hieuvubk commented Apr 22, 2024

Description

Closes: #18290


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
  • 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.

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

    • Enhanced error messaging for block retries in CLI multisign tests.
    • Improved account and validator setup in network configuration utilities.
    • Added debug print statements in authentication module initialization for better traceability.
  • Refactor

    • Updated simulation utility imports across various test and simulation files for consistency.
    • Refactored network utility functions for genesis state initialization.
    • Removed deprecated code and updated transaction generation in simulation operations.
  • Bug Fixes

    • Standardized transaction response checks in end-to-end testing modules.
  • Documentation

    • No visible changes to end-users.

Copy link
Contributor

coderabbitai bot commented Apr 22, 2024

Walkthrough

Walkthrough

The changes involve updates to import paths and functions across various test and simulation files in the Cosmos SDK. Key updates include replacing simtestutil with helper for simulation utilities, enhancing error handling in E2E tests, and refactoring network utility functions for better test setup and execution.

Changes

Files Change Summary
simapp/.../app_test.go, simapp/.../root.go Updated import paths for simtestutil to github.com/cosmos/cosmos-sdk/x/simulation/helper.
simapp/.../sim_bench_test.go, simapp/.../sim_test.go, simapp/.../test_helpers.go Replaced references to simtestutil with helper.
tests/e2e/auth/suite.go Added error handling print statements in TestCLIMultisign.
tests/e2e/.../tx.go, tests/e2e/gov/tx.go Replaced clitestutil.CheckTxCode with e2etestutil.CheckTxCode.
tests/e2e/baseapp/..., tests/integration/... Updated import paths from simtestutil to helper.
testutil/network/network.go, testutil/network/util.go Restructured imports and refactored functions for network configuration and genesis file handling.
tools/hubl/internal/compat.go Removed deprecated fields and updated gRPC handling.
x/auth/depinject.go, x/authz/simulation/operations.go, x/bank/simulation/operations.go Introduced changes in simulation operations and dependency injection.

Possibly related issues


Recent Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 28f5cec and f51ca17.
Files selected for processing (2)
  • testutil/network/network.go (8 hunks)
  • x/genutil/utils.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • testutil/network/network.go
Additional Context Used
Path-based Instructions (1)
x/genutil/utils.go (1)

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

Additional comments not posted (1)
x/genutil/utils.go (1)

149-161: Function implementation looks good and follows best practices.

This function effectively utilizes the SDK's types and methods to generate a new message for creating a validator.


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

tests/integration/utils/utils.go Fixed Show fixed Hide fixed
tests/integration/utils/utils.go Fixed Show fixed Hide fixed
@@ -49,6 +49,7 @@ func SetupSimulation(config simtypes.Config, dirPrefix, dbName string, verbose,
return db, dir, logger, false, nil
}

// Can move to simapp
Copy link
Member

Choose a reason for hiding this comment

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

we broke everyone two versions ago (v0.47) to move all of those from simapp to the sdk and made simapp as hard as possible to import (as it is our testing and demo app, so it shouldn't be imported).
I am not sure we should move this back.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm the only reason I moved it to simapp is we just use SetupSimulation for integration & some simapp tests.
Let me see if I can move to x/simulate. How does it sound?

Copy link
Member

Choose a reason for hiding this comment

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

Right, but those helpers should be used by chains

@hieuvubk hieuvubk marked this pull request as ready for review April 25, 2024 06:33
@hieuvubk hieuvubk requested a review from a team as a code owner April 25, 2024 06:33
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.

network.Network is used for e2e tests, chains should write e2e tests as well, so I think network should not be in simapp. Otherwise chains will need to copy / paste the whole package.

https://sourcegraph.com/search?q=context:global+%22github.com/cosmos/cosmos-sdk/testutil/network%22+-repo:github.com/cosmos/cosmos-sdk&patternType=keyword&sm=0

@@ -395,6 +395,7 @@ func (c *container) resolve(in providerInput, moduleKey *moduleKey, caller Locat
}

vr, err := c.getResolver(in.Type, moduleKey)
fmt.Println("getResolver", vr, err, in.Type, moduleKey, in.Optional)
Copy link
Member

Choose a reason for hiding this comment

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

this should be removed

@hieuvubk
Copy link
Collaborator Author

network.Network is used for e2e tests, chains should write e2e tests as well, so I think network should not be in simapp. Otherwise chains will need to copy / paste the whole package.

https://sourcegraph.com/search?q=context:global+%22github.com/cosmos/cosmos-sdk/testutil/network%22+-repo:github.com/cosmos/cosmos-sdk&patternType=keyword&sm=0

Try some hacks to move all x/ related to genutil. Move network back to testutil.

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

@@ -1047,6 +1047,7 @@ func (s *E2ETestSuite) TestCLIMultisign() {
}
return clientCtx.Codec.UnmarshalJSON(resp, &balRes)
}, 3)
fmt.Println("RetryForBlocks err", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling the error from RetryForBlocks more robustly.

The current implementation prints the error but does not handle it, which could lead to further execution with an undefined state. It would be better to assert no error or handle it appropriately to ensure the test's integrity.

genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
simtestutil "github.com/cosmos/cosmos-sdk/x/simulation/helper"
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace simtestutil with the correct import from github.com/cosmos/cosmos-sdk/x/simulation/helper as per PR objectives.

@@ -221,3 +232,37 @@
func createConfigFolder(dir string) error {
return os.Mkdir(path.Join(dir, "config"), 0o700)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Replace simtestutil.NewAppOptionsWithFlagHome with the correct utility from github.com/cosmos/cosmos-sdk/x/simulation/helper as per PR objectives.

Comment on lines 4 to 5
"fmt"

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider removing the fmt import and fmt.Println statement from production code to maintain cleanliness and performance.

- import (
-   "fmt"
- )
- fmt.Println("Account Keeper", k)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
"fmt"

)

// Can move to tests/integration
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment about moving the test function to a different directory suggests a potential improvement in test organization. Consider creating a GitHub issue to track this suggestion.

Would you like me to open a GitHub issue to track the potential reorganization of test functions as suggested in the comment?


appGenStateJSON, err := json.MarshalIndent(cfg.GenesisState, "", " ")
func initGenFiles(cfg Config, genAccs []sdk.AccAddress, genFiles []string) error {
genState, err := genutil.InitGenFileFromAddrs(genAccs, cfg.GenesisState, cfg.Codec, cfg.ChainID, cfg.BondDenom, cfg.StakingTokens, cfg.AccountTokens)

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This definition of err is never used.
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

Out of diff range and nitpick comments (2)
x/genutil/utils.go (2)

17-33: Consider organizing imports according to the Uber Golang style guide.

Imports should be grouped in the following order: standard library, third-party packages, and then internal packages. This helps in improving readability and maintainability of the code.


Line range hint 63-65: Reduce the permissions for directory creation to enhance security.

Using 0o777 permissions allows all users to read, write, and execute files in this directory, which can lead to security vulnerabilities. Consider using more restrictive permissions, such as 0o750.

Comment on lines +130 to +144
codec.MustUnmarshalJSON(genState[authtypes.ModuleName], &authGenState)

accounts, err := authtypes.PackAccounts(genAccounts)
if err != nil {
return nil, err
}

authGenState.Accounts = append(authGenState.Accounts, accounts...)
genState[authtypes.ModuleName] = codec.MustMarshalJSON(&authGenState)

// set the balances in the genesis state
codec.MustUnmarshalJSON(genState[banktypes.ModuleName], &bankGenState)

bankGenState.Balances = append(bankGenState.Balances, genBalances...)
genState[banktypes.ModuleName] = codec.MustMarshalJSON(&bankGenState)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling JSON operations errors gracefully instead of using methods that can panic.

Using MustUnmarshalJSON and MustMarshalJSON can cause the application to panic if there's an error in JSON operations. It's safer to handle these errors gracefully to prevent the application from crashing unexpectedly.

@tac0turtle
Copy link
Member

closing this for now. We will go a different approach to try to avoid breaking the apis

@tac0turtle tac0turtle closed this May 6, 2024
@tac0turtle tac0turtle deleted the hieu/remove_auth_testutil branch May 6, 2024 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

remove cosmossdk.io/x/* dependence in the root go module
3 participants