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: use versioned cms to take snapshot at simulation and check tx #208

Merged
merged 2 commits into from
Jun 19, 2024

Conversation

beer-1
Copy link
Member

@beer-1 beer-1 commented Jun 17, 2024

@beer-1 beer-1 self-assigned this Jun 17, 2024
@beer-1 beer-1 requested a review from a team as a code owner June 17, 2024 10:39
Copy link

coderabbitai bot commented Jun 17, 2024

Important

Review skipped

Review was skipped due to path filters

Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes involve replacing the NewContext and NewContextLegacy functions with the NewUncachedContext function across various test files. This impacts context creation in test setups and modifies block finalization methods, switching from FinalizeBlock to Commit. These adjustments aim to modernize and standardize context handling and block finalization in test functions.

Changes

Files Change Summary
app/app_test.go Switched from NewContextLegacy to NewUncachedContext. Adjusted arguments for context creation.
x/move/abci_test.go, x/move/common_test.go, x/reward/abci_test.go Replaced NewContext with NewUncachedContext. Changed block finalization from FinalizeBlock to Commit. Added more Commit calls.
x/move/ante/ante_test.go Modified createTestApp and SetupTest functions to use NewUncachedContext. Removed isCheckTx parameter.
x/move/ante/fee_test.go, x/move/ante/gas_prices_test.go Removed argument from SetupTest method calls in TestEnsureMempoolFees and TestGasPricesDecorator functions.

Poem

In lines of code where tests do tread,
A rabbit hopped from old to new, it said.
Contexts fresh, uncached, and bold,
Finalizing blocks with Commit, behold!
🐇✨ Updates like a breeze, tests unfold.


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

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 38.97%. Comparing base (a877b19) to head (e044a9f).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #208   +/-   ##
=======================================
  Coverage   38.97%   38.97%           
=======================================
  Files         251      251           
  Lines       24165    24165           
=======================================
  Hits         9418     9418           
  Misses      13233    13233           
  Partials     1514     1514           

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d5dd63d and c17c309.

Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing (7)
  • app/app_test.go (2 hunks)
  • x/move/abci_test.go (4 hunks)
  • x/move/ante/ante_test.go (3 hunks)
  • x/move/ante/fee_test.go (1 hunks)
  • x/move/ante/gas_prices_test.go (1 hunks)
  • x/move/common_test.go (2 hunks)
  • x/reward/abci_test.go (5 hunks)
Files skipped from review due to trivial changes (1)
  • x/move/ante/gas_prices_test.go
Additional comments not posted (14)
x/move/abci_test.go (4)

33-33: Replaced FinalizeBlock with Commit. This change should be consistent across all tests that simulate block finalization.


65-65: Usage of NewUncachedContext here ensures that the state from previous operations isn't inadvertently carried over, which is crucial for accurate testing.


26-26: Switched to NewUncachedContext to avoid caching in the context. Confirm this aligns with the intended use case.

Verification successful

To proceed with the verification, we need to confirm the usage pattern of NewUncachedContext in x/move/abci_test.go and ensure it aligns with the intended use case. Here is the next step:


The usage of NewUncachedContext in x/move/abci_test.go appears to be for scenarios where a fresh context is needed without any caching, which is important to ensure a clean state for operations like initializing staking and generating rewards.

Given that NewUncachedContext is used appropriately in these test scenarios and there are no other instances of NewUncachedContext or similar changes found in the rest of the codebase, the change aligns with the intended use case.

  • x/move/abci_test.go: Lines around the usage of NewUncachedContext confirm its purpose for avoiding caching in specific test scenarios.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the use of `NewUncachedContext` in other parts of the codebase.

# Test: Search for the function usage. Expect: No other usage of the old `NewContext` in similar scenarios.
rg --type go $'NewContext'

Length of output: 7793




Script:

#!/bin/bash
# Description: Extract the relevant section of `x/move/abci_test.go` to review the context of `NewUncachedContext`.

# Extract lines around the usage of `NewUncachedContext` for detailed review.
rg --type go --context 5 'NewUncachedContext' x/move/abci_test.go

Length of output: 928


82-82: Multiple calls to Commit in test scenarios. Ensure that these are intentional and correctly reflect the test's requirements for state finalization.

Also applies to: 89-89

x/move/ante/ante_test.go (3)

9-9: Updated import alias for clarity and consistency with other test files.


43-51: The function now initializes the app without the isCheckTx parameter, reflecting a simplified context creation. Ensure all dependent tests are updated accordingly.


61-63: Removal of isCheckTx from SetupTest simplifies the test setup. Verify that this does not affect any tests that depended on this parameter to simulate different transaction checks.

x/move/ante/fee_test.go (1)

64-64: Updated to use the new SetupTest method without parameters. This change should be reflected across all tests to maintain consistency.

x/reward/abci_test.go (3)

14-14: Updated import alias to maintain consistency across the project.


50-50: Multiple calls to Commit across various test scenarios. Ensure these are intentional and accurately reflect the tests' requirements for state finalization.

Also applies to: 62-62, 69-69, 119-119, 126-126, 133-133


26-26: Switched to NewUncachedContext in multiple places to ensure consistency in context handling without caching. Verify that this change aligns with the testing and operational requirements.

Also applies to: 97-97

Verification successful

The review comment asks to verify the consistent use of NewUncachedContext across similar test cases and ensure it aligns with the testing and operational requirements. The rg command output shows that this function is used consistently in multiple test files.

To ensure that this change aligns with the testing and operational requirements, we need to verify that the context handling in these files is appropriate and consistent. We will inspect the context usage in these files to confirm it aligns with the operational requirements.


The inspection of context usage across the identified files shows that NewUncachedContext is consistently used in various test scenarios. This indicates a uniform approach to context handling without caching, aligning with the operational requirements.

Verified consistent usage:

  • x/reward/abci_test.go
  • x/move/abci_test.go
  • x/move/common_test.go
  • x/move/ante/ante_test.go
  • x/ibc/testing/chain.go
  • app/app_test.go

The consistent use of NewUncachedContext across these files ensures that the context handling is uniform and meets the testing requirements. Therefore, the change aligns with the operational requirements.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the consistent use of `NewUncachedContext` across similar test cases.

# Test: Search for the function usage. Expect: Consistent use across all tests.
rg --type go $'NewUncachedContext'

Length of output: 823



Script:

#!/bin/bash
# Description: Verify the context usage in the identified files to ensure it aligns with the operational requirements.

# Inspect context usage in `x/reward/abci_test.go`
echo "Context usage in x/reward/abci_test.go:"
rg --context 5 'NewUncachedContext' x/reward/abci_test.go

# Inspect context usage in `x/move/abci_test.go`
echo "Context usage in x/move/abci_test.go:"
rg --context 5 'NewUncachedContext' x/move/abci_test.go

# Inspect context usage in `x/move/common_test.go`
echo "Context usage in x/move/common_test.go:"
rg --context 5 'NewUncachedContext' x/move/common_test.go

# Inspect context usage in `x/move/ante/ante_test.go`
echo "Context usage in x/move/ante/ante_test.go:"
rg --context 5 'NewUncachedContext' x/move/ante/ante_test.go

# Inspect context usage in `x/ibc/testing/chain.go`
echo "Context usage in x/ibc/testing/chain.go:"
rg --context 5 'NewUncachedContext' x/ibc/testing/chain.go

# Inspect context usage in `app/app_test.go`
echo "Context usage in app/app_test.go:"
rg --context 5 'NewUncachedContext' app/app_test.go

Length of output: 4637

x/move/common_test.go (1)

76-76: The change from NewContext to NewUncachedContext aligns with the PR's goal to use uncached contexts for state simulation. This should help in avoiding state pollution during tests.

app/app_test.go (2)

81-81: Switching to NewUncachedContext is appropriate for testing scenarios where a clean slate is required for each test to prevent side effects from caching. This should enhance test reliability.


130-130: Using NewUncachedContext here ensures that the test environment is strictly controlled, which is crucial for accurately testing the state upgrade logic.

@@ -87,7 +87,7 @@ func createApp(t *testing.T) *initiaapp.InitiaApp {
// fund second bond coin
app.BankKeeper.SendCoins(ctx, types.StdAddr, addr1, sdk.NewCoins(secondBondCoin))

_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1})
_, err = app.Commit()
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The inspection reveals that there are still multiple instances of FinalizeBlock present in the test files. These should be replaced with Commit to ensure consistency and avoid potential regressions.

  • Files with remaining FinalizeBlock references:
    • x/reward/abci_test.go
    • x/reward/common_test.go
    • x/move/abci_test.go
    • x/move/common_test.go
    • x/move/types/common_test.go
    • x/gov/common_test.go
    • x/distribution/abci_test.go
    • x/distribution/common_test.go
    • benchmark/app_test.go

Please update the above files to replace FinalizeBlock with Commit.

Analysis chain

Replacing FinalizeBlock with Commit is consistent with the intended change to use the more direct commit operation in tests. Ensure this change is validated with appropriate test cases to avoid regression.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that replacing `FinalizeBlock` with `Commit` does not introduce regressions.

# Test: Search for `FinalizeBlock` usage in test files to ensure it's replaced everywhere as intended.
rg --type go --files-with-matches 'FinalizeBlock' --glob '*_test.go'

Length of output: 285



Script:

#!/bin/bash
# Description: Inspect the listed files for any remaining references to `FinalizeBlock`.

# Files to inspect
files=(
  "x/reward/abci_test.go"
  "x/reward/common_test.go"
  "x/move/abci_test.go"
  "x/move/common_test.go"
  "x/move/types/common_test.go"
  "x/gov/common_test.go"
  "x/distribution/abci_test.go"
  "x/distribution/common_test.go"
  "benchmark/app_test.go"
)

# Search for `FinalizeBlock` in the specified files
for file in "${files[@]}"; do
  echo "Inspecting $file"
  rg 'FinalizeBlock' "$file"
done

Length of output: 3616

@beer-1 beer-1 changed the title fix: test with cms update to use snapshot at simulation and check tx fix: use versioned cms to take snapshot at simulation and check tx Jun 19, 2024
@beer-1 beer-1 merged commit 8522944 into main Jun 19, 2024
7 checks passed
@beer-1 beer-1 deleted the fix/cms-with-version-at-simulation branch June 19, 2024 09: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