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

Reinstate the TestAggregateIntentWithPRClaims #1320

Merged
merged 19 commits into from
Apr 8, 2024

Conversation

tuantran1702
Copy link
Contributor

@tuantran1702 tuantran1702 commented Mar 22, 2024

1. Summary

Fixes #1296

2.Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

3. Implementation details

4. How to test/use

5. Checklist

  • Does the Readme need to be updated?

6. Limitations (optional)

7. Future Work (optional)

Summary by CodeRabbit

  • Refactor
    • Enhanced test scenarios for intent aggregation in the interchain staking module.
    • Updated test functions to accurately represent functionalities related to validators and intents.
    • Adjusted variable declarations for improved test coverage.
    • Concealed internal details for confidentiality.

Copy link
Contributor

coderabbitai bot commented Mar 22, 2024

Walkthrough

The recent changes involve refactoring the test functions in intent_test.go within the interchain staking module. These modifications focus on enhancing intent aggregation with claims, updating function signatures, adjusting variable declarations, and improving test scenarios for more comprehensive coverage and reliability.

Changes

File Path Change Summary
.../interchainstaking/keeper/intent_test.go Refactored test functions for aggregating intents with claims, updated function signatures and variable declarations.

Assessment against linked issues

Objective Addressed Explanation
Reinstate TestAggregateIntentWithPRClaims (#1296)
Combine TestAggregateIntentWith TestAggregateIntentWithPRClaims for full coverage (#1296)

Poem

Among the code's twists and turns so fine,
A rabbit danced, tests to refine.
🐇 With each test, a leap of grace,
Ensuring code's solid embrace.

"Enhance, refine," the rabbit's song,
Through the code it hopped along.
🌟 In the digital realm, under the coding moon's light,
The rabbit's touch made the code shine bright.

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.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • 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

vercel bot commented Mar 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quicksilver ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 8, 2024 4:34pm

Copy link

codecov bot commented Mar 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.68%. Comparing base (1683da8) to head (ddb0413).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1320      +/-   ##
==========================================
+ Coverage   63.60%   63.68%   +0.08%     
==========================================
  Files         171      171              
  Lines       11652    11652              
==========================================
+ Hits         7411     7421      +10     
+ Misses       3497     3488       -9     
+ Partials      744      743       -1     
Flag Coverage Δ
unittests 63.68% <ø> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1 file with indirect coverage changes

},
&types.Validator{
ValoperAddress: "cosmosvaloper156gqf9837u7d4c4678yt3rl4ls9c5vuursrrzf",
/*

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note test

Suspicious 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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 60e77b3 and a7010fa.
Files selected for processing (2)
  • x/interchainstaking/keeper/intent_test.go (3 hunks)
  • x/interchainstaking/keeper/zones_test.go (3 hunks)
Additional comments: 5
x/interchainstaking/keeper/zones_test.go (2)
  • 341-391: The function TestZone_GetBondedValidatorAddressesAsSlice is entirely commented out. While there's a previous bot comment regarding a TODO in the source code, it's essential to address or remove commented-out code sections to maintain codebase cleanliness and readability. If this test is no longer relevant, consider removing it entirely or updating it to reflect the current codebase state.
  • 434-445: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [392-465]

The addition of TestZone_GetAggregateIntentOrDefault is a positive step towards enhancing test coverage for intent aggregation. To further improve the robustness of this test, consider adding more scenarios and edge cases, such as handling empty validator lists or validators with zero voting power.

x/interchainstaking/keeper/intent_test.go (3)
  • 138-138: The use of a hardcoded value 7313913 for setting up test balances might limit the flexibility and readability of the test. Consider defining this as a constant at the top of your test file or within the test function itself, with a descriptive name that explains its purpose or origin. This approach enhances maintainability and readability.
  • 360-484: This test case, TestAggregateIntentWithPRClaims, introduces scenarios that combine intents, balances, and claims to test the aggregation logic. However, there are a few areas that could be improved for clarity and maintainability:
  1. The test cases use hardcoded values for balances and claims. Similar to the previous comment, consider using named constants for these values to improve readability and maintainability.
  2. The comments within the test cases, such as "four delegators each at 25%", could be expanded to explain the rationale behind the test scenario more clearly. This would help future maintainers understand the purpose of each test case more quickly.
  3. The use of Sort() in the expected function closures is a good practice for ensuring consistent ordering, but it's worth noting in a comment that the order is significant for the comparison to succeed, as this might not be immediately obvious to someone new to the codebase.

Overall, these tests are well-structured and provide good coverage of the functionality being tested. Enhancing the clarity and maintainability of the test cases as suggested would make them even more valuable.

  • 486-640: The functions TestDefaultIntent, TestDefaultIntentWithJailed, TestDefaultIntentWithTombstoned, TestDefaultIntentWithCommission100, and TestDefaultIntentWithOneUnbondedOneUnbonding provide comprehensive coverage for various scenarios involving default intent calculation. A few observations and suggestions:
  1. The repeated setup code for creating a zone and setting validators could be refactored into a helper function to reduce duplication and improve readability. This would make each test function more focused on the specific scenario it's testing.
  2. The assertions for the expected weights in the validators' intents are clear and straightforward. However, adding brief comments explaining why certain weights are expected in each scenario could help future maintainers understand the test logic more quickly.
  3. The handling of different validator statuses (e.g., jailed, tombstoned, unbonded, unbonding) is well-tested, which is crucial for ensuring the robustness of the default intent calculation logic.

Refactoring to reduce code duplication and adding explanatory comments would further improve the quality of these tests.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a7010fa and ca6a43c.
Files selected for processing (1)
  • x/interchainstaking/keeper/intent_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/interchainstaking/keeper/intent_test.go

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ca6a43c and 74609c2.
Files selected for processing (1)
  • x/interchainstaking/keeper/intent_test.go (3 hunks)
Files not summarized due to errors (1)
  • x/interchainstaking/keeper/intent_test.go: Error: Message exceeds token limit
Additional comments: 2
x/interchainstaking/keeper/intent_test.go (2)
  • 360-531: The test cases in TestAggregateIntentWithPRClaims are well-structured and cover a variety of scenarios, including single and multiple intents and claims, with different supply percentages. However, there's a potential improvement in the clarity of test case names and the documentation of the logic behind expected outcomes. Specifically, for complex scenarios like "two multi-val intents, two claims, 50% supply," it would be beneficial to add comments explaining how the expected weights are calculated to aid in understanding the test's intent and ensuring its correctness.

Consider adding detailed comments within each test case, especially for the expected function, to explain the rationale behind the expected outcomes. This will improve maintainability and ease future modifications or debugging.

  • 587-709: The TestDefaultIntent and related tests (TestDefaultIntentWithJailed, TestDefaultIntentWithTombstoned, TestDefaultIntentWithCommission100, TestDefaultIntentWithOneUnbondedOneUnbonding) effectively cover various scenarios affecting the default intent aggregation. It's important to ensure that these tests accurately reflect the intended behavior of the system, especially in edge cases like handling jailed or tombstoned validators, and validators with different bonding statuses.

These tests are comprehensive and cover a wide range of scenarios. Ensure that the logic for handling different validator statuses remains consistent with the overall design and requirements of the interchainstaking module.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 74609c2 and e3bfe64.
Files selected for processing (1)
  • x/interchainstaking/keeper/intent_test.go (3 hunks)
Files not summarized due to errors (1)
  • x/interchainstaking/keeper/intent_test.go: Error: Message exceeds token limit
Additional comments (5)
x/interchainstaking/keeper/intent_test.go (5)
  • 587-616: In TestDefaultIntent, the test verifies that the default aggregate intents are calculated correctly, expecting each validator to have a weight of 0.2 (20%). The logic and assertions appear correct and align with the expected behavior of evenly distributing weights among validators when no specific intents are set. This test effectively ensures the fallback mechanism to default intents works as intended.
  • 618-647: In TestDefaultIntentWithJailed, the test correctly handles the scenario where a validator is jailed, ensuring they are excluded from the default aggregate intents calculation. This is crucial for maintaining the integrity of the staking process, as jailed validators should not receive delegations. The test's logic and assertions are appropriate and validate the expected behavior accurately.
  • 649-678: TestDefaultIntentWithTombstoned effectively tests the scenario where a validator is tombstoned, ensuring they are excluded from the default aggregate intents calculation. This aligns with the expected behavior, as tombstoned validators, similar to jailed ones, should not receive delegations. The test's logic and assertions are correct, ensuring the system's integrity in handling validator statuses.
  • 680-709: In TestDefaultIntentWithCommission100, the test scenario where a validator has a 100% commission rate is correctly handled, ensuring they are excluded from the default aggregate intents calculation. This scenario is important for ensuring that validators with unrealistic commission rates do not unfairly influence the default intent calculation. The test's logic and assertions are appropriate and validate the expected behavior accurately.
  • 711-741: TestDefaultIntentWithOneUnbondedOneUnbonding accurately tests the scenario where validators are in unbonded and unbonding states, ensuring they are excluded from the default aggregate intents calculation. This is crucial for the staking process, as validators not in an active bonded state should not receive delegations. The test's logic and assertions correctly validate the expected behavior, ensuring the system's integrity in handling various validator states.

x/interchainstaking/keeper/intent_test.go Outdated Show resolved Hide resolved
Comment on lines 396 to 398
user1.String(): {UserAddress: user1.String(), ChainId: zone.ChainId, Module: cmtypes.ClaimTypeLiquidToken, Amount: sdkmath.NewInt(1000), SourceChainId: "osmosis-1"},
user1.String(): {UserAddress: user1.String(), ChainId: zone.ChainId, Module: cmtypes.ClaimTypeLiquidToken, Amount: sdkmath.NewInt(1000), SourceChainId: "osmosis-1"},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Rabit flagged that only one claim is set here because they both use the same map index.

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 Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e3bfe64 and 1dfd35c.
Files selected for processing (1)
  • x/interchainstaking/keeper/intent_test.go (3 hunks)
Files not summarized due to errors (1)
  • x/interchainstaking/keeper/intent_test.go: Error: Message exceeds token limit
Additional Context Used
Additional comments not posted (2)
x/interchainstaking/keeper/intent_test.go (2)

360-588: The test cases in TestAggregateIntentWithPRClaims are comprehensive, covering various scenarios with single and multiple intents and claims. However, ensure that the test cases accurately reflect the intended scenarios, especially considering the previous comment about a duplicate map key in the claims setup. This could potentially lead to misleading test outcomes if not addressed.


590-744: The functions TestDefaultIntent, TestDefaultIntentWithJailed, TestDefaultIntentWithTombstoned, TestDefaultIntentWithCommission100, and TestDefaultIntentWithOneUnbondedOneUnbonding provide a good range of scenarios for testing default intent calculations under various conditions. It's crucial to ensure that these tests accurately simulate the conditions they're meant to test, such as the handling of jailed, tombstoned, unbonded, and unbonding validators, as well as those with a 100% commission rate. This will help ensure the robustness of the default intent calculation logic.

@joe-bowman
Copy link
Contributor

This pull request has been deployed to Vercel.

Latest commit: ddb0413
✅ Preview: https://pr-1320.app-dev.quicksilver.zone
🔍 Inspect: https://vercel.com/quicksilver/quicksilver/8Qm3MTGN53C2KEPNVwgG3xahoobv

View Workflow Logs

@joe-bowman joe-bowman enabled auto-merge (squash) April 8, 2024 16:44
@joe-bowman joe-bowman disabled auto-merge April 8, 2024 16:44
@joe-bowman joe-bowman merged commit cd70d49 into main Apr 8, 2024
26 checks passed
@joe-bowman joe-bowman deleted the tuan/reinstate-intent-test branch April 8, 2024 16:44
@faddat faddat mentioned this pull request Apr 11, 2024
5 tasks
faddat added a commit that referenced this pull request Apr 11, 2024
* fix undefined window error (#1396)

* chore(deps): bump github.com/cosmos/ibc-go/v5 from 5.3.2 to 5.4.0 (#1398)

Bumps [github.com/cosmos/ibc-go/v5](https://github.com/cosmos/ibc-go) from 5.3.2 to 5.4.0.
- [Release notes](https://github.com/cosmos/ibc-go/releases)
- [Changelog](https://github.com/cosmos/ibc-go/blob/v5.4.0/CHANGELOG.md)
- [Commits](cosmos/ibc-go@v5.3.2...v5.4.0)

---
updated-dependencies:
- dependency-name: github.com/cosmos/ibc-go/v5
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump golang.org/x/tools from 0.19.0 to 0.20.0 (#1392)

Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.19.0 to 0.20.0.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](golang/tools@v0.19.0...v0.20.0)

---
updated-dependencies:
- dependency-name: golang.org/x/tools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump google.golang.org/grpc from 1.62.1 to 1.63.0 (#1383)

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.62.1 to 1.63.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.62.1...v1.63.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Joe Bowman <[email protected]>

* use correct supply when determining proportions (#1389)

* use correct supply when determining proportions

* fix HandleMsgTransfer tests

---------

Co-authored-by: Tuan Tran <[email protected]>

* Reinstate the TestAggregateIntentWithPRClaims (#1320)

* fix(intent-test): fix the claim to match the supply

* refactor: enable some tests and convert them to keeper tests

* fix int64 to sdkmath.Int

* rename alias to sdkmath to avoid confusion

* fix claim to match supply

* remove balance

* add unclaimedRatio

* add multi claim, less than 100% supply

* add tests, write comment for reasoning expected output

* fix tests failing due to #1345

* fix test

---------

Co-authored-by: Jacob Gadikian <[email protected]>
Co-authored-by: Joe Bowman <[email protected]>

* fix: Withdrawal records should not exist with 0 burnAmount (#1284)

* add guard to ```AddWithdrawalRecord```  and ```SetWithdrawalRecord```

* fix tests missing BurnAmount field

* return error instead of panic for ```SetwithdrawalRecord```  and ```AddWithdrawalRecord```

* fix linting

* return error

* refactor to check for error

* add missing BurnAmount field in TestGetRatio

* refactor test

* add old function for testing upgrade handler

* add upgrade handler and test

* add Upgrade handler to testnet upgrades

* Update x/interchainstaking/keeper/withdrawal_record.go comment

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* add test for set withdrawal records

* refactor: remove old code from keeper

* linting

* linting

* resolve conflict, fix upgrade name

* linting

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Jacob Gadikian <[email protected]>
Co-authored-by: Joe Bowman <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Joseph Chalabi <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Joe Bowman <[email protected]>
Co-authored-by: Tuan Tran <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reinstate TestAggregateIntentWithPRClaims
3 participants