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

refactor: modules should implement appmodule.AppModule #18252

Merged
merged 4 commits into from
Oct 25, 2023

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Oct 25, 2023

Description

This PR makes sure all SDK modules implement from now appmodule.AppModule as well.
This is clearly already recommended by us (autocli and other functionalities check a module is a module by checking this interface): https://github.com/cosmos/cosmos-sdk/blob/main/UPGRADING.md#all-1 and easy to forget (cosmos/ibc-go#4607).


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
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • run make lint and make test
  • 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 ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Summary by CodeRabbit

  • Refactor: Enhanced the MockTxSelector functions to handle cancellation and timeouts more efficiently, improving the reliability of the system.
  • Test: Introduced a mock implementation of the DB interface, facilitating more comprehensive and efficient testing.
  • Test: Expanded the MockAppModuleWithAllExtensions and MockAppModuleWithAllExtensionsABCI structs with new methods, enhancing the testing capabilities.
  • Refactor: Renamed the CoreAppModuleBasicAdaptor function to CoreAppModuleAdaptor and added a new CoreAppModuleBasicAdaptor function for better code organization.
  • New Feature: Added a new interface AppModule that extends appmodule.AppModule, ensuring all modules implement the necessary functions, thereby improving the robustness of the system.
  • Test: Added a new method AddressCodec to the MockAccountKeeper struct, improving the testing scope.
  • Chore: Updated the scripts/mockgen.sh script to reflect changes in the mock generation process.

@julienrbrt julienrbrt added the backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release label Oct 25, 2023
@julienrbrt julienrbrt requested a review from a team as a code owner October 25, 2023 11:45
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 25, 2023

Walkthrough

This pull request introduces context handling in the MockTxSelector struct, adds new methods to the MockAppModuleWithAllExtensions, MockAppModuleWithAllExtensionsABCI, MockAppModule, and MockHasABCIEndBlock structs, and implements a mock DB interface. It also adds an AppModule interface and modifies the NewManager function to check for this interface. Lastly, it adds an AddressCodec method to the MockAccountKeeper struct and modifies the mockgen.sh script.

Changes

File(s) Summary
baseapp/testutil/mock/mocks.go Added context handling to MockTxSelector struct.
store/mock/cosmos_cosmos_db_DB.go Introduced a mock implementation of the DB interface.
testutil/mock/types_mock_appmodule.go, testutil/mock/types_module_module.go Added new methods to MockAppModuleWithAllExtensions, MockAppModuleWithAllExtensionsABCI, MockAppModule, and MockHasABCIEndBlock structs.
types/module/core_module.go, types/module/module.go Added AppModule interface and modified NewManager function to check for this interface.
x/slashing/testutil/expected_keepers_mocks.go Added AddressCodec method to MockAccountKeeper struct.
scripts/mockgen.sh Modified to remove a line of code that generates a mock for the DB interface.

🐇
"In the land of code, where the shadows lie,
We've made some changes, oh me, oh my!
Contexts, mocks, and interfaces new,
Celebrate these changes, for they are few.
So hop along, and don't be shy,
In the land of code, where the shadows lie." 🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.json

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: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 139a29e and aad27f1.
Files selected for processing (7)
  • baseapp/testutil/mock/mocks.go (1 hunks)
  • store/mock/cosmos_cosmos_db_DB.go (1 hunks)
  • testutil/mock/types_mock_appmodule.go (2 hunks)
  • testutil/mock/types_module_module.go (2 hunks)
  • types/module/core_module.go (2 hunks)
  • types/module/module.go (2 hunks)
  • x/slashing/testutil/expected_keepers_mocks.go (1 hunks)
Files skipped from review due to trivial changes (5)
  • store/mock/cosmos_cosmos_db_DB.go
  • testutil/mock/types_module_module.go
  • types/module/core_module.go
  • types/module/module.go
  • x/slashing/testutil/expected_keepers_mocks.go
Additional comments: 4
baseapp/testutil/mock/mocks.go (4)
  • 210-215: The function signature for SelectTxForProposal has been updated to include a context.Context parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 218-221: The function signature for SelectTxForProposal in the MockTxSelectorMockRecorder struct has been updated to include a context.Context parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 224-229: The function signature for SelectedTxs has been updated to include a context.Context parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 232-234: The function signature for SelectedTxs in the MockTxSelectorMockRecorder struct has been updated to include a context.Context parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

testutil/mock/types_mock_appmodule.go Show resolved Hide resolved
testutil/mock/types_mock_appmodule.go Show resolved Hide resolved
testutil/mock/types_mock_appmodule.go Show resolved Hide resolved
testutil/mock/types_mock_appmodule.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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between aad27f1 and ca01dee.
Files selected for processing (1)
  • scripts/mockgen.sh (1 hunks)
Files skipped from review due to trivial changes (1)
  • scripts/mockgen.sh

Copy link
Contributor

@testinginprod testinginprod left a comment

Choose a reason for hiding this comment

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

lgtm!

@julienrbrt julienrbrt added this pull request to the merge queue Oct 25, 2023
Merged via the queue into main with commit 797ae0f Oct 25, 2023
57 checks passed
@julienrbrt julienrbrt deleted the julien/module-assert branch October 25, 2023 12:33
mergify bot pushed a commit that referenced this pull request Oct 25, 2023
julienrbrt added a commit that referenced this pull request Oct 25, 2023
…) (#18255)

Co-authored-by: Julien Robert <julien@rbrt.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release C:x/slashing Type: Build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants