-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
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 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. WalkthroughThe changes comprise various structural and functional updates across multiple packages. Key modifications include switching data types from Changes
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAttention: Patch coverage is
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. |
There was a problem hiding this 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
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 inBalanceGenerator
.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 inBalanceGenerator
.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 inPriceGenerator
.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 inPriceGenerator
.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.
There was a problem hiding this 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
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 forMaxValidators
.The
MaxValidators
field inStakingParams
is defined asint
. 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.
There was a problem hiding this 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
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 oft.Parallel()
for concurrent testing andassert.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 toint64
usingInt64()
. 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.
There was a problem hiding this 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
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 testspkg/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 usingUnbondsGenerator
, 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 usingUnbondsGenerator
, 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 usingDelegationsGenerator
, 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 usingDelegationsGenerator
, 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 functionChangeBech32Prefix
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 fromint64
touint64
for theUnbonds
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 DelegationsDataThe change from
int64
touint64
for theDelegations
map inDelegationsData
is appropriate if the data it holds cannot be negative. This change should help in preventing potential underflow issues.
There was a problem hiding this 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
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 testspkg/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 testspkg/generators/validator_rank.go
[warning] 85-85: pkg/generators/validator_rank.go#L85
Added line #L85 was not covered by testspkg/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
andgithub.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 ofrequire.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.
There was a problem hiding this 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
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 settingDelegatorShares
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.
Summary by CodeRabbit
Bug Fixes
int64
touint64
.Refactor
Tests
New Features