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/block #585

Merged
merged 4 commits into from
Mar 5, 2024
Merged

Test/block #585

merged 4 commits into from
Mar 5, 2024

Conversation

ccamel
Copy link
Member

@ccamel ccamel commented Mar 4, 2024

Following up on issue #579, update the unit tests for the block predicates (block_height/1 and block_time/1) to employ Gherkin testing methodoly.

Summary by CodeRabbit

  • New Features

    • Enhanced block height and block time retrieval functionalities with deterministic behavior and added examples.
  • Documentation

    • Updated documentation for block height and block time predicates with new scenarios.
  • Tests

    • Added feature tests for block height and block time predicates, including retrieving and comparing values.
  • Refactor

    • Improved code structure in templates and logic handling, including updates to query client creation and test setups.

@ccamel ccamel self-assigned this Mar 4, 2024
Copy link
Contributor

coderabbitai bot commented Mar 4, 2024

Walkthrough

The recent updates focus on enhancing the predicates block_height and block_time by ensuring determinism and adding practical usage scenarios. Additionally, a new feature in the func.go script template allows for conditional data table rendering, improving the flexibility of output formats. The test features for block_height and block_time have been expanded to include comparison operations, and the test suite has seen refinements in structure and query logic, streamlining the testing process for block-related functionalities.

Changes

Files Change Summary
docs/predicate/block_height_1.md,
docs/predicate/block_time_1.md
Updated predicates to include is det, added usage scenarios.
scripts/templates/func.go.txt Added conditional block for data table rendering.
x/logic/keeper/features/block_height_1.feature,
x/logic/keeper/features/block_time_1.feature
Features test block_height/2 and block_time/2, including retrieval and comparison operations.
x/logic/keeper/features_test.go Improved imports, struct fields, added global variables and functions, updated query client logic.
x/logic/predicate/block.go Removed example comments, added determinism annotations.

🐇✨
In the realm of code, where logic threads weave,
A rabbit hopped in, new tricks up its sleeve.
With predicates clear, and tests that delight,
It ensures that each block, in the blockchain, is right.
"To the moon!" it exclaims, with a leap and a cheer,
For the code grows more robust, with each passing year.
🌟🚀

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-tests 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c7ed234 and 6b69465.
Files selected for processing (7)
  • docs/predicate/block_height_1.md (2 hunks)
  • docs/predicate/block_time_1.md (2 hunks)
  • scripts/templates/func.go.txt (1 hunks)
  • x/logic/keeper/features/block_height_1.feature (1 hunks)
  • x/logic/keeper/features/block_time_1.feature (1 hunks)
  • x/logic/keeper/features_test.go (6 hunks)
  • x/logic/predicate/block.go (2 hunks)
Additional comments: 12
scripts/templates/func.go.txt (1)
  • 36-43: The addition of the conditional block for rendering a data table if present is a good enhancement. It improves the documentation's expressiveness by allowing structured data to be included in test scenarios. This change aligns well with the adoption of the Gherkin methodology for more readable and behavior-driven tests.
x/logic/predicate/block.go (2)
  • 13-15: The update to the BlockHeight function signature, including the determinism annotation is det, is a positive change. It clarifies the expected behavior of the predicate and aligns with the documentation enhancements. Removing example comments also helps in cleaning up the code.
  • 33-35: The update to the BlockTime function signature, including the determinism annotation is det, enhances clarity and aligns with the goal of making the predicates well-documented and deterministic. The removal of example comments contributes to a cleaner codebase.
x/logic/keeper/features/block_height_1.feature (2)
  • 4-24: The scenario "Retrieve the block height of the current block" is well-constructed, demonstrating the block_height/1 predicate's functionality in a clear and behavior-driven manner. The use of Gherkin syntax enhances the readability and expressiveness of the test.
  • 26-48: The scenario "Check that the block height is greater than a certain value" effectively demonstrates another use case of the block_height/1 predicate, specifically for governance-related checks. The scenario is clear, relevant, and well-structured, maintaining the Given-When-Then flow.
x/logic/keeper/features/block_time_1.feature (2)
  • 4-24: The scenario "Retrieve the block time of the current block" is well-constructed, demonstrating the block_time/1 predicate's functionality in a clear and behavior-driven manner. The use of Gherkin syntax enhances the readability and expressiveness of the test.
  • 26-49: The scenario "Check that the block time is greater than a certain time" effectively demonstrates another use case of the block_time/1 predicate, specifically for governance-related checks. The scenario is clear, relevant, and well-structured, maintaining the Given-When-Then flow.
x/logic/keeper/features_test.go (5)
  • 9-12: The addition of imports for strconv and time is appropriate given the context of the changes in this file, particularly for handling time-related operations and string-to-integer conversions which are essential for the new test scenarios.
  • 56-59: Refactoring the testCase struct to include new fields is a good practice, as it seems to align with the additional requirements of the updated tests. However, ensure that all instances and usages of testCase have been updated accordingly to prevent any runtime errors.
  • 74-91: The function givenABlockWithTheFollowingHeader is a well-structured addition that leverages the Gherkin syntax for setting up test scenarios. It's clear and concise, making the tests more readable and maintainable. However, ensure that error messages are as informative as possible to aid in debugging when tests fail.
  • 105-115: Refactoring the whenTheQueryIsRun function to use a new query client creation logic is a significant improvement. It abstracts the complexity of setting up the query client, making the test code cleaner and more maintainable. However, ensure that error handling is robust and provides clear context for failures.
  • 175-203: The newQueryClient function is a crucial addition that encapsulates the creation of a new query client for testing. This function improves modularity and reusability of the test setup code. However, it's important to ensure that the mock controllers and keepers are properly managed to avoid any leaks or unintended side effects, especially in a test environment.

x/logic/keeper/features_test.go Outdated Show resolved Hide resolved
x/logic/keeper/features_test.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c7ed234 and d8b1d8f.
Files selected for processing (7)
  • docs/predicate/block_height_1.md (2 hunks)
  • docs/predicate/block_time_1.md (2 hunks)
  • scripts/templates/func.go.txt (1 hunks)
  • x/logic/keeper/features/block_height_1.feature (1 hunks)
  • x/logic/keeper/features/block_time_1.feature (1 hunks)
  • x/logic/keeper/features_test.go (6 hunks)
  • x/logic/predicate/block.go (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • x/logic/keeper/features/block_height_1.feature
  • x/logic/keeper/features/block_time_1.feature
  • x/logic/predicate/block.go
Additional comments: 13
scripts/templates/func.go.txt (1)
  • 36-43: The addition of the conditional block for rendering data tables is a valuable enhancement for supporting Gherkin syntax in documentation. This change allows for the inclusion of structured, tabular data in examples, which can significantly improve the clarity and expressiveness of test scenarios. The implementation correctly checks for the presence of a DataTable and iterates over its rows to render the table in markdown format. This approach is consistent with the goal of enhancing documentation readability and utility.

However, it's important to ensure that the data table rendering aligns with the overall documentation style and that the table format is correctly supported in the target documentation environment. Additionally, consider adding a brief comment above the conditional block to explain its purpose for future maintainers.

docs/predicate/block_height_1.md (2)
  • 15-15: The addition of the is det annotation to the block_height/1 predicate's signature is a good practice. It clearly indicates that the predicate is deterministic, meaning it will always produce the same output given the same input. This is crucial information for users and developers, as it sets expectations about the predicate's behavior.
  • 24-52: The scenarios added to demonstrate retrieving the block height of the current block and checking if it is greater than a certain value are well-structured and provide clear, step-by-step examples of how to use the block_height/1 predicate. These examples enhance the documentation by offering practical use cases that help users understand the predicate's functionality in real-world contexts.

One minor suggestion is to ensure consistency in the formatting of the code blocks and tables across the documentation. For example, ensuring that the indentation and spacing within code blocks and tables are uniform can improve readability.

docs/predicate/block_time_1.md (2)
  • 15-15: The update to the block_time/1 predicate's signature to include the is det annotation is consistent with the changes made to the block_height/1 predicate. This annotation clarifies the deterministic nature of the predicate, which is beneficial for users and developers by setting clear expectations about its behavior.
  • 24-84: The scenarios added for the block_time/1 predicate, which demonstrate how to retrieve the block time of the current block and check if it is greater than a specific time, are well-structured and informative. These examples provide valuable insights into the predicate's practical applications, enhancing the documentation's utility.

As with the previous file, ensuring consistency in the formatting of code blocks and tables can further improve the documentation's readability. Additionally, consider adding a brief explanation or comment about the significance of the specific time used in the examples (e.g., "1709550216 seconds (Monday 4 March 2024 11:03:36 GMT)") to provide context for users unfamiliar with Unix time representation.

x/logic/keeper/features_test.go (8)
  • 9-9: The addition of the strconv import is necessary for converting strings to integers, likely used in the context of parsing block heights or times from strings. This is a standard library import and is correctly placed in the import block.
  • 12-12: The addition of the time import is necessary for working with time-related operations, such as setting the block time in test scenarios. This is a standard library import and is correctly placed in the import block.
  • 36-36: The introduction of a global variable key to hold the store key is a significant change. It's important to ensure that this key is used consistently across the test suite and does not introduce any side effects or conflicts with other tests. Using a global variable for the store key can be justified in a test context, especially if it simplifies setup and teardown processes or if it's used across multiple test cases.
  • 54-57: Refactoring the testCase struct to include new fields (t, ctx, request, got) enhances the structure and clarity of test cases. This change allows for better encapsulation of test case data and context, making the tests more readable and maintainable. Ensure that all instances of testCase are updated to reflect these changes and that the new fields are utilized appropriately in test functions.
  • 72-96: The addition of the givenABlockWithTheFollowingHeader function is a positive enhancement to the test suite. It allows for setting up test scenarios with specific block headers, which is crucial for testing predicates like block_height/1 and block_time/1. The function correctly parses the table input and sets the block header accordingly. Ensure that error handling is robust and that invalid inputs are handled gracefully to prevent test flakiness.
  • 112-122: Refactoring the whenTheQueryIsRun function to use a new query client creation logic is a significant improvement. This change likely makes the test suite more flexible and adaptable to different testing environments or configurations. Ensure that the new query client creation logic (newQueryClient) is correctly implemented and that it integrates seamlessly with the rest of the test suite.
  • 182-210: The introduction of the newQueryClient function is a key enhancement to the test suite. It encapsulates the logic for creating a new query client, which is essential for executing queries in test scenarios. This function demonstrates good practice by isolating dependency setup and making the test suite more modular. Ensure that the function is used consistently across the test suite and that it correctly handles any potential errors during the query client creation process.
  • 212-218: The addition of the atoi64 helper function is a practical enhancement for converting string inputs to int64. This function is likely used in the context of parsing block heights or times from strings. Ensure that error handling is robust and that invalid inputs are handled gracefully to prevent test failures due to parsing errors.

@ccamel ccamel requested a review from amimart March 4, 2024 13:31
Copy link
Member

@amimart amimart left a comment

Choose a reason for hiding this comment

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

Nice 😉

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9f896a2 and 781e249.
Files selected for processing (7)
  • docs/predicate/block_height_1.md (2 hunks)
  • docs/predicate/block_time_1.md (2 hunks)
  • scripts/templates/func.go.txt (1 hunks)
  • x/logic/keeper/features/block_height_1.feature (1 hunks)
  • x/logic/keeper/features/block_time_1.feature (1 hunks)
  • x/logic/keeper/features_test.go (6 hunks)
  • x/logic/predicate/block.go (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • x/logic/keeper/features/block_height_1.feature
  • x/logic/keeper/features/block_time_1.feature
  • x/logic/predicate/block.go
Additional comments: 11
scripts/templates/func.go.txt (1)
  • 36-43: The addition of a conditional block to render a data table is a good enhancement for documentation clarity and expressiveness. However, ensure that the data table format aligns with the expected documentation standards and that the conditional logic correctly checks for the presence of a DataTable object.
docs/predicate/block_height_1.md (2)
  • 15-15: The update to the predicate's signature to include is det is a valuable addition for clarifying the determinism of the block_height/1 function. This aligns well with the documentation's goal of providing clear and precise information.
  • 24-52: The added scenarios for retrieving the block height and checking if it's greater than a certain value are well-documented and provide clear, practical examples of using the block_height/1 predicate. These additions enhance the documentation's usefulness and readability.
docs/predicate/block_time_1.md (2)
  • 15-15: The update to the predicate's signature to include is det is a valuable addition for clarifying the determinism of the block_time/1 function. This aligns well with the documentation's goal of providing clear and precise information.
  • 24-84: The added scenarios for retrieving the block time and checking if it's greater than a certain time are well-documented and provide clear, practical examples of using the block_time/1 predicate. These additions enhance the documentation's usefulness and readability.
x/logic/keeper/features_test.go (6)
  • 9-12: The addition of strconv and time imports is appropriate for the functionality being tested, particularly with the introduction of scenarios involving block height and time.
  • 58-61: Refactoring the testCase struct fields to include the test context and request/response objects is a good practice for organizing test data and making the tests more readable and maintainable.
  • 76-100: The addition of givenABlockWithTheFollowingHeader function is a significant improvement for setting up test scenarios. It allows for dynamic configuration of block headers based on the given table, enhancing the flexibility and expressiveness of the tests.
  • 116-126: Refactoring whenTheQueryIsRun to use a new query client creation logic is a positive change, ensuring that each test scenario uses a fresh client. This enhances test isolation and reliability.
  • 186-214: The newQueryClient function is well-implemented, providing a clean and isolated way to create a query client for test scenarios. This function contributes to the overall modularity and maintainability of the test suite.
  • 216-222: The atoi64 helper function is a useful addition for converting strings to int64, simplifying the process of handling numeric values in test scenarios. This utility function enhances code readability and reduces redundancy.

x/logic/keeper/features_test.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9f896a2 and 80b8390.
Files selected for processing (7)
  • docs/predicate/block_height_1.md (2 hunks)
  • docs/predicate/block_time_1.md (2 hunks)
  • scripts/templates/func.go.txt (1 hunks)
  • x/logic/keeper/features/block_height_1.feature (1 hunks)
  • x/logic/keeper/features/block_time_1.feature (1 hunks)
  • x/logic/keeper/features_test.go (6 hunks)
  • x/logic/predicate/block.go (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • x/logic/keeper/features/block_height_1.feature
  • x/logic/keeper/features/block_time_1.feature
  • x/logic/predicate/block.go
Additional comments: 8
scripts/templates/func.go.txt (1)
  • 36-43: The addition of the conditional block for rendering data tables in the documentation is a valuable enhancement. It improves the expressiveness of the examples by allowing the inclusion of structured data. This change aligns well with the goal of making documentation more informative and easier to understand.
docs/predicate/block_height_1.md (2)
  • 12-15: The update to the block_height/1 predicate's signature, including the is det annotation, clearly communicates its deterministic behavior. This is a valuable addition for users, enhancing their understanding of the predicate's behavior.
  • 24-52: The addition of scenarios for retrieving the block height and checking if it is greater than a certain value are excellent examples of the block_height/1 predicate's practical applications. These scenarios are clear, well-documented, and provide valuable insights into how the predicate can be used effectively.
docs/predicate/block_time_1.md (2)
  • 12-15: The update to the block_time/1 predicate's signature, including the is det annotation, effectively communicates its deterministic behavior. This clarification is crucial for users and enhances their understanding of how the predicate operates.
  • 24-84: The scenarios added for retrieving the block time and checking if it is greater than a certain time are clear and informative, effectively demonstrating the block_time/1 predicate's practical applications. These examples are well-documented and provide valuable insights for users.
x/logic/keeper/features_test.go (3)
  • 9-12: The addition of strconv and time imports, along with the global variable key, are appropriate for the enhancements made to the test suite. These changes support the new functionality introduced in the tests and follow best practices for Cosmos SDK testing.
  • 54-57: The refactoring of the testCase struct fields improves the structure and clarity of the test cases, making them more aligned with the specific requirements of the test scenarios.
  • 72-97: The addition of the givenABlockWithTheFollowingHeader function enhances the test suite by providing a clear and reusable way to set up test scenarios involving block headers. This function, along with others like newQueryClient, contributes significantly to making the tests more robust and maintainable.

@ccamel ccamel merged commit 2aade1a into main Mar 5, 2024
19 checks passed
@ccamel ccamel deleted the test/block branch March 5, 2024 08:19
@bot-anik
Copy link
Member

bot-anik commented Mar 5, 2024

🎉 This PR is included in version 7.0.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants