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

chore: add generators test #62

Merged
merged 28 commits into from
Jun 22, 2024
Merged

chore: add generators test #62

merged 28 commits into from
Jun 22, 2024

Conversation

freak12techno
Copy link
Collaborator

@freak12techno freak12techno commented Jun 22, 2024

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where delegation and unbond values were incorrectly handled by changing data types from int64 to uint64.
  • Refactor

    • Updated various generator and fetcher modules to use more precise data types and improved methods for better performance and accuracy.
  • Tests

    • Added extensive test cases for multiple generators to validate functionality under different state scenarios.
    • Renamed some test functions for better clarity on what they are testing.
  • New Features

    • Introduced new utility functions and structures to improve codebase maintainability and functionality.
    • Added a function for changing Bech32 prefixes in utility module.

Copy link
Contributor

coderabbitai bot commented Jun 22, 2024

Warning

Rate limit exceeded

@freak12techno has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 27 minutes and 19 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 6297a8d and 6ec167d.

Walkthrough

The changes comprise various structural and functional updates across multiple packages. Key modifications include switching data types from int64 to uint64 in delegation and unbonding logics, enhanced tests for the balance, commission, and consumer info generators, and new test files for improved coverage. Also, several utility methods were updated or removed, leading to a more efficient handling of data conversions and calculations.

Changes

File Path Change Summary
pkg/fetchers/delegations.go, pkg/fetchers/unbonds.go Changed types in DelegationsData and UnbondsData from int64 to uint64.
pkg/generators/balance_test.go Renamed test function from TestBlockSetValidators to TestBalanceGeneratorNotEmptyState.
pkg/generators/commission_test.go, consumer_info_test.go, ... Added new test files and functions validating generators for commission, consumer info, delegations, denom coefficients, etc.
pkg/generators/consumer_info.go Removed import for utils and updated data conversion methods.
pkg/generators/signing_info.go Updated method for converting missedBlocksCounter from string to int64.
pkg/generators/validator_rank.go Changed calculation method for sorting activeValidators based on DelegatorShares.
pkg/generators/validators_info.go Introduced usage of cosmossdk.io/math package for decimal calculations.
pkg/types/tendermint.go Introduced new public struct types SigningInfo, SlashingParams, and StakingParams.
pkg/types/tendermint_test.go Added imports for new packages and updated error handling for amount conversions.
pkg/utils/utils.go Removed StrToInt64 function and added a new ChangeBech32Prefix function.
pkg/utils/utils_test.go Removed TestStrToInt64 and related test functions.

Poem

Amid the code, a shift we see,
Ints to uints for precision's glee.
New tests arise, in files they sprawl,
Assuring quality, one and all.
🌟🐰 Numbers fly, through logic dense,
Code refined, in every sense.


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

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.

Copy link

codecov bot commented Jun 22, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 7 lines in your changes missing coverage. Please review.

Project coverage is 40.98%. Comparing base (4bb8f21) to head (6ec167d).

Files Patch % Lines
pkg/fetchers/delegations.go 0.00% 4 Missing ⚠️
pkg/fetchers/unbonds.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #62       +/-   ##
===========================================
+ Coverage   13.38%   40.98%   +27.60%     
===========================================
  Files          59       59               
  Lines        2272     2264        -8     
===========================================
+ Hits          304      928      +624     
+ Misses       1967     1335      -632     
  Partials        1        1               

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4bb8f21 and ab61fb2.

Files selected for processing (2)
  • pkg/generators/balance_test.go (1 hunks)
  • pkg/generators/price_test.go (1 hunks)
Additional comments not posted (4)
pkg/generators/balance_test.go (2)

Line range hint 1-21: LGTM: Test for empty state in BalanceGenerator.

The function TestBalanceGeneratorNoState is well-implemented to test the generator with an empty state, ensuring that no results are generated as expected.


Line range hint 22-34: Well-implemented test for non-empty state in BalanceGenerator.

The function TestBalanceGeneratorNotEmptyState effectively tests the generator with a non-empty state. The setup of balance data is detailed and specific, which helps in accurately assessing the generator's functionality.

pkg/generators/price_test.go (2)

12-19: LGTM: Test for empty state in PriceGenerator.

The function TestPriceGeneratorNoState correctly tests the generator with an empty state, ensuring that no results are generated as expected.


21-36: Well-implemented test for non-empty state in PriceGenerator.

The function TestPriceGeneratorNotEmptyState effectively tests the generator with a non-empty state. The setup of price data is detailed and specific, helping to accurately assess the generator's functionality.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ab61fb2 and d011163.

Files selected for processing (5)
  • pkg/generators/signing_info_test.go (1 hunks)
  • pkg/generators/slashing_params_test.go (1 hunks)
  • pkg/generators/soft_opt_out_threshold_test.go (1 hunks)
  • pkg/generators/staking_params_test.go (1 hunks)
  • pkg/types/tendermint.go (2 hunks)
Additional comments not posted (9)
pkg/generators/soft_opt_out_threshold_test.go (2)

12-19: Test function for empty state is well-implemented.

The function TestSoftOptOutThresholdGeneratorNoState is correctly using parallel test execution and properly initializes the state. The assertion to check empty results is appropriate for the scenario.


21-34: Test function for non-empty state is correctly implemented.

The function TestSoftOptOutThresholdGeneratorNotEmptyState effectively sets a predefined state and correctly asserts that the results are not empty, which is expected behavior based on the setup.

pkg/generators/staking_params_test.go (2)

13-19: Test function for empty state is well-implemented.

The function TestStakingParamsGeneratorNoState correctly uses parallel test execution and properly initializes the state. The assertion to check empty results is appropriate for the scenario.


22-38: Test function for non-empty state is correctly implemented.

The function TestStakingParamsGeneratorNotEmptyState effectively sets a predefined state and correctly asserts that the results are not empty, which is expected behavior based on the setup.

pkg/generators/slashing_params_test.go (2)

13-19: Test function for empty state is well-implemented.

The function TestSlashingParamsGeneratorNoState correctly uses parallel test execution and properly initializes the state. The assertion to check empty results is appropriate for the scenario.


22-38: Test function for non-empty state is correctly implemented.

The function TestSlashingParamsGeneratorNotEmptyState effectively sets a predefined state and correctly asserts that the results are not empty, which is expected behavior based on the setup.

pkg/generators/signing_info_test.go (2)

13-19: Test function for empty state is well-implemented.

The function TestSigningInfoGeneratorNoState correctly uses parallel test execution and properly initializes the state. The assertion to check empty results is appropriate for the scenario.


22-40: Test function for non-empty state is correctly implemented.

The function TestSigningInfoGeneratorNotEmptyState effectively sets a predefined state and correctly asserts that the results are not empty, which is expected behavior based on the setup.

pkg/types/tendermint.go (1)

123-124: Review the data type for MaxValidators.

The MaxValidators field in StakingParams is defined as int. This is appropriate if the expected number of validators is not excessively large. Ensure this aligns with the expected usage and maximum possible validators in the system.

pkg/types/tendermint.go Outdated Show resolved Hide resolved
pkg/types/tendermint.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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d011163 and f17910e.

Files selected for processing (14)
  • pkg/generators/commission_test.go (1 hunks)
  • pkg/generators/consumer_info.go (2 hunks)
  • pkg/generators/consumer_info_test.go (1 hunks)
  • pkg/generators/denom_coefficient_test.go (1 hunks)
  • pkg/generators/is_consumer_test.go (1 hunks)
  • pkg/generators/node_info_test.go (1 hunks)
  • pkg/generators/rewards_test.go (1 hunks)
  • pkg/generators/self_delegations_test.go (1 hunks)
  • pkg/generators/signing_info.go (2 hunks)
  • pkg/generators/signing_info_test.go (1 hunks)
  • pkg/generators/slashing_params.go (2 hunks)
  • pkg/generators/slashing_params_test.go (1 hunks)
  • pkg/generators/uptime_test.go (1 hunks)
  • pkg/types/tendermint.go (5 hunks)
Files skipped from review due to trivial changes (2)
  • pkg/generators/consumer_info.go
  • pkg/generators/slashing_params.go
Files skipped from review as they are similar to previous changes (3)
  • pkg/generators/signing_info_test.go
  • pkg/generators/slashing_params_test.go
  • pkg/types/tendermint.go
Additional comments not posted (14)
pkg/generators/uptime_test.go (1)

1-17: Test structure approved.

The test for UptimeGenerator is well-structured and follows good practices for unit testing. The use of t.Parallel() for concurrent testing and assert.NotEmpty to validate the results are particularly noteworthy.

pkg/generators/is_consumer_test.go (1)

1-29: Test structure approved.

The test for IsConsumerGenerator is well-structured and effectively tests the generator's ability to identify consumer chains. The setup of mock data and the use of assertions are correctly implemented.

pkg/generators/denom_coefficient_test.go (1)

1-35: Test structure approved.

The test for DenomCoefficientGenerator is well-structured and effectively tests the handling of different denominations across chains. The setup of mock data and the use of assertions are correctly implemented.

pkg/generators/rewards_test.go (2)

13-20: Test structure approved for empty state scenario.

The test TestRewardsGeneratorNoState correctly checks the generator's behavior with an empty state, ensuring that no data leads to no results, which is a valid scenario.


22-39: Test structure approved for non-empty state scenario.

The test TestRewardsGeneratorNotEmptyState effectively tests the generator's functionality with a non-empty state. The setup of mock data and the use of assertions to check for non-empty results are correctly implemented.

pkg/generators/self_delegations_test.go (2)

13-20: Test function for empty state is well-implemented.

The function TestSelfDelegationGeneratorNoState correctly sets up a test for the scenario where no state is present, and it properly asserts that the results should be empty.


22-37: Test function for non-empty state is correctly implemented.

The function TestSelfDelegationGeneratorNotEmptyState effectively tests the generator with a non-empty state, ensuring that the results are not empty when expected data is present.

pkg/generators/commission_test.go (2)

13-20: Test function for empty state is well-implemented.

The function TestCommissionGeneratorNoState correctly sets up a test for the scenario where no state is present, and it properly asserts that the results should be empty.


22-39: Test function for non-empty state is correctly implemented.

The function TestCommissionGeneratorNotEmptyState effectively tests the generator with a non-empty state, ensuring that the results are not empty when expected data is present.

pkg/generators/consumer_info_test.go (2)

15-22: Test function for empty state is well-implemented.

The function TestConsumerInfoGeneratorNoState correctly sets up a test for the scenario where no state is present, and it properly asserts that the results should be empty.


24-41: Test function for non-empty state is correctly implemented.

The function TestConsumerInfoGeneratorNotEmptyState effectively tests the generator with a non-empty state, ensuring that the results are not empty when expected data is present.

pkg/generators/node_info_test.go (2)

13-20: Test function for empty state is well-implemented.

The function TestNodeInfoGeneratorNoState correctly sets up a test for the scenario where no state is present, and it properly asserts that the results should be empty.


22-43: Test function for non-empty state is correctly implemented.

The function TestNodeInfoGeneratorNotEmptyState effectively tests the generator with a non-empty state, ensuring that the results are not empty when expected data is present.

pkg/generators/signing_info.go (1)

36-36: Ensure proper handling of type conversion and possible errors.

The code directly assumes that the MissedBlocksCounter can be successfully converted to int64 using Int64(). Consider checking for errors during this conversion to avoid runtime panics if the conversion fails.

- missedBlocksCounter := signingInfo.ValSigningInfo.MissedBlocksCounter.Int64()
+ missedBlocksCounter, err := signingInfo.ValSigningInfo.MissedBlocksCounter.Int64()
+ if err != nil {
+     // Handle error appropriately, perhaps log it or continue with a default value
+     continue
+ }

Likely invalid or redundant comment.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f17910e and 9c3b1e6.

Files selected for processing (8)
  • pkg/fetchers/delegations.go (4 hunks)
  • pkg/fetchers/unbonds.go (4 hunks)
  • pkg/generators/delegations_test.go (1 hunks)
  • pkg/generators/denom_coefficient_test.go (1 hunks)
  • pkg/generators/unbonds_test.go (1 hunks)
  • pkg/types/tendermint.go (6 hunks)
  • pkg/utils/utils.go (1 hunks)
  • pkg/utils/utils_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • pkg/utils/utils_test.go
Files skipped from review as they are similar to previous changes (2)
  • pkg/generators/denom_coefficient_test.go
  • pkg/types/tendermint.go
Additional context used
GitHub Check: codecov/patch
pkg/fetchers/unbonds.go

[warning] 45-45: pkg/fetchers/unbonds.go#L45
Added line #L45 was not covered by tests


[warning] 52-52: pkg/fetchers/unbonds.go#L52
Added line #L52 was not covered by tests


[warning] 83-83: pkg/fetchers/unbonds.go#L83
Added line #L83 was not covered by tests

pkg/fetchers/delegations.go

[warning] 45-45: pkg/fetchers/delegations.go#L45
Added line #L45 was not covered by tests


[warning] 51-51: pkg/fetchers/delegations.go#L51
Added line #L51 was not covered by tests


[warning] 53-53: pkg/fetchers/delegations.go#L53
Added line #L53 was not covered by tests


[warning] 86-86: pkg/fetchers/delegations.go#L86
Added line #L86 was not covered by tests

Additional comments not posted (7)
pkg/generators/unbonds_test.go (2)

12-19: Test function for no state scenario is well-implemented.

The test TestUnbondsGeneratorNoState correctly initializes a state, generates results using UnbondsGenerator, and asserts that the results should be empty. This is a standard approach for testing the behavior with no state.


21-36: Test function for non-empty state scenario is well-implemented.

The test TestUnbondsGeneratorNotEmptyState correctly initializes a state with mock data, generates results using UnbondsGenerator, and asserts that the results are not empty. This ensures that the generator behaves as expected when the state is populated.

pkg/generators/delegations_test.go (2)

12-19: Test function for no state scenario is well-implemented.

The test TestDelegationsGeneratorNoState correctly initializes a state, generates results using DelegationsGenerator, and asserts that the results should be empty. This follows the expected behavior for testing with no initial state.


21-36: Test function for non-empty state scenario is well-implemented.

The test TestDelegationsGeneratorNotEmptyState correctly sets up a state with mock data, generates results using DelegationsGenerator, and asserts that the results are not empty. This confirms that the generator functions correctly when the state is populated.

pkg/utils/utils.go (1)

Line range hint 19-21: New utility function ChangeBech32Prefix is well-implemented.

The function ChangeBech32Prefix correctly handles the decoding and re-encoding of Bech32 addresses. It properly returns an error when decoding fails, which is a good practice for error handling in utility functions.

pkg/fetchers/unbonds.go (1)

23-23: Data structure change is correctly implemented.

The change in the UnbondsData struct from int64 to uint64 for the Unbonds map is correctly implemented. This change aligns with the overall PR goal of type modifications.

pkg/fetchers/delegations.go (1)

23-23: Type Change from int64 to uint64 in DelegationsData

The change from int64 to uint64 for the Delegations map in DelegationsData is appropriate if the data it holds cannot be negative. This change should help in preventing potential underflow issues.

pkg/fetchers/delegations.go Show resolved Hide resolved
pkg/fetchers/delegations.go Show resolved Hide resolved
pkg/fetchers/delegations.go Show resolved Hide resolved
pkg/fetchers/unbonds.go Show resolved Hide resolved
@freak12techno freak12techno changed the title chore: add price generator test chore: add generators test Jun 22, 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: 9

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9c3b1e6 and c881d20.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (23)
  • go.mod (3 hunks)
  • pkg/generators/active_set_tokens.go (1 hunks)
  • pkg/generators/balance_test.go (3 hunks)
  • pkg/generators/commission_test.go (1 hunks)
  • pkg/generators/consumer_info_test.go (1 hunks)
  • pkg/generators/delegations_test.go (1 hunks)
  • pkg/generators/denom_coefficient_test.go (1 hunks)
  • pkg/generators/is_consumer_test.go (1 hunks)
  • pkg/generators/node_info_test.go (1 hunks)
  • pkg/generators/price_test.go (1 hunks)
  • pkg/generators/rewards_test.go (1 hunks)
  • pkg/generators/self_delegations_test.go (1 hunks)
  • pkg/generators/signing_info_test.go (1 hunks)
  • pkg/generators/single_validator_info.go (1 hunks)
  • pkg/generators/slashing_params_test.go (1 hunks)
  • pkg/generators/soft_opt_out_threshold_test.go (1 hunks)
  • pkg/generators/staking_params_test.go (1 hunks)
  • pkg/generators/unbonds_test.go (1 hunks)
  • pkg/generators/uptime_test.go (1 hunks)
  • pkg/generators/validator_rank.go (1 hunks)
  • pkg/generators/validators_info.go (3 hunks)
  • pkg/types/tendermint.go (8 hunks)
  • pkg/types/tendermint_test.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • go.mod
Files skipped from review as they are similar to previous changes (17)
  • pkg/generators/balance_test.go
  • pkg/generators/commission_test.go
  • pkg/generators/consumer_info_test.go
  • pkg/generators/delegations_test.go
  • pkg/generators/denom_coefficient_test.go
  • pkg/generators/is_consumer_test.go
  • pkg/generators/node_info_test.go
  • pkg/generators/price_test.go
  • pkg/generators/rewards_test.go
  • pkg/generators/self_delegations_test.go
  • pkg/generators/signing_info_test.go
  • pkg/generators/slashing_params_test.go
  • pkg/generators/soft_opt_out_threshold_test.go
  • pkg/generators/staking_params_test.go
  • pkg/generators/unbonds_test.go
  • pkg/generators/uptime_test.go
  • pkg/types/tendermint.go
Additional context used
GitHub Check: codecov/patch
pkg/generators/active_set_tokens.go

[warning] 61-61: pkg/generators/active_set_tokens.go#L61
Added line #L61 was not covered by tests


[warning] 64-64: pkg/generators/active_set_tokens.go#L64
Added line #L64 was not covered by tests

pkg/generators/validators_info.go

[warning] 59-59: pkg/generators/validators_info.go#L59
Added line #L59 was not covered by tests


[warning] 62-62: pkg/generators/validators_info.go#L62
Added line #L62 was not covered by tests


[warning] 65-65: pkg/generators/validators_info.go#L65
Added line #L65 was not covered by tests


[warning] 74-74: pkg/generators/validators_info.go#L74
Added line #L74 was not covered by tests

pkg/generators/validator_rank.go

[warning] 85-85: pkg/generators/validator_rank.go#L85
Added line #L85 was not covered by tests

pkg/generators/single_validator_info.go

[warning] 160-160: pkg/generators/single_validator_info.go#L160
Added line #L160 was not covered by tests


[warning] 165-165: pkg/generators/single_validator_info.go#L165
Added line #L165 was not covered by tests


[warning] 170-170: pkg/generators/single_validator_info.go#L170
Added line #L170 was not covered by tests


[warning] 175-175: pkg/generators/single_validator_info.go#L175
Added line #L175 was not covered by tests

Additional comments not posted (3)
pkg/types/tendermint_test.go (2)

6-7: Approve the addition of new imports.

The new imports (cosmossdk.io/math and github.com/stretchr/testify/require) are appropriate for the operations performed in the tests, such as handling decimal amounts and improved assertion handling.


22-26: Updated test function logic is correct.

The changes made to use the math.LegacyNewDecFromStr for handling decimal string conversion and the use of require.NoError for error handling are correct and improve the robustness of the test.

pkg/generators/validators_info.go (1)

11-11: Approve the new import for decimal calculations.

The addition of the cosmossdk.io/math package is appropriate for handling precise decimal calculations in the context of blockchain and financial computations.

pkg/generators/single_validator_info.go Show resolved Hide resolved
pkg/generators/single_validator_info.go Show resolved Hide resolved
pkg/generators/single_validator_info.go Show resolved Hide resolved
pkg/generators/single_validator_info.go Show resolved Hide resolved
pkg/generators/active_set_tokens.go Show resolved Hide resolved
pkg/generators/active_set_tokens.go Show resolved Hide resolved
pkg/generators/validators_info.go Outdated Show resolved Hide resolved
pkg/generators/validators_info.go Show resolved Hide resolved
pkg/generators/validator_rank.go 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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c881d20 and 6297a8d.

Files selected for processing (4)
  • pkg/generators/active_set_tokens_test.go (1 hunks)
  • pkg/generators/validator_rank_test.go (1 hunks)
  • pkg/generators/validators_info.go (3 hunks)
  • pkg/generators/validators_info_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pkg/generators/validators_info.go
Additional context used
Learnings (1)
pkg/generators/active_set_tokens_test.go (1)
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#62
File: pkg/generators/active_set_tokens.go:61-61
Timestamp: 2024-06-22T22:57:51.216Z
Learning: The indirect testing method used in `ActiveSetTokensGenerator`, which verifies the outcome by checking the metric's value against the expected stake of the last active validator, is considered sufficient by the user for reflecting the intended behavior of the sorting logic.
Additional comments not posted (15)
pkg/generators/validators_info_test.go (4)

17-24: LGTM!

The test is well-structured and checks the expected behavior when no validators are present. It uses parallel execution and asserts that the results are empty, which is appropriate for the scenario.


26-34: LGTM!

This test validates the scenario where no consumer validators are present. It correctly sets an empty ValidatorsData in the state and checks for empty results. Parallel execution is used efficiently.


36-78: LGTM!

The test covers the scenario where the validators are not consumers. It sets up a state with specific validators and checks the length and values of the results using Prometheus metrics. The use of math.LegacyMustNewDecFromStr for setting DelegatorShares demonstrates good integration with the cosmos SDK.


80-109: LGTM!

This test handles the scenario with consumer validators. It sets up the state with empty validator data and checks the results' length and values. The use of Prometheus metrics to verify the results is consistent and appropriate.

pkg/generators/active_set_tokens_test.go (6)

18-25: LGTM!

The test ensures that no results are generated when no validators are present, using parallel execution and asserting the results are empty.


27-35: LGTM!

This test checks the generator behavior when no staking parameters are set. It appropriately asserts that the results are empty, indicating robust error handling and edge case consideration.


37-51: LGTM!

The test verifies the generator's response when validators are absent for a specific chain. It correctly sets up the state and uses assertions to ensure that the results are not empty but contain no data, which is expected behavior.


53-71: LGTM!

This test effectively checks the scenario where staking parameters are not set for a chain. It confirms that the generator still produces results, but the collected count is zero, which meets the expectations for this case.
[APPLIED]


73-105: LGTM!

The test is designed to handle scenarios where the number of validators does not meet the required maximum. It sets up the state accordingly and validates that the gauge values are correctly calculated and reported.


107-139: LGTM!

This test checks the generator's functionality when there are sufficient validators. It ensures that the gauge values are correctly computed based on the validators' shares, demonstrating a thorough understanding of the domain logic.

pkg/generators/validator_rank_test.go (5)

19-26: LGTM!

This test evaluates the generator when the state is empty. It uses parallel execution and asserts that no results are generated, which aligns with expected behavior when no data is available.


28-41: LGTM!

The test checks the generator's output when no validators are associated with a chain. It correctly asserts that the results are not empty but contain no data, which is the expected outcome for this scenario.


43-69: LGTM!

This test handles the case where validators specified in the configuration are not found in the fetched data. It sets up the state appropriately and checks that the results are not empty but contain no data, confirming the generator's correct behavior when data is mismatched.


71-106: LGTM!

The test is focused on a scenario where none of the validators are active. It ensures that the generator still produces results, but the collected count is zero, which is consistent with the expectations for this scenario.


108-149: LGTM!

This test validates the generator's functionality when there are active validators. It effectively uses the InEpsilon assertion to check if the gauge values are within an acceptable range, which is crucial for accuracy in metrics reporting.

@freak12techno freak12techno merged commit ca3df04 into main Jun 22, 2024
8 checks passed
@freak12techno freak12techno deleted the add-generators-tests branch June 22, 2024 23:42
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.

1 participant