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

Add monogen tool #213

Merged
merged 10 commits into from
Sep 16, 2024
Merged

Add monogen tool #213

merged 10 commits into from
Sep 16, 2024

Conversation

joshklop
Copy link
Collaborator

@joshklop joshklop commented Sep 15, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a command-line tool monogen for scaffolding Cosmos SDK projects.
    • Added automation script monogen.sh for initializing Cosmos SDK applications.
  • Bug Fixes

    • Updated dependencies to enhance compatibility and security.
  • Chores

    • Enhanced .gitignore to manage ignored files more effectively.
    • Updated build process in the Makefile for better binary management.

Copy link
Contributor

coderabbitai bot commented Sep 15, 2024

Walkthrough

The pull request introduces several modifications across multiple files, including the addition of a .gitignore entry for binaries, updates to the Makefile for binary management, and enhancements to the go.mod file with dependency upgrades. New files are added to implement a command-line interface tool (monogen) for scaffolding a Cosmos SDK application, along with a script for automating the setup process. Additionally, a test file is introduced to validate the functionality of the monogen.Generate function, ensuring integration with the CometBFT client.

Changes

File(s) Change Summary
.gitignore Added bin/ to ignore binaries.
Makefile Introduced variable BIN for output directory; added monogen target; modified clean target.
go.mod Updated multiple dependencies to newer versions, including Cosmos SDK and CometBFT libraries.
monogen/cmd/main.go Implemented CLI tool monogen with flags for project generation.
monogen/monogen.go Added functionality for generating and modifying a Cosmos SDK application scaffold.
monogen/monogen.sh Created script for automating application initialization and setup.
monogen/monogen_test.go Introduced tests for the monogen.Generate function, validating application setup and connectivity.

Possibly related PRs

  • Fix op-proposer behavior in e2e tests #196: The changes in this PR involve modifications to the go.mod file, which aligns with the updates made in the main PR regarding dependency management. Both PRs reflect efforts to maintain and enhance the project's dependencies, although they focus on different aspects of the codebase.

Poem

🐰 In the meadow where bunnies play,
New tools and scripts have come our way.
Binaries tucked away with care,
Cosmos apps sprout everywhere!
With tests to keep us safe and sound,
A joyful hop in code we've found! 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fa3a8c9 and d82a3c3.

Files selected for processing (3)
  • monogen/cmd/main.go (1 hunks)
  • monogen/monogen.go (1 hunks)
  • monogen/monogen_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • monogen/cmd/main.go
  • monogen/monogen.go
  • monogen/monogen_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 generate interesting stats about this repository and render them as a table.
    -- @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.

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

@joshklop joshklop force-pushed the joshklop.monogen branch 2 times, most recently from 9060562 to aa754a9 Compare September 15, 2024 03:25
@joshklop joshklop marked this pull request as ready for review September 16, 2024 04:58
@joshklop
Copy link
Collaborator Author

joshklop commented Sep 16, 2024

To try it out yourself, run

make monogen \
    && cd .. \
    && ./monomer/bin/monogen \
    && cd testapp \
    && ../monomer/monogen/monogen.sh \
    && ./testappd monomer start --minimum-gas-prices 0.01stake

Two follow-ups are planned:

  1. Docs updates
  2. Generating a realistic testapp for e2e tests.

The idea is that we can instruct users to run

go run github.com/polymerdao/monomer/cmd/monogen@latest

and automatically paste monogen.sh in the docs so we never have to modify the tutorial. This has the added benefit of running the tutorial in tests, so it will always be up-to-date.

@joshklop
Copy link
Collaborator Author

joshklop commented Sep 16, 2024

I'll fix the lints tomorrow. This is ready for review otherwise. This is a monolithic change; it will not be useful to review commit-by-commit.

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)
monogen/monogen.sh (1)

1-40: Great work on automating the initialization and setup process for a Cosmos SDK-based application!

The script is well-structured, follows best practices, and provides useful comments and documentation. It automates the initialization and setup process for a Cosmos SDK-based application, which is a good practice and will save time and reduce errors.

As a suggestion for improvement, consider adding a help message or usage instructions at the beginning of the script to provide more information about what the script does and how to use it. This will make it easier for other developers to understand and use the script.

monogen/monogen.go (2)

19-20: Address the TODO comment.

The TODO comment indicates that the function should handle the case when the directory already exists. Please ensure that this case is handled appropriately to avoid overwriting existing files or throwing an error.

Do you want me to generate the code to handle this case or open a GitHub issue to track this task?


18-89: Consider decomposing the function into smaller functions.

The Generate function is quite large and performs several distinct tasks. Consider decomposing it into smaller functions for better readability and maintainability. For example, you could extract the code for applying modifications into a separate function.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 609bc99 and fa3a8c9.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (7)
  • .gitignore (1 hunks)
  • Makefile (2 hunks)
  • go.mod (12 hunks)
  • monogen/cmd/main.go (1 hunks)
  • monogen/monogen.go (1 hunks)
  • monogen/monogen.sh (1 hunks)
  • monogen/monogen_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • .gitignore
Additional context used
GitHub Check: go
monogen/cmd/main.go

[failure] 43-43:
exitAfterDefer: os.Exit will exit, and defer cancel() will not run (gocritic)

Additional comments not posted (33)
monogen/monogen.sh (4)

1-4: LGTM!

The shebang line is correct, and the set -e command is a good practice to stop the script execution if any command fails.


6-10: LGTM!

The code segment correctly checks the Go version and sets the ldflags variable accordingly. The go build command is used to build the binary with the correct flags.


12-34: LGTM!

The code segment correctly initializes the application's config and data directories, creates a dummy account, funds it at genesis, and facilitates the creation of a genesis transaction for the dummy account to self-delegate as a validator. Finally, it collects the generated transactions into the genesis file.


36-40: LGTM!

The comment is informative and provides a useful command to start the application with configurable minimum gas prices.

monogen/monogen_test.go (3)

16-62: Comprehensive and well-structured test for monogen.Generate.

The test function TestGenerate is well-designed and covers the essential aspects of the monogen.Generate function. It follows a clear and logical flow, setting up the environment, executing the generation script, starting the application, and performing a connectivity check with the blockchain.

The test takes appropriate measures to ensure that it does not interfere with the user's environment by using a temporary directory and custom home environment variable. It effectively validates the integration of the monogen functionality with the CometBFT client by verifying the connectivity and retrieving the block information.

The test uses appropriate assertions to verify the expected behavior and handles the cleanup of the started application using defer statements. The use of a custom logWriter to capture the output of the executed commands is a nice touch for debugging purposes.

Overall, this test provides confidence in the correctness of the monogen.Generate function and its integration with the CometBFT client.


64-64: Clear and concise type alias for logging functionality.

The logWriter type alias provides a clear and concise way to define the logging functionality used in the test function. By using a function type that takes a variadic parameter of type any, it can be easily used with the t.Log function to capture the output of the executed commands.

The type alias improves the readability of the code and encapsulates the logging functionality in a meaningful way.


66-69: Effective implementation of the io.Writer interface for logging.

The Write method on the logWriter type correctly implements the io.Writer interface, allowing it to be used for capturing the output of the executed commands in the test function.

By logging the string representation of the input byte slice using the logWriter function, it effectively captures the output. The method adheres to the io.Writer interface contract by returning the length of the input byte slice and a nil error.

This implementation enables seamless integration with the cmd.Stdout and cmd.Stderr fields, facilitating the capture of command output for debugging purposes.

Makefile (4)

5-5: LGTM!

The BIN variable is defined correctly using the conditional assignment operator, allowing the user to override the default value if needed. The variable is used appropriately in the monogen target to specify the output directory for the binary.


13-13: LGTM!

The monogen target is declared correctly as a phony target using the .PHONY directive. This ensures that the target is always executed, regardless of the existence of a file named monogen in the directory.


14-15: LGTM!

The monogen target is defined correctly to compile the Go program located in ./monogen/cmd using the go build command. The -o flag is used appropriately to specify the output directory and binary name using the BIN variable.


94-94: LGTM!

The clean target is updated correctly to remove the $(BIN) directory if it exists. The if statement is used appropriately to check for the directory's existence before attempting to remove it recursively using the rm -r command. This ensures effective cleanup of the build artifacts.

monogen/monogen.go (4)

91-158: LGTM!

The addRollupModule function correctly adds the rollup module to the application. The changes are well-structured and follow best practices.


160-211: LGTM!

The removeConsensusModule function correctly removes the consensus module from the application. The changes are well-structured and follow best practices.


213-242: LGTM!

The addMonomerCommand function correctly adds the Monomer command to the application's command structure. The changes are well-structured and follow best practices.


244-263: LGTM!

The addReplaceDirectives function correctly adds the replace directives to the go.mod file. The changes are well-structured and follow best practices.

go.mod (18)

4-4: LGTM!

The minor version update for cosmossdk.io/api is unlikely to introduce breaking changes and may include bug fixes or minor enhancements.


12-12: LGTM!

The patch version update for github.com/cometbft/cometbft is unlikely to introduce breaking changes and may include bug fixes or performance improvements.


16-16: LGTM!

The patch version update for github.com/cosmos/cosmos-sdk is unlikely to introduce breaking changes and may include bug fixes or performance improvements.


24-24: LGTM!

The patch version update for github.com/gorilla/mux is unlikely to introduce breaking changes and may include bug fixes or performance improvements.


32-32: LGTM!

The patch version update for github.com/spf13/cobra is unlikely to introduce breaking changes and may include bug fixes or performance improvements.


35-35: LGTM!

The version update for golang.org/x/exp to a newer commit hash is unlikely to introduce breaking changes and may include bug fixes, performance improvements, or new experimental features.


43-43: LGTM!

The patch version update for cosmossdk.io/x/tx is unlikely to introduce breaking changes and may include bug fixes or performance improvements.


44-44: LGTM!

The addition of the indirect dependency dario.cat/mergo is likely required by one of the direct dependencies and should not cause any issues.


47-47: LGTM!

The patch version update for github.com/99designs/keyring is unlikely to introduce breaking changes and may include bug fixes or performance improvements.


74-74: LGTM!

The minor version update for github.com/cenkalti/backoff/v4 is unlikely to introduce breaking changes and may include new features or enhancements.


94-94: LGTM!

The patch version update for github.com/cpuguy83/go-md2man/v2 is unlikely to introduce breaking changes and may include bug fixes or performance improvements.


98-98: LGTM!

The minor version update for github.com/danieljoos/wincred is unlikely to introduce breaking changes and may include new features or enhancements.


121-121: LGTM!

The minor version update for github.com/fatih/color is unlikely to introduce breaking changes and may include new features or enhancements.


188-188: LGTM!

The patch version update for github.com/hashicorp/go-hclog is unlikely to introduce breaking changes and may include bug fixes or performance improvements.


193-193: LGTM!

The minor version update for github.com/hashicorp/go-plugin is unlikely to introduce breaking changes and may include new features or enhancements.


196-196: LGTM!

The patch version update for github.com/hashicorp/golang-lru/v2 is unlikely to introduce breaking changes and may include bug fixes or performance improvements.


294-294: LGTM!

The minor version update for github.com/pelletier/go-toml/v2 is unlikely to introduce breaking changes and may include new features or enhancements.


352-352: LGTM!

The patch version update for go.etcd.io/bbolt is unlikely to introduce breaking changes and may include bug fixes or performance improvements.

monogen/cmd/main.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@natebeauregard natebeauregard left a comment

Choose a reason for hiding this comment

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

LGTM! Left a few minor nits and questions but the impl looks solid

monogen/cmd/main.go Outdated Show resolved Hide resolved
monogen/monogen.go Outdated Show resolved Hide resolved
monogen/monogen.go Outdated Show resolved Hide resolved
monogen/monogen.go Show resolved Hide resolved
monogen/monogen_test.go Show resolved Hide resolved
Makefile Show resolved Hide resolved
@joshklop joshklop merged commit 84943f6 into main Sep 16, 2024
15 checks passed
@joshklop joshklop deleted the joshklop.monogen branch September 16, 2024 22:44
@coderabbitai coderabbitai bot mentioned this pull request Sep 17, 2024
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.

2 participants