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

fix: initialize staking at genesis #290

Merged
merged 1 commit into from
Oct 31, 2024
Merged

Conversation

beer-1
Copy link
Contributor

@beer-1 beer-1 commented Oct 24, 2024

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@beer-1 beer-1 self-assigned this Oct 24, 2024
@beer-1 beer-1 requested a review from a team as a code owner October 24, 2024 06:03
Copy link

coderabbitai bot commented Oct 24, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request primarily involve modifications to the moveKeeper.Initialize method across various test files, adding a new parameter, bondDenom. This adjustment affects how the moveKeeper is initialized, ensuring that the bond denomination is incorporated into the setup process. Additionally, several test functions are updated to reflect these changes, particularly in how they handle coin minting and validator funding. The overall structure of the tests remains intact, focusing on enhancing the handling of the bond denomination.

Changes

File Path Change Summary
x/bank/keeper/common_test.go Updated moveKeeper.Initialize to include bondDenom. Modified initialTotalSupply and Mint methods.
x/distribution/keeper/common_test.go Updated moveKeeper.Initialize to include bondDenom.
x/gov/keeper/common_test.go Updated moveKeeper.Initialize to include bondDenom. Modified createValidatorWithCoin.
x/ibc-hooks/keeper/common_test.go Updated moveKeeper.Initialize to include bondDenom.
x/ibc-hooks/move-hooks/common_test.go Updated moveKeeper.Initialize to include bondDenom. Minor comment adjustments.
x/move/keeper/common_test.go Updated moveKeeper.Initialize to include bondDenom.
x/move/keeper/genesis.go Updated Initialize method to include baseDenom. Enhanced error handling in Initialize.
x/move/keeper/staking_test.go Added TestApplyStakingDeltas_BaseDenom. Modified existing test to handle a second bond denomination.
x/mstaking/keeper/common_test.go Updated moveKeeper.Initialize to include bondDenom. Modified createValidatorWithBalance.
x/reward/keeper/common_test.go Updated moveKeeper.Initialize to include bondDenom.
x/slashing/keeper/common_test.go Updated moveKeeper.Initialize to include bondDenom.

Possibly related PRs

  • Fix/distribution commission #217: The changes in this PR involve updates to the moveKeeper.Initialize method, which is also a focus in the main PR regarding the handling of the bond denomination.
  • feat: add vesting vote #234: This PR modifies the _createTestInput function to include a new parameter related to the moveKeeper, which aligns with the changes made in the main PR regarding the moveKeeper.Initialize method.
  • fix: audit fix #245: The changes in this PR include updates to the AllocateTokens function, which may relate to the overall handling of tokens and denominations, similar to the bond denomination changes in the main PR.
  • fix: audit #253: This PR includes modifications to the AllocateTokens function, which also deals with token allocation and may relate to the changes in handling denominations in the main PR.
  • feat: update slinky => connect/v2 #269: The updates in this PR involve changes to the moveKeeper and its associated functionalities, which may connect to the enhancements made in the main PR regarding the bond denomination.
  • feat: add submsg impl  #277: This PR introduces new functionality for handling Stargate messages, which may relate to the overall message handling and token interactions discussed in the main PR.

Suggested reviewers

  • sh-cha

Poem

In the meadow where bunnies roam,
The bondDenom finds its home.
With moveKeeper now set right,
Minting coins brings pure delight!
Hopping through tests, we cheer and play,
For a brighter, bouncier day! 🐇✨


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

Copy link

@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

🧹 Outside diff range and nitpick comments (3)
x/ibc-hooks/move-hooks/common_test.go (1)

312-312: Consider adding test cases with custom bond denominations.

To ensure robust testing of the staking initialization, consider adding test cases that use different bond denominations beyond the default one.

Example test setup:

func TestStakingInitializationWithCustomBondDenom(t *testing.T) {
    customBondDenom := "custom"
    ctx, keepers := createTestInput(t, false, true)
    // Verify initialization with custom bond denom
    // Add assertions here
}
x/slashing/keeper/common_test.go (1)

392-392: Consider adding specific test cases for genesis staking initialization

While the initialization change looks good, consider adding test cases that specifically verify the genesis staking initialization behavior with different bond denominations to ensure the fix works as intended.

Would you like me to help create test cases that verify the genesis staking initialization with different bond denominations?

x/move/keeper/staking_test.go (1)

250-270: Enhance error handling verification.

The error checks could be more thorough:

  1. Verify specific error messages for failure cases
  2. Consider using require.ErrorContains for more precise error checking
  3. Consider combining multiple error checks using a helper function

Example helper function:

func requireNoErrorf(t *testing.T, err error, format string, args ...interface{}) {
    t.Helper()
    if err != nil {
        t.Errorf(format+": %v", append(args, err)...)
    }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 342a327 and f4ddc27.

📒 Files selected for processing (11)
  • x/bank/keeper/common_test.go (1 hunks)
  • x/distribution/keeper/common_test.go (1 hunks)
  • x/gov/keeper/common_test.go (1 hunks)
  • x/ibc-hooks/keeper/common_test.go (1 hunks)
  • x/ibc-hooks/move-hooks/common_test.go (1 hunks)
  • x/move/keeper/common_test.go (1 hunks)
  • x/move/keeper/genesis.go (3 hunks)
  • x/move/keeper/staking_test.go (1 hunks)
  • x/mstaking/keeper/common_test.go (1 hunks)
  • x/reward/keeper/common_test.go (1 hunks)
  • x/slashing/keeper/common_test.go (1 hunks)
🔇 Additional comments (15)
x/move/keeper/genesis.go (4)

18-18: LGTM: Parameter addition aligns with PR objective.

The addition of baseDenom parameter is appropriate for initializing staking at genesis.


61-71: Verify initialization order dependency.

The code initializes move bank coin before move staking. Please verify that this order is required and documented.

Consider:

  1. Adding a comment explaining the required initialization order
  2. Documenting this dependency in the module's README or design docs

93-95: Verify genesis parameter handling.

The initialization is only performed when no modules exist (len(genState.GetModules()) == 0). Please verify:

  1. This is the intended behavior for staking initialization
  2. The params.BaseDenom is properly set in the genesis file
#!/bin/bash
# Search for genesis.json examples or tests that set BaseDenom
rg -g "*.json" -A 5 "BaseDenom"

57-59: Review duplicate error handling.

There are two calls to handleExecuteResponse - one at line 57 and another at line 73. The second call could potentially overwrite the error state from the staking initialization block. Consider consolidating the error handling.

Also applies to: 73-73

x/reward/keeper/common_test.go (1)

378-379: LGTM: Properly integrated bondDenom parameter

The addition of bondDenom parameter to moveKeeper.Initialize is well integrated with the test setup. The parameter is consistent with moveParams.BaseDenom and properly initialized for staking at genesis.

Let's verify the integration:

✅ Verification successful

Let me generate additional scripts to verify the BaseDenom consistency, as the previous search didn't capture the full context.


Let me try one more time with corrected paths and patterns:


Based on the search results, I can now generate the final response:

✅ Verified: bondDenom parameter is consistently integrated

The verification shows that:

  • The bondDenom parameter is consistently used across all test setups in different modules
  • In all cases, moveParams.BaseDenom is properly set to bondDenom before calling Initialize
  • The initialization sequence is consistent:
    1. Set moveParams.BaseDenom = bondDenom
    2. Set raw params via SetRawParams
    3. Load stdlib module bytes
    4. Call Initialize with correct parameters including bondDenom
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that bondDenom is consistently used across the codebase
# Test 1: Check if bondDenom is properly used in Initialize calls
rg -A 2 "Initialize.*bondDenom" 

# Test 2: Check if BaseDenom is consistently set to bondDenom before Initialize
rg -B 5 "Initialize.*bondDenom" | rg "BaseDenom.*bondDenom"

Length of output: 2009


Script:

#!/bin/bash
# Let's check the full context around Initialize calls to verify BaseDenom setup
# Using more context lines and a broader search pattern

# Check the context of Initialize calls in test files
rg -B 10 "Initialize.*bondDenom" common_test.go

# Specifically look for moveParams setup before Initialize
rg -B 10 "moveParams.*BaseDenom.*bondDenom" common_test.go

# Check the Initialize method signature to understand the expected parameters
ast-grep --pattern 'func $_Initialize($$$) {
  $$$
}'

Length of output: 276


Script:

#!/bin/bash
# Search for Initialize implementation
ast-grep --pattern 'func ($_ *Keeper) Initialize($$$) {
  $$$
}'

# Check the context of Initialize calls in test files, searching all directories
rg -B 10 "Initialize.*bondDenom" --type go

# Look for moveParams.BaseDenom setup
rg -B 5 "moveParams\.BaseDenom.*=.*bondDenom" --type go

Length of output: 9872

x/ibc-hooks/move-hooks/common_test.go (1)

312-312: LGTM! Verify test coverage for different bond denominations.

The addition of bondDenom parameter to moveKeeper.Initialize is correct and aligns with the PR objective of fixing staking initialization at genesis.

Let's verify the test coverage:

x/ibc-hooks/keeper/common_test.go (1)

399-399: LGTM: Consistent bond denomination initialization

The addition of bondDenom parameter to moveKeeper.Initialize is consistent with the staking configuration across other keepers and properly uses the defined constant.

x/bank/keeper/common_test.go (1)

397-397: LGTM: Proper initialization of moveKeeper with bondDenom

The addition of bondDenom parameter to moveKeeper.Initialize is correct and consistent with:

  • The PR's objective to fix staking initialization at genesis
  • The test setup where bondDenom is properly defined as a constant
  • Other related initialization like stakingParams and rewardParams which also use the same bondDenom
x/mstaking/keeper/common_test.go (1)

423-424: LGTM! Verify test coverage for staking initialization.

The addition of bondDenom parameter to moveKeeper.Initialize aligns with the PR objective of fixing staking initialization at genesis. Since this is a common test setup, it ensures all staking-related tests use the correct bond denomination.

Let's verify the test coverage for staking initialization:

✅ Verification successful

Let me gather more information to verify the test coverage comprehensively.


Based on the search results, I can now provide a comprehensive verification of the test coverage.

Test coverage for moveKeeper.Initialize with bondDenom is comprehensive

The search results show that:

  1. The Initialize method with bondDenom parameter is properly tested across multiple test suites:

    • x/mstaking/keeper/common_test.go
    • x/reward/keeper/common_test.go
    • x/slashing/keeper/common_test.go
    • x/distribution/keeper/common_test.go
    • x/gov/keeper/common_test.go
    • x/bank/keeper/common_test.go
    • x/ibc-hooks/keeper/common_test.go
  2. The initialization flow is also tested through:

    • Genesis initialization tests
    • Staking-specific initialization via InitializeStaking method
    • Integration with other modules' test setups

The change to add bondDenom parameter is well-covered across the test suite, ensuring the staking initialization works correctly with the proper bond denomination at genesis.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check test coverage for staking initialization
# Look for test cases that verify staking initialization with bond denomination

# Search for test functions related to staking initialization
rg -t go "func.*Test.*Init.*Staking" 

# Search for test assertions related to bond denomination
rg -t go "require.*bond.*denom" 

Length of output: 525


Script:

#!/bin/bash
# Search for Initialize method usage in test files
rg -t go "Initialize.*\(" -A 2

# Search for test functions that might be testing initialization
rg -t go "func.*Test.*Initialize" -A 5

# Look for genesis-related test functions since initialization happens at genesis
rg -t go "func.*Test.*Genesis" -A 5

# Search for moveKeeper initialization patterns
ast-grep --pattern 'moveKeeper.Initialize($$$)'

Length of output: 11605

x/gov/keeper/common_test.go (1)

409-409: LGTM: Consistent bond denomination initialization

The addition of bondDenom parameter to moveKeeper.Initialize aligns with the PR's objective of fixing staking initialization at genesis and maintains consistency with the bond denomination handling throughout the test setup.

x/slashing/keeper/common_test.go (1)

392-392: LGTM: Proper integration of bondDenom parameter

The initialization change correctly integrates the bondDenom parameter, maintaining consistency with other test files and properly handling errors.

x/distribution/keeper/common_test.go (3)

381-382: LGTM: Bond denomination properly initialized in move keeper.

The addition of bondDenom parameter to moveKeeper.Initialize aligns with the PR's objective of fixing staking initialization at genesis. The initialization is properly handled with error checking.


381-382: Verify test coverage for move keeper initialization.

The initialization of the move keeper with bond denomination is a critical change. Let's ensure there are adequate test cases covering this initialization.

#!/bin/bash
# Description: Check for test coverage of move keeper initialization
# Expected: Should find test cases specifically testing initialization with bond denomination

# Search for test cases related to move keeper initialization
rg -A 5 "func Test.*Initialize" 
ast-grep --pattern 'func Test$_($_) {
  $$$
  moveKeeper.Initialize($$$)
  $$$
}'

Also applies to: 171-175


381-382: Verify bond denomination consistency across the test setup.

The bond denomination is defined as a constant and used consistently in the initialization. Let's verify its usage across the codebase to ensure consistent initialization.

Also applies to: 67-68

✅ Verification successful

Let me gather more specific information about the bond denomination usage.

This will help us verify the consistency of bond denomination usage in the test setup and across the codebase.


Let me generate the final response based on the gathered information.

Bond denomination is consistently defined and used across test files

The verification shows that:

  • The bondDenom constant in x/distribution/keeper/common_test.go is correctly defined using initiaapp.BondDenom
  • The bond denomination is consistently used in the Initialize call
  • The same bond denomination constant is used consistently across various test files in different modules (distribution, gov, bank, ibc-hooks, etc.)
  • The bond denomination is properly set in staking parameters across all test setups
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of bond denomination in test files
# Expected: All test files should use the same bond denomination constant

# Search for bond denomination definitions and usage in test files
rg -l "bondDenom.*=.*initiaapp\.BondDenom" 
rg -l "\.Initialize\(.*bondDenom\)"

Length of output: 505


Script:

#!/bin/bash
# Search for bond denomination definition and usage in test files
rg -A 3 "bondDenom.*:?=.*" x/distribution/keeper/common_test.go
rg -A 3 "Initialize.*bondDenom" x/distribution/keeper/common_test.go

# Search for other test files that might be using Initialize with bond denomination
rg -A 3 "Initialize.*bondDenom" "**/*_test.go"

# Look for bond denomination constant definitions
rg -A 1 "BondDenom.*=.*" 

Length of output: 8504

x/move/keeper/common_test.go (1)

422-422: LGTM! Verify integration with staking parameters.

The addition of bondDenom parameter to moveKeeper.Initialize aligns with the PR objective of fixing staking initialization at genesis. The parameter is properly sourced from the constant and matches the staking parameters set earlier in the test setup.

✅ Verification successful

The shell script results show that:

  1. The bondDenom parameter is consistently used across all test files for staking parameters configuration via stakingParams.BondDenoms = []string{bondDenom}
  2. The moveKeeper.Initialize method is called with the bondDenom parameter consistently across all test files in various modules (bank, gov, distribution, ibc-hooks, move, mstaking, slashing, reward)

This verifies that the integration is consistent across the codebase, and the change aligns with the staking initialization patterns used in other modules.

Integration verified - bondDenom parameter consistently used

The addition of bondDenom parameter to moveKeeper.Initialize is properly integrated across all test files. The parameter is consistently sourced from the same constant and aligns with the staking parameters configuration, ensuring uniform bond denomination handling across modules.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that the bondDenom is consistently used across staking initialization
# and parameters

# Check staking parameters configuration
rg -A 5 "stakingParams.*BondDenoms.*bondDenom"

# Check move keeper initialization with bondDenom
rg -A 5 "moveKeeper.*Initialize.*bondDenom"

Length of output: 7405

x/move/keeper/staking_test.go Show resolved Hide resolved
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 9.09091% with 10 lines in your changes missing coverage. Please review.

Project coverage is 40.82%. Comparing base (342a327) to head (f4ddc27).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
x/move/keeper/genesis.go 9.09% 7 Missing and 3 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #290      +/-   ##
==========================================
- Coverage   40.83%   40.82%   -0.02%     
==========================================
  Files         270      270              
  Lines       25779    25789      +10     
==========================================
+ Hits        10528    10529       +1     
- Misses      13626    13632       +6     
- Partials     1625     1628       +3     
Files with missing lines Coverage Δ
x/move/keeper/genesis.go 15.75% <9.09%> (-0.43%) ⬇️

... and 1 file with indirect coverage changes

Copy link
Contributor

@Vritra4 Vritra4 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@sh-cha sh-cha left a comment

Choose a reason for hiding this comment

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

LGTM

@beer-1 beer-1 merged commit 53170d0 into main Oct 31, 2024
10 of 11 checks passed
@beer-1 beer-1 deleted the fix/initialize-staking-at-genesis branch October 31, 2024 06:43
beer-1 added a commit that referenced this pull request Oct 31, 2024
@coderabbitai coderabbitai bot mentioned this pull request Oct 31, 2024
11 tasks
beer-1 added a commit that referenced this pull request Oct 31, 2024
* prepare upgrade initiation-2

* fetching code bytes with precompile readlib func

* delete existing upgrade handler

* dont delete if it is module

* add cosmos move

* add get&set checksums, genesis import&export module checksums

* change checksum func

* initialize staking at genesis (#290)

* movevm loaderv2 integration (#284)

* connect movevm with loaderv2 and introduce module & script cache

* use cache context before query

* disable unstable

* update movevm to latest

* add toml description

---------

Co-authored-by: beer-1 <[email protected]>

* wip

* delete keys after iteration

* clone key value

* fix

* reverse iterate vmstore & set keys

* final touch

* update swagger docs

---------

Co-authored-by: beer-1 <[email protected]>
Co-authored-by: beer-1 <[email protected]>
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.

3 participants