InjectiveLabs / sdk-go

Tools to work with the Injective Chain, Injective EVM and EIP712.
Apache License 2.0
95 stars 41 forks source link

feat: add GetStatus to tmclient #247

Closed proofofze closed 3 weeks ago

proofofze commented 3 weeks ago

This PR adds a method to tmClient that lets callers get the status of the Tendermint node

coderabbitai[bot] commented 3 weeks ago

Walkthrough

The pull request introduces significant enhancements to the Cosmos SDK keyring management, including the addition of a new keyring helper, error handling improvements, and updates to the testing framework. The workflow for running tests has been modified to include GPG key setup and password management. Additionally, various files have been created or updated to support the new functionalities, including error definitions and configuration options for the keyring.

Changes

Files Change Summary
.github/workflows/run-tests.yml Added steps for GPG key setup and password manager installation.
.pre-commit-config.yaml Updated exclude patterns to broaden scope of excluded files.
auth_vote/authz_vote.go Removed redundant error check after tmClient initialization.
client/keyring/README.md Introduced a new keyring helper for the Cosmos SDK with flexible configuration options.
client/keyring/errors.go Added error variables for keyring operation failures.
client/keyring/key_config.go Introduced a struct for keyring configuration with functional options.
client/keyring/keyring.go Implemented keyring management functions and validation logic.
client/keyring/keyring_config.go Defined configuration structure and options for the keyring.
client/keyring/keyring_errors_test.go Added unit tests for keyring error handling scenarios.
client/keyring/keyring_test.go Established a test suite for keyring functionalities.
client/keyring/testdata/... Introduced new test data files related to JWT tokens and hashes.
client/tm/tmclient.go Added GetStatus method to the TendermintClient interface.
go.mod Updated dependencies and added a new direct dependency on github.com/cosmos/go-bip39.

Possibly related PRs

Suggested reviewers

🐰 In the meadow, where the bunnies play,
A keyring helper hops in, brightening the day!
With GPG keys and passwords, oh what a sight,
Managing secrets, making it right!
Errors caught, tests run with glee,
In the land of code, it's a jubilee! 🎉


📜 Recent review details **Configuration used: .coderabbit.yaml** **Review profile: CHILL**
📥 Commits Files that changed from the base of the PR and between 92ece76d571ae281653832e48c75bd3644bc334c and 1ef066b39255d83c1ee18908d5dcff192c25ced6.
📒 Files selected for processing (17) * .github/workflows/run-tests.yml (1 hunks) * .pre-commit-config.yaml (1 hunks) * auth_vote/authz_vote.go (0 hunks) * client/keyring/README.md (1 hunks) * client/keyring/errors.go (1 hunks) * client/keyring/key_config.go (1 hunks) * client/keyring/keyring.go (1 hunks) * client/keyring/keyring_config.go (1 hunks) * client/keyring/keyring_errors_test.go (1 hunks) * client/keyring/keyring_test.go (1 hunks) * client/keyring/testdata/keyring-file/263117aad9ebf5759a8272ad2ae4968dd12d4602.address (1 hunks) * client/keyring/testdata/keyring-file/310322fcb0937ade77a9ba0d128f9e7f17312796.address (1 hunks) * client/keyring/testdata/keyring-file/keyhash (1 hunks) * client/keyring/testdata/keyring-file/test.info (1 hunks) * client/keyring/testdata/keyring-file/test2.info (1 hunks) * client/tm/tmclient.go (2 hunks) * go.mod (1 hunks)
💤 Files with no reviewable changes (1) * auth_vote/authz_vote.go
✅ Files skipped from review due to trivial changes (1) * client/keyring/testdata/keyring-file/test.info
🧰 Additional context used
🪛 LanguageTool
client/keyring/README.md
[style] ~3-~3: The phrase “a variety of” may be wordy. To make your writing clearer, consider replacing it. Context: ...ring Helper Creates a new keyring from a variety of options. See `ConfigOpt` and related op... (A_VARIETY_OF) --- [grammar] ~24-~24: Did you mean “having to alias” or “having aliased”? Context: ...ds a single key to the keyring, without having alias name. * `WithNamedKey` addes a single k... (WITHOUT_VBG_VB) --- [uncategorized] ~62-~62: If this is a compound adjective that modifies the following noun, use a hyphen. Context: ... WithKeyFrom("sender"), ), ) ``` Real world use case of keyring initialization from... (EN_COMPOUND_ADJECTIVE_INTERNAL)
🪛 Gitleaks
client/keyring/keyring_test.go
285-285: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key) --- 286-286: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key)
🔇 Additional comments (19)
client/keyring/testdata/keyring-file/keyhash (1)
`1-1`: **LGTM. Consider adding context for the hash.** The addition of this bcrypt hash for test purposes is appropriate. The hash uses a secure format with a cost factor of 10, which is suitable for testing scenarios. Consider adding a comment at the top of the file to provide context about what this hash represents and how it's used in tests. This will improve maintainability and make it easier for other developers to understand its purpose. Let's verify if this hash is used in corresponding test cases: This will help ensure that the hash is properly utilized in the test suite.
client/keyring/testdata/keyring-file/263117aad9ebf5759a8272ad2ae4968dd12d4602.address (1)
`1-1`: **LGTM. Consider documenting the test data and verifying the creation date.** The JWT structure looks correct and uses strong encryption methods, which is good. However, I have a few suggestions: 1. The creation date in the JWT is set to September 7, 2024, which is in the future. While this might be intentional for testing purposes, it's worth verifying to ensure it aligns with the test requirements. 2. Consider adding a comment or separate documentation file explaining the purpose of this test data, including what it represents and how it should be used in tests. This will help other developers understand its significance and how to maintain it. To check if there's any existing documentation for this test data, you can run: If no documentation is found, consider adding some to explain the purpose and usage of this test data.
client/keyring/testdata/keyring-file/310322fcb0937ade77a9ba0d128f9e7f17312796.address (1)
`1-1`: **LGTM with some considerations** The JWT structure looks correct and uses strong encryption algorithms (PBES2-HS256+A128KW for key wrapping and A256GCM for encryption). However, please consider the following points: 1. The creation date in the JWT is set to 2024, which is in the future. While this might be intentional for testing purposes, ensure that your code handles future dates correctly to avoid any potential issues. 2. As this file is in a testdata directory, please confirm that it doesn't contain any real, sensitive information. It's crucial to use mock data for testing to prevent accidental exposure of sensitive data. 3. The filename (`310322fcb0937ade77a9ba0d128f9e7f17312796.address`) appears to be a hexadecimal string. Could you verify its purpose and ensure it aligns with the intended use in your tests? To ensure this file is only used for testing purposes, you can run the following command: If this command returns any results, please review those occurrences to ensure the test data isn't being used in production code.
.pre-commit-config.yaml (1)
`5-6`: **LGTM: Exclusion of test data files is appropriate.** The addition of `client/keyring/testdata/.*` to the `exclude` section is a good practice. This prevents pre-commit hooks from running on test data files, which often don't need to adhere to the same formatting or linting rules as production code.
client/keyring/testdata/keyring-file/test2.info (1)
`1-1`: **Verify the "created" date in the JWT header** The JWT header contains a creation date set in the future: "2024-09-07". This might cause issues with date-sensitive operations in your tests or actual implementation. Consider updating it to a more recent or static date for consistency in test results. To confirm this observation, you can run the following command:
.github/workflows/run-tests.yml (1)
`18-24`: **Clarify the purpose of GPG and password management additions.** The workflow now includes steps for setting up GPG keys and a password manager before running tests. While these additions enhance the workflow's cryptographic capabilities, it's not clear why they are necessary or how they relate to the tests. Could you please provide some context on: 1. Why GPG keys and a password manager are needed for running tests? 2. How these new steps relate to the changes in the application being tested? 3. Are there any new environment variables or secrets that need to be set up for these steps to work correctly? This information will help ensure that the workflow changes align with the project's needs and that all necessary configurations are in place.
client/keyring/errors.go (1)
`1-3`: **LGTM: Package declaration and import statement are correct.** The package name "keyring" is appropriate for the functionality it provides, and the import of "github.com/pkg/errors" is correct and commonly used for error handling in Go.
client/keyring/key_config.go (2)
`1-6`: **LGTM: Package declaration and imports are appropriate.** The package name `keyring` is suitable for the functionality provided. The imports for `bip39` and `errors` are relevant and correctly specified. --- `1-69`: **Overall assessment: Good design with some security improvements needed.** The `key_config.go` file introduces a well-designed keyring configuration system using the functional options pattern, which provides good flexibility. The code is generally well-structured and follows Go conventions. Key points: 1. The use of functional options is a good practice for configuration. 2. Mnemonic validation is a positive security measure. 3. Security warnings for insecure options are present but could be more prominent. 4. There's room for improvement in handling sensitive data and preventing insecure options in production. Please address the suggestions in the previous comments to enhance the overall security and robustness of this module.
client/tm/tmclient.go (3)
`21-21`: **LGTM: New method added to the interface** The `GetStatus` method is a good addition to the `TendermintClient` interface. It follows the existing naming conventions and method signatures, and it provides a way to query the node's status, which can be useful for monitoring and diagnostics. --- `21-21`: **Summary of changes** The addition of the `GetStatus` method to both the `TendermintClient` interface and its implementation in `tmClient` is a valuable enhancement. It provides a clean way to query the node's status, which can be useful for monitoring and diagnostics. The implementation is consistent with existing patterns in the codebase. Key points: 1. The interface addition is well-designed and follows existing conventions. 2. The implementation is straightforward and correct. 3. A minor suggestion was made to improve the method's documentation. 4. It's recommended to verify the usage of this new method in the broader codebase. Overall, these changes improve the functionality of the Tendermint client without introducing any breaking changes. Also applies to: 94-97 --- `21-21`: **Verify usage of the new GetStatus method** The addition of the `GetStatus` method enhances the `TendermintClient` interface and its implementation. To ensure it's being utilized effectively: Let's check if the new method is being used in other parts of the codebase: If there are no results, consider adding a TODO to utilize this new functionality where appropriate in the codebase. Also applies to: 94-97
client/keyring/keyring_config.go (5)
`1-5`: **LGTM: Package declaration and imports are appropriate.** The package name `keyring` accurately reflects the functionality, and the import of `github.com/pkg/errors` is a good choice for error handling. --- `7-8`: **Well-designed configuration option pattern.** The `ConfigOpt` type definition enables a flexible and extensible configuration system. This functional options pattern allows for easy addition of new configuration options in the future without breaking existing code. --- `20-30`: **LGTM: Well-defined backend types with clear documentation.** The `Backend` type and its associated constants are well-defined and documented. This approach enhances type safety and provides clear options for backend selection. --- `1-120`: **Overall: Well-designed and implemented keyring configuration system.** This file introduces a comprehensive and flexible keyring configuration system using the functional options pattern. The code is well-structured, follows Go best practices, and includes appropriate error handling. Key strengths: 1. Flexible configuration options 2. Clear separation of concerns 3. Type-safe backend selection 4. Robust error handling Minor suggestions for improvement have been made throughout the review, including: 1. Adding field comments to the `cosmosKeyringConfig` struct 2. Enhancing input validation for `WithKeyringBackend` 3. Refactoring key addition functions to reduce duplication 4. Adding validation for the default key's existence Overall, this is a solid implementation that provides a strong foundation for keyring management in the application. --- `110-120`: **LGTM with suggestion: Default key setter function.** The `WithDefaultKey` function is implemented correctly, following the established pattern for configuration options. However, there's no validation to ensure that the specified default key exists in the `Keys` slice. Consider adding a validation step to check for the key's existence. This could be done during the configuration application phase. To verify this, we can search for any existing validation logic: If no validation is found, consider adding a validation step in the configuration application function (which is not visible in the current file).
client/keyring/README.md (1)
`37-82`: **LGTM for Examples section** The Examples section effectively demonstrates various use cases for keyring initialization. The provided code snippets are clear, well-formatted, and cover different scenarios, including: 1. In-memory keyring with a private key hex 2. In-memory keyring with a mnemonic phrase 3. Real-world use case with CLI flags These examples provide valuable guidance for users implementing the keyring helper in different contexts.
🧰 Tools
🪛 LanguageTool
[uncategorized] ~62-~62: If this is a compound adjective that modifies the following noun, use a hyphen. Context: ... WithKeyFrom("sender"), ), ) ``` Real world use case of keyring initialization from... (EN_COMPOUND_ADJECTIVE_INTERNAL)
go.mod (1)
`21-21`: **Approve the addition of go-bip39 dependency.** The addition of `github.com/cosmos/go-bip39 v1.0.0` is appropriate for implementing BIP39-related functionality, which is commonly used for mnemonic-based key generation in the Cosmos ecosystem. Please ensure that this new dependency is properly utilized in the codebase. You can run the following command to check its usage: ```shell #!/bin/bash # Check usage of the new go-bip39 dependency rg --type go 'github.com/cosmos/go-bip39' ```
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.