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

feat: refactor denoms #64

Merged
merged 9 commits into from
Jun 25, 2024
Merged

feat: refactor denoms #64

merged 9 commits into from
Jun 25, 2024

Conversation

freak12techno
Copy link
Collaborator

@freak12techno freak12techno commented Jun 23, 2024

Summary by CodeRabbit

  • New Features

    • Introduced currency conversion functionality to convert amounts based on denomination information.
    • Added a new label "denom" to Prometheus metrics for better tracking of active set tokens.
  • Bug Fixes

    • Enhanced validation for base denominations and wallet prefixes in chain configurations.
  • Tests

    • Updated test cases to validate new configurations and data structures for chains and denominations.
    • Added new test scenarios to cover the updated validation rules and metrics tracking.
  • Chores

    • Improved error handling and warnings in chain and consumer chain validations.

Copy link
Contributor

coderabbitai bot commented Jun 23, 2024

Walkthrough

This update adds significant enhancements to the application by introducing support for handling currency denominations, improving validation logic, and enriching Prometheus metrics with new labels. Key changes include augmenting functions to accept new parameters, updating test cases, adding new validation methods, and modifying configurations to include denomination information.

Changes

File(s) Change Summary
pkg/app.go, pkg/generators/active_set_tokens_test.go, pkg/generators/balance_test.go, pkg/generators/commission_test.go, pkg/generators/rewards_test.go, pkg/generators/self_delegations_test.go, pkg/generators/single_validator_info_test.go, pkg/generators/validators_info_test.go Introduced new parameters in generator functions and test scenarios, including handling of denominations.
pkg/config/denom_info.go Added Convert method in DenomInfos struct for currency conversion.
pkg/config/chain.go, pkg/config/chain_test.go, pkg/config/config_test.go Updated validation logic and warnings in Chain struct, added tests for new fields BaseDenom and BechWalletPrefix.
pkg/config/consumer_chain.go, pkg/config/consumer_chain_test.go Added DisplayWarnings method and validation for BaseDenom in ConsumerChain struct.
pkg/fetchers/signing_info.go, pkg/fetchers/signing_info_test.go Enhanced fetcher to include BechValidatorPrefix in the condition validation and modified test cases.

Poem

In code's vast maze, we found our way,
With chains and denoms on display.
Validators' shares, we finely tune,
Metrics dance under the moon.
Validation firm, where errors loom,
A rabbit's joy, in code's bright bloom.
🐇✨


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 23, 2024

Codecov Report

Attention: Patch coverage is 96.64430% with 5 lines in your changes missing coverage. Please review.

Project coverage is 90.16%. Comparing base (0485a96) to head (ae6c5a3).

Files Patch % Lines
pkg/app.go 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #64      +/-   ##
==========================================
+ Coverage   89.89%   90.16%   +0.26%     
==========================================
  Files          59       58       -1     
  Lines        2237     2287      +50     
==========================================
+ Hits         2011     2062      +51     
+ Misses        225      224       -1     
  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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ca3df04 and 4ebc9db.

Files selected for processing (4)
  • pkg/app.go (1 hunks)
  • pkg/config/denom_info.go (2 hunks)
  • pkg/generators/balance.go (3 hunks)
  • pkg/generators/balance_test.go (3 hunks)
Additional context used
GitHub Check: codecov/patch
pkg/app.go

[warning] 113-113: pkg/app.go#L113
Added line #L113 was not covered by tests

Additional comments not posted (3)
pkg/generators/balance.go (2)

16-17: Constructor for BalanceGenerator properly initializes the Chains field.

The constructor NewBalanceGenerator correctly initializes the Chains field of the BalanceGenerator struct. This is a straightforward and effective implementation.


36-77: Refactored Generate method in BalanceGenerator.

The refactoring in the Generate method to iterate over g.Chains and chain.ConsumerChains instead of data.Balances aligns with the structural changes in the data model. This should provide a more robust way of handling balances across multiple chains and their consumers.

Ensure proper testing, especially around the nested loops and conditional checks, to prevent any data mishandling.

pkg/generators/balance_test.go (1)

Line range hint 21-94: Updated tests for BalanceGenerator.

The updates in the test cases reflect the new structure of BalanceGenerator and the data model changes. The tests seem to be comprehensive, covering various scenarios and using assertions to validate the behavior.

Ensure that all edge cases, especially error handling and boundary conditions, are covered in the tests.

pkg/config/denom_info.go Outdated Show resolved Hide resolved
pkg/app.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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4ebc9db and be14b4b.

Files selected for processing (7)
  • pkg/app.go (1 hunks)
  • pkg/generators/commission.go (3 hunks)
  • pkg/generators/commission_test.go (3 hunks)
  • pkg/generators/rewards.go (3 hunks)
  • pkg/generators/rewards_test.go (3 hunks)
  • pkg/generators/self_delegation.go (3 hunks)
  • pkg/generators/self_delegations_test.go (3 hunks)
Files not reviewed due to errors (3)
  • pkg/generators/rewards_test.go (no review received)
  • pkg/generators/commission_test.go (no review received)
  • pkg/generators/self_delegations_test.go (no review received)
Additional context used
Learnings (1)
pkg/app.go (1)
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#64
File: pkg/app.go:113-113
Timestamp: 2024-06-23T21:45:53.914Z
Learning: The integration of `NewBalanceGenerator` with `appConfig.Chains` in the `App` constructor is implicitly tested in the `TestBalanceGeneratorNotEmptyState` test case. This test case checks the behavior of `NewBalanceGenerator` when provided with specific chain configurations.
GitHub Check: codecov/patch
pkg/app.go

[warning] 108-108: pkg/app.go#L108
Added line #L108 was not covered by tests


[warning] 112-114: pkg/app.go#L112-L114
Added lines #L112 - L114 were not covered by tests

Additional comments not posted (6)
pkg/generators/rewards.go (2)

16-17: Constructor correctly initializes Chains field.

The new constructor implementation properly initializes the RewardsGenerator with the given chain configurations, aligning with the PR's refactoring goals.


36-54: Enhanced loop logic to handle multiple chains and currency conversion.

The updated loop in the Generate method effectively iterates over multiple chain configurations, utilizing the new Convert method for accurate denomination conversions. This is a significant improvement for scalability and flexibility in handling various chain specifics.

pkg/generators/self_delegation.go (2)

16-17: Constructor correctly initializes Chains field in SelfDelegationGenerator.

The constructor for SelfDelegationGenerator is correctly updated to initialize the Chains field, ensuring that chain configurations are properly passed to the generator.


36-53: Updated Generate method to support multiple chain configurations.

The Generate method in SelfDelegationGenerator has been effectively updated to iterate over multiple chains and perform currency conversions using the newly introduced Convert method. This enhances the functionality to accommodate varying chain specifics.

pkg/generators/commission.go (2)

16-17: Proper initialization of Chains field in CommissionGenerator.

The constructor for CommissionGenerator has been updated to initialize the Chains field, which is crucial for handling multiple chain configurations effectively.


36-54: Updated Generate method to handle chain-specific commission data.

The Generate method in CommissionGenerator has been updated to handle multiple chains, using the Convert method for accurate currency conversions. This ensures that the generator can adapt to different chain configurations and their specific commission data.

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

Outside diff range and nitpick comments (3)
pkg/generators/rewards.go (1)

13-13: Add documentation for Chains field.

The Chains field in RewardsGenerator struct is missing documentation. It's best practice to document public fields, especially in a struct that is likely central to your application logic.

pkg/generators/self_delegation.go (1)

13-13: Add documentation for Chains field.

Similar to the RewardsGenerator, the Chains field in SelfDelegationGenerator struct lacks documentation. Adding a comment here would improve code readability and maintainability.

pkg/generators/commission.go (1)

13-13: Add documentation for Chains field.

The Chains field in CommissionGenerator struct is also missing documentation. Consistent with other generator files, adding a comment here would be beneficial.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4ebc9db and 11a2fe4.

Files selected for processing (14)
  • pkg/app.go (1 hunks)
  • pkg/config/denom_info.go (2 hunks)
  • pkg/fetchers/price.go (1 hunks)
  • pkg/fetchers/price_test.go (5 hunks)
  • pkg/generators/balance.go (3 hunks)
  • pkg/generators/balance_test.go (3 hunks)
  • pkg/generators/commission.go (3 hunks)
  • pkg/generators/commission_test.go (3 hunks)
  • pkg/generators/rewards.go (3 hunks)
  • pkg/generators/rewards_test.go (3 hunks)
  • pkg/generators/self_delegation.go (3 hunks)
  • pkg/generators/self_delegations_test.go (3 hunks)
  • pkg/generators/validators_info.go (4 hunks)
  • pkg/generators/validators_info_test.go (7 hunks)
Files skipped from review as they are similar to previous changes (3)
  • pkg/config/denom_info.go
  • pkg/generators/balance.go
  • pkg/generators/balance_test.go
Additional context used
Learnings (2)
pkg/generators/validators_info_test.go (1)
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/consumer_validators.go:40-40
Timestamp: 2024-06-23T16:11:23.143Z
Learning: The `TestConsumerValidatorsFetcherBase` method in `pkg/fetchers/consumer_validators_test.go` tests the initialization of `ConsumerValidatorsFetcher` with the `Chains` parameter.
pkg/app.go (1)
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#64
File: pkg/app.go:113-113
Timestamp: 2024-06-23T21:45:53.914Z
Learning: The integration of `NewBalanceGenerator` with `appConfig.Chains` in the `App` constructor is implicitly tested in the `TestBalanceGeneratorNotEmptyState` test case. This test case checks the behavior of `NewBalanceGenerator` when provided with specific chain configurations.
GitHub Check: codecov/patch
pkg/app.go

[warning] 106-106: pkg/app.go#L106
Added line #L106 was not covered by tests


[warning] 110-113: pkg/app.go#L110-L113
Added lines #L110 - L113 were not covered by tests

Additional comments not posted (17)
pkg/generators/rewards.go (1)

16-17: Constructor function implementation looks good.

The constructor function NewRewardsGenerator correctly initializes the RewardsGenerator with the provided chains. This is a straightforward and clean implementation.

pkg/generators/self_delegation.go (1)

16-17: Constructor function implementation is correct.

The constructor for SelfDelegationGenerator is implemented correctly, initializing the struct with the provided chains. This setup is consistent with other generator classes in the module.

pkg/generators/commission.go (1)

16-17: Constructor function is implemented correctly.

The NewCommissionGenerator constructor is correctly set up to initialize the CommissionGenerator with the provided chains. This consistency across generator constructors is good to see.

pkg/generators/rewards_test.go (2)

41-53: Review of chains slice setup in test cases.

The setup of the chains slice in the test cases is done correctly. It reflects the new structure expected by the RewardsGenerator. This setup is crucial for testing the generator with different chain configurations.


60-68: Review of assertions in test cases.

The assertions in the test cases are well-structured. They correctly use the InEpsilon method to account for floating point precision issues, which is important when dealing with financial calculations.

pkg/generators/commission_test.go (2)

21-21: LGTM!

The changes correctly reflect the updated NewCommissionGenerator function signature to accommodate chain configurations.


54-54: LGTM!

The generator is correctly initialized with a non-empty list of chains, and the results are appropriately asserted.

pkg/generators/self_delegations_test.go (2)

21-21: LGTM!

The changes correctly reflect the updated NewSelfDelegationGenerator function signature to accommodate chain configurations.


56-56: LGTM!

The generator is correctly initialized with a non-empty list of chains, and the results are appropriately asserted.

pkg/fetchers/price.go (1)

78-78: LGTM!

The update to use DisplayDenom instead of Denom for currency rates mapping is correctly implemented and aligns with the changes to the data model.

pkg/generators/validators_info.go (2)

20-20: LGTM!

The NewValidatorsInfoGenerator function is correctly updated to take a list of chains as a parameter, aligning with the new architecture requirements.


Line range hint 54-83: LGTM!

The Generate method correctly handles chain-specific data and uses the new Convert method for denomination conversions, ensuring data consistency across different chain configurations.

pkg/generators/validators_info_test.go (3)

22-22: Refactor: Update NewValidatorsInfoGenerator initialization to use chain configurations

The updated test cases correctly initialize NewValidatorsInfoGenerator with the new chain configurations. This change is consistent across multiple test functions, ensuring that the generator's behavior is tested against the intended configurations.

Also applies to: 32-32, 65-65, 104-104


67-69: Refactor: Chain configuration and assertions updated

The addition of detailed chain configurations and the update of assertions to include the "denom": "atom" label are well-integrated. These changes ensure that the tests are aligned with the new chain-specific logic in the generator.
[APROVED]

Also applies to: 84-84


46-46: Adjustment: Updated DelegatorShares values in test validators

The DelegatorShares values for validators have been updated to new values. It's important to verify that these values are consistent with expected test scenarios and reflect realistic test conditions.

Also applies to: 51-51, 55-55

pkg/fetchers/price_test.go (2)

54-54: Refactor: Updated Denoms configuration in price fetcher tests

The tests have been updated to reflect the new Denoms configuration, which includes a DisplayDenom field. This change is crucial for ensuring that the price fetcher correctly handles the new denomination display names.

Also applies to: 92-92, 135-135


115-115: Validation: Correct handling of denomination data in price fetcher

The assertions for denomData correctly check the fetched price data against the expected values. This ensures that the price fetcher is accurately processing and returning the correct price information for the specified denominations.

Also applies to: 159-159

pkg/app.go Show resolved Hide resolved
Comment on lines +36 to +54
for _, chain := range g.Chains {
chainRewards, ok := data.Rewards[chain.Name]
if !ok {
continue
}

for _, validator := range chain.Validators {
validatorRewards, ok := chainRewards[validator.Address]
if !ok {
continue
}

for _, balance := range validatorRewards {
amountConverted := chain.Denoms.Convert(&balance)
selfDelegationRewardsTokens.With(prometheus.Labels{
"chain": chain,
"address": validator,
"denom": balance.Denom,
}).Set(balance.Amount)
"chain": chain.Name,
"address": validator.Address,
"denom": amountConverted.Denom,
}).Set(amountConverted.Amount)
Copy link
Contributor

@coderabbitai coderabbitai bot Jun 24, 2024

Choose a reason for hiding this comment

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

Review of loop logic in Generate method.

The nested loops handle the chain-specific rewards data correctly. However, consider adding error handling or logging when the ok check fails, as silently continuing might obscure data issues.

+ if !ok {
+   log.Printf("No rewards data available for chain %s", chain.Name)
+   continue
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for _, chain := range g.Chains {
chainRewards, ok := data.Rewards[chain.Name]
if !ok {
continue
}
for _, validator := range chain.Validators {
validatorRewards, ok := chainRewards[validator.Address]
if !ok {
continue
}
for _, balance := range validatorRewards {
amountConverted := chain.Denoms.Convert(&balance)
selfDelegationRewardsTokens.With(prometheus.Labels{
"chain": chain,
"address": validator,
"denom": balance.Denom,
}).Set(balance.Amount)
"chain": chain.Name,
"address": validator.Address,
"denom": amountConverted.Denom,
}).Set(amountConverted.Amount)
for _, chain := range g.Chains {
chainRewards, ok := data.Rewards[chain.Name]
if !ok {
log.Printf("No rewards data available for chain %s", chain.Name)
continue
}
for _, validator := range chain.Validators {
validatorRewards, ok := chainRewards[validator.Address]
if !ok {
continue
}
for _, balance := range validatorRewards {
amountConverted := chain.Denoms.Convert(&balance)
selfDelegationRewardsTokens.With(prometheus.Labels{
"chain": chain.Name,
"address": validator.Address,
"denom": amountConverted.Denom,
}).Set(amountConverted.Amount)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can have this if the query for commission is disabled and this is not an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

No description provided.

pkg/generators/self_delegation.go Show resolved Hide resolved
pkg/generators/commission.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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 11a2fe4 and 3047015.

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

98-98: Addition of 'denom' label in delegationsGauge metrics is consistent with PR objectives.

This change aligns with the overall objective of enhancing the flexibility of the generators by incorporating chain-specific configurations. The addition of the 'denom' label allows more detailed metric tracking per denomination.

pkg/generators/single_validator_info_test.go (3)

78-79: Proper configuration and initialization of DenomInfos in tests.

The test setup correctly initializes DenomInfos with appropriate values, which is crucial for ensuring that the conversion of denominations is tested properly. This reflects the changes made in the main codebase and helps maintain consistency between implementation and testing.


88-93: Comprehensive testing of validator statuses and properties.

These tests effectively cover various scenarios, including different validator statuses and commission rates. It's good to see that the tests are thorough, covering multiple aspects of the validator information. This is essential for ensuring that the generator behaves as expected across different conditions.
[APROVED]

Also applies to: 112-112


176-176: Correct denomination in test assertions.

The test correctly asserts the expected denomination ('atom') after conversion. This ensures that the Convert method is functioning as intended and that the metrics are being recorded with the correct denominations.

pkg/generators/single_validator_info.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 3047015 and 35e6951.

Files selected for processing (11)
  • config.example.toml (3 hunks)
  • pkg/app.go (1 hunks)
  • pkg/config/denom_info.go (3 hunks)
  • pkg/generators/active_set_tokens.go (2 hunks)
  • pkg/generators/active_set_tokens_test.go (3 hunks)
  • pkg/generators/balance_test.go (3 hunks)
  • pkg/generators/commission_test.go (3 hunks)
  • pkg/generators/rewards_test.go (3 hunks)
  • pkg/generators/self_delegations_test.go (3 hunks)
  • pkg/generators/single_validator_info_test.go (4 hunks)
  • pkg/generators/validators_info_test.go (7 hunks)
Files skipped from review as they are similar to previous changes (8)
  • pkg/app.go
  • pkg/config/denom_info.go
  • pkg/generators/balance_test.go
  • pkg/generators/commission_test.go
  • pkg/generators/rewards_test.go
  • pkg/generators/self_delegations_test.go
  • pkg/generators/single_validator_info_test.go
  • pkg/generators/validators_info_test.go
Additional context used
Learnings (2)
pkg/generators/active_set_tokens.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.
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 (5)
pkg/generators/active_set_tokens.go (2)

42-42: Extended metric labels to include 'denom'

The addition of the "denom" label to the Prometheus metric definition is consistent with the PR's objectives to enhance denomination tracking. This change allows for more granular monitoring and is a good use of Prometheus's capabilities.


65-74: Logic for denomination conversion and metric setting

The changes to convert the last validator's stake using the DenomInfos.Convert method and set the metric values accordingly are well-implemented. This ensures that the metrics reflect the denominations accurately. Make sure that the Convert method handles edge cases and errors robustly.

pkg/generators/active_set_tokens_test.go (2)

Line range hint 76-108: Updated test setup with detailed chain and denomination information

The modifications in the test setup to include detailed chain and denomination information are crucial for ensuring the generator's functionality with the new denomination features. The use of realistic data in DelegatorShares enhances the test's reliability. Ensure that all edge cases for denomination conversion are covered in the tests.


Line range hint 115-147: Enhanced test setup for sufficient validators scenario

The test setup for scenarios with enough validators now includes updated DelegatorShares values and detailed denomination data, aligning with the changes in the main code. This ensures that the tests are comprehensive and reflect the operational conditions accurately.

config.example.toml (1)

Line range hint 2-125: Comprehensive update to configuration settings

The updates to the configuration file are comprehensive and align well with the new features introduced in the codebase. The detailed settings for denominations, including base and display denominations, are particularly noteworthy. These changes will facilitate more accurate and customizable metric generation based on the chain-specific settings.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 35e6951 and ae6c5a3.

Files selected for processing (7)
  • pkg/config/chain.go (3 hunks)
  • pkg/config/chain_test.go (5 hunks)
  • pkg/config/config_test.go (3 hunks)
  • pkg/config/consumer_chain.go (2 hunks)
  • pkg/config/consumer_chain_test.go (2 hunks)
  • pkg/fetchers/signing_info.go (1 hunks)
  • pkg/fetchers/signing_info_test.go (5 hunks)
Additional comments not posted (11)
pkg/config/consumer_chain_test.go (1)

48-54: Ensure error handling for missing BaseDenom in ConsumerChain.

The addition of this test case is crucial as it verifies the new validation logic ensuring that BaseDenom is set, aligning with the enhanced configuration requirements.

pkg/config/consumer_chain.go (2)

45-47: Added validation for BaseDenom.

This change is essential for ensuring that all consumer chains have a base denomination set, which is crucial for operations that depend on currency values. This aligns with the new configuration requirements.


58-83: Enhanced warning generation for missing prefixes.

The added warnings for missing BechWalletPrefix, BechValidatorPrefix, and BechConsensusPrefix are important for alerting users about potential configuration issues that could affect the application's functionality. This proactive error handling is a good practice.

pkg/config/chain.go (2)

48-50: Validate presence of BaseDenom.

This validation is crucial for ensuring that the base denomination is set for each chain, which is necessary for financial calculations and operations within the application.


Line range hint 76-94: Comprehensive warning management for chains.

The modifications to include warnings for missing BechWalletPrefix and the addition of iterating over ConsumerChains to gather their warnings ensure that all potential configuration issues are flagged. This is a robust approach to handling configuration validation.

pkg/config/config_test.go (2)

49-49: Validate configuration with BaseDenom.

The test ensures that the configuration is valid when BaseDenom is set, which is crucial for the application's operations that depend on currency values.


65-65: Check for warnings related to BaseDenom and BechWalletPrefix.

The tests for warnings when BaseDenom and BechWalletPrefix are set are important to ensure that the application alerts users about potential configuration issues. It's good to see that these aspects are being thoroughly tested.

Also applies to: 79-83

pkg/config/chain_test.go (1)

48-54: Comprehensive testing of Chain validation and warning generation.

The tests cover various scenarios including missing BaseDenom, invalid validators, and consumer chains. This ensures that the Chain struct's validation logic is robust and can handle different configuration errors effectively.

Also applies to: 62-62, 75-75, 89-89, 104-104, 118-119, 143-151, 158-163

pkg/fetchers/signing_info.go (1)

148-148: Ensure proper handling when Bech prefixes are missing.

The condition if chain.BechConsensusPrefix == "" || chain.BechValidatorPrefix == "" correctly prevents further operations if required Bech prefixes are not set, which is a good practice for robust error handling.

pkg/fetchers/signing_info_test.go (2)

344-344: Consistent use of BechValidatorPrefix in test setups.

The addition of BechValidatorPrefix in the test setups for consumer chains is consistent across multiple test cases. This consistency is crucial for ensuring that the tests accurately reflect the expected real-world usage of the application.

Also applies to: 401-401, 449-449


369-369: Verify the handling of empty data in error scenarios.

The tests TestSigningInfoFetcherConsumerAssignedKeyQueryError and TestSigningInfoFetcherConsumerAssignedKeyNodeError are designed to handle error scenarios properly by ensuring that no data is populated when an error occurs. This is a good practice to prevent corrupt or partial data from being used.

Also applies to: 426-426

pkg/config/consumer_chain_test.go Show resolved Hide resolved
@freak12techno freak12techno merged commit 9645d34 into main Jun 25, 2024
8 checks passed
@freak12techno freak12techno deleted the refactor-denoms branch June 25, 2024 22:30
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