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

chore: cleanup comet dependence in tests #18239

Merged
merged 19 commits into from
Oct 26, 2023
Merged

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented Oct 24, 2023

Description

Related to: #17555 and #17425

Some of the cometbft package usages:

"github.com/cometbft/cometbft/proto/tendermint/types"
15 usages
x/auth/ante: ConsensusParams
x/consensus: ConsensusParams
x/genutil: ConsensusParams
x/simulation: many things
x/upgrade: ConsensusParams
x/staking: HistoricalInfo makes use of Header


"github.com/cometbft/cometbft/crypto"
x/auth: crypto.AddressHash and CRandBytes
x/slashing: crypto.Address in hooks
x/staking: crypto.AddressHash and GetCmtConsPubKey

(maybe we can just move all of these functions to our crypto package)

"github.com/cometbft/cometbft/abci/types"

- any module that has initGenesis or endblocker returning validator updates
- abci.Event in tests

"github.com/cometbft/cometbft/types"

- GenesisDocFromFile
- ValidatorSet
- many others

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: Updated the codebase to use the header.Info struct instead of the cmtproto.Header struct, improving the consistency and readability of the code.
  • Refactor: Removed unnecessary block finalization calls in various test functions, simplifying the test setup and execution.
  • Refactor: Replaced the usage of cmttime.Now() with the standard time.Now(), making the code more standard-compliant.
  • Refactor: Removed the SimTxFinalizeBlock function and replaced it with SimDeliver in simulation operations, streamlining the simulation process.

These changes primarily improve the code's maintainability and readability, and they do not introduce new features or directly affect end-users.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 24, 2023

Walkthrough

The changes primarily revolve around the replacement of cmtproto.Header with header.Info and the removal of block finalization calls in tests. The SimTxFinalizeBlock function has been replaced with SimDeliver in several places. The usage of cmttime.Now() has been replaced with time.Now().

Changes

File(s) Summary
baseapp/test_helpers.go Removed SimTxFinalizeBlock function from BaseApp struct.
tests/integration/bank/app_test.go, testutil/sims/tx_helpers.go, x/auth/ante/feegrant_test.go, x/auth/vesting/fuzz_test.go, x/auth/vesting/msg_server_test.go, x/auth/vesting/types/vesting_account_test.go, x/authz/keeper/genesis_test.go, x/authz/simulation/operations.go, x/authz/simulation/operations_test.go, x/bank/keeper/collections_test.go, x/bank/keeper/keeper_test.go, x/bank/simulation/operations.go, x/bank/simulation/operations_test.go, x/distribution/keeper/allocation_test.go, x/distribution/keeper/delegation_test.go, x/distribution/keeper/keeper_test.go, x/distribution/simulation/operations_test.go, x/evidence/genesis_test.go, x/evidence/keeper/keeper_test.go, x/feegrant/simulation/operations_test.go, x/genutil/types/genesis.go, x/gov/abci_test.go, x/gov/simulation/operations_test.go, x/group/keeper/keeper_test.go, x/group/simulation/operations_test.go, x/nft/simulation/operations_test.go, x/protocolpool/simulation/operations_test.go, x/slashing/app_test.go, x/slashing/simulation/operations_test.go, x/staking/app_test.go Replaced cmtproto.Header with header.Info and removed block finalization calls in tests. Replaced SimTxFinalizeBlock with SimDeliver in several places. Replaced cmttime.Now() with time.Now().

"In the land of code, where logic is king, 🐇
Changes were made, to make tests sing. 🎵
Headers were swapped, time was aligned, ⏰
FinalizeBlock, we no longer find. 🚫
Celebrate now, for the code is clean, 🎉
In the realm of software, a sight to be seen!" 🌟


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

@tac0turtle tac0turtle changed the title Facu/module test cleanup chore: cleanup comet dependence in tests Oct 24, 2023
@github-actions github-actions bot added C:x/auth C:x/genutil genutil module issues labels Oct 25, 2023
x/genutil/types/genesis.go Dismissed Show dismissed Hide dismissed
@facundomedica facundomedica marked this pull request as ready for review October 26, 2023 10:23
@facundomedica facundomedica requested a review from a team as a code owner October 26, 2023 10:23
@github-prbot github-prbot requested review from a team, kocubinski and likhita-809 and removed request for a team October 26, 2023 10:23
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 331e106 and 608d377.
Files ignored due to filter (2)
  • x/nft/go.mod
  • x/protocolpool/go.mod
Files selected for processing (31)
  • baseapp/test_helpers.go (1} hunks)
  • tests/integration/bank/app_test.go (6} hunks)
  • testutil/sims/tx_helpers.go (2} hunks)
  • x/auth/ante/feegrant_test.go (2} hunks)
  • x/auth/vesting/fuzz_test.go (2} hunks)
  • x/auth/vesting/msg_server_test.go (2} hunks)
  • x/auth/vesting/types/vesting_account_test.go (22} hunks)
  • x/authz/keeper/genesis_test.go (2} hunks)
  • x/authz/simulation/operations.go (3} hunks)
  • x/authz/simulation/operations_test.go (6} hunks)
  • x/bank/keeper/collections_test.go (2} hunks)
  • x/bank/keeper/keeper_test.go (14} hunks)
  • x/bank/simulation/operations.go (2} hunks)
  • x/bank/simulation/operations_test.go (5} hunks)
  • x/distribution/keeper/allocation_test.go (4} hunks)
  • x/distribution/keeper/delegation_test.go (10} hunks)
  • x/distribution/keeper/keeper_test.go (2} hunks)
  • x/distribution/simulation/operations_test.go (4} hunks)
  • x/evidence/genesis_test.go (2} hunks)
  • x/evidence/keeper/keeper_test.go (2} hunks)
  • x/feegrant/simulation/operations_test.go (4} hunks)
  • x/genutil/types/genesis.go (2} hunks)
  • x/gov/abci_test.go (8} hunks)
  • x/gov/simulation/operations_test.go (7} hunks)
  • x/group/keeper/keeper_test.go (2} hunks)
  • x/group/simulation/operations_test.go (15} hunks)
  • x/nft/simulation/operations_test.go (2} hunks)
  • x/protocolpool/simulation/operations_test.go (2} hunks)
  • x/slashing/app_test.go (3} hunks)
  • x/slashing/simulation/operations_test.go (1} hunks)
  • x/staking/app_test.go (5} hunks)
Files skipped from review due to trivial changes (21)
  • baseapp/test_helpers.go
  • tests/integration/bank/app_test.go
  • testutil/sims/tx_helpers.go
  • x/auth/ante/feegrant_test.go
  • x/auth/vesting/fuzz_test.go
  • x/auth/vesting/types/vesting_account_test.go
  • x/authz/simulation/operations_test.go
  • x/bank/keeper/keeper_test.go
  • x/bank/simulation/operations_test.go
  • x/distribution/keeper/delegation_test.go
  • x/evidence/genesis_test.go
  • x/evidence/keeper/keeper_test.go
  • x/feegrant/simulation/operations_test.go
  • x/genutil/types/genesis.go
  • x/gov/abci_test.go
  • x/gov/simulation/operations_test.go
  • x/group/keeper/keeper_test.go
  • x/group/simulation/operations_test.go
  • x/nft/simulation/operations_test.go
  • x/slashing/simulation/operations_test.go
  • x/staking/app_test.go
Additional comments: 26
x/protocolpool/simulation/operations_test.go (2)
  • 4-9: The import of github.com/cometbft/cometbft/abci/types has been removed. Ensure that this does not affect any other parts of the code that might be using it. Also, verify that the replacement packages provide equivalent functionality.

  • 112-117: The call to suite.App.FinalizeBlock has been removed. This suggests a change in the block finalization process. Ensure that this does not affect the correctness of the tests and that the block finalization is handled elsewhere if necessary.

x/bank/keeper/collections_test.go (2)
  • 5-11: The import of cometbft package has been replaced with standard time package and cosmossdk.io/core/header. This change aligns with the goal of reducing reliance on external packages and using standard Go packages where possible. It also simplifies the code by using the standard time.Now() function instead of cmttime.Now().

  • 30-30: The context creation has been modified to use header.Info instead of cmtproto.Header. This change is consistent with the replacement of cometbft package imports. It's important to ensure that the new header.Info type is compatible with all functions that use this context.

x/auth/vesting/msg_server_test.go (2)
  • 7-10: The import of cometbft package has been replaced with the standard time package and cosmossdk.io/core/header. This change aligns with the goal of reducing reliance on external packages and using standard Go packages where possible. Ensure that the header.Info type and time.Now() function provide the same functionality as the replaced cmtproto.Header and cmttime.Now().

  • 48-48: The context creation has been updated to use header.Info and time.Now(). This change is consistent with the import changes. However, ensure that the header.Info type and time.Now() function are compatible with the WithHeaderInfo method and provide the same functionality as the replaced cmtproto.Header and cmttime.Now().

x/slashing/app_test.go (3)
  • 9-9: The import of the cometbft package has been replaced with the cosmossdk.io/core/header package. This change aligns with the PR's goal of reducing dependency on external packages. Ensure that the header package provides equivalent functionality to the cometbft package.

  • 93-97: The cmtproto.Header has been replaced with header.Info. This change is consistent with the new import from cosmossdk.io/core/header. The app.FinalizeBlock function call has been removed, suggesting a change in the block finalization process. Ensure that the removal of app.FinalizeBlock does not affect the test's functionality and that the block finalization process is handled elsewhere in the code.

  • 113-114: The cmtproto.Header has been replaced with header.Info in this hunk as well. This change is consistent with the new import from cosmossdk.io/core/header. Ensure that the header.Info type provides equivalent functionality to the cmtproto.Header type.

x/authz/keeper/genesis_test.go (2)
  • 7-10: The import of cometbft package has been replaced with cosmossdk.io/core/header. This change aligns with the PR's goal of reducing dependency on external packages. Ensure that the header package provides equivalent functionality to the cometbft package.

  • 49-49: The context creation has been modified to use header.Info instead of cmtproto.Header. This change is consistent with the import changes. Verify that header.Info provides the same functionality as cmtproto.Header and that the Height field is correctly set.

x/authz/simulation/operations.go (3)
  • 141-147: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [144-148]

The function app.SimTxFinalizeBlock has been replaced with app.SimDeliver. Ensure that app.SimDeliver is capable of handling the transaction delivery as expected. If app.SimDeliver does not include the block finalization process, make sure that it is handled elsewhere if necessary.

  • 218-224: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [221-225]

The function app.SimTxFinalizeBlock has been replaced with app.SimDeliver. Ensure that app.SimDeliver is capable of handling the transaction delivery as expected. If app.SimDeliver does not include the block finalization process, make sure that it is handled elsewhere if necessary.

  • 318-324: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [321-325]

The function app.SimTxFinalizeBlock has been replaced with app.SimDeliver. Ensure that app.SimDeliver is capable of handling the transaction delivery as expected. If app.SimDeliver does not include the block finalization process, make sure that it is handled elsewhere if necessary.

x/distribution/keeper/allocation_test.go (4)
  • 7-12: The import of cometbft package has been replaced with cosmossdk.io/core/header. This change aligns with the PR's goal of reducing dependency on external packages. Ensure that the header.Info type from cosmossdk.io/core/header provides the same functionality as cmtproto.Header from cometbft.

  • 35-35: The cmtproto.Header has been replaced with header.Info in the context creation. This change is consistent with the import changes. Ensure that the header.Info type provides the same functionality as cmtproto.Header and that the context creation is correct.

  • 94-94: The cmtproto.Header has been replaced with header.Info in the context creation. This change is consistent with the import changes. Ensure that the header.Info type provides the same functionality as cmtproto.Header and that the context creation is correct.

  • 224-224: The cmtproto.Header has been replaced with header.Info in the context creation. This change is consistent with the import changes. Ensure that the header.Info type provides the same functionality as cmtproto.Header and that the context creation is correct.

x/bank/simulation/operations.go (2)
  • 174-180: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [177-181]

The function app.SimTxFinalizeBlock has been replaced with app.SimDeliver. Ensure that app.SimDeliver performs all the necessary operations that app.SimTxFinalizeBlock was doing, especially in the context of transaction finalization. If there are any additional steps required for transaction finalization, they should be handled appropriately.

  • 390-396: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [393-397]

The function app.SimTxFinalizeBlock has been replaced with app.SimDeliver. As mentioned above, ensure that app.SimDeliver performs all the necessary operations that app.SimTxFinalizeBlock was doing, especially in the context of transaction finalization. If there are any additional steps required for transaction finalization, they should be handled appropriately.

x/distribution/keeper/keeper_test.go (2)
  • 7-10: The import of cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" has been replaced with "cosmossdk.io/core/header". This change aligns with the PR's goal of reducing dependency on the cometbft package. Ensure that the header package from cosmossdk.io/core provides equivalent functionality to the cmtproto package from cometbft.

  • 42-42: The context creation has been updated to use header.Info{Time: time.Now()} instead of cmtproto.Header{Time: time.Now()}. This change is consistent with the updated import. Ensure that all instances of cmtproto.Header have been replaced with header.Info throughout the codebase.

x/distribution/simulation/operations_test.go (4)
  • 4-9: The import of github.com/cometbft/cometbft/abci/types has been removed. Ensure that this does not affect the functionality of the code, as the abci package might have been used for its types and functions. If the functionality provided by abci is now covered by other packages, this change is fine.

  • 73-78: The call to suite.app.FinalizeBlock has been removed. This function was previously used to finalize the block before executing the operation. If the block finalization is now handled elsewhere or is no longer necessary due to changes in the block processing logic, this change is acceptable. However, ensure that removing this does not affect the state of the blockchain application during testing.

  • 113-118: Similar to the previous comment, the call to suite.app.FinalizeBlock has been removed. Ensure that this does not affect the state of the blockchain application during testing.

  • 174-179: Again, the call to suite.app.FinalizeBlock has been removed. Ensure that this does not affect the state of the blockchain application during testing.

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

utACK, love the cleanup

@facundomedica facundomedica added this pull request to the merge queue Oct 26, 2023
Merged via the queue into main with commit ab2a725 Oct 26, 2023
59 checks passed
@facundomedica facundomedica deleted the facu/module-test-cleanup branch October 26, 2023 17:08
@@ -68,7 +67,7 @@ func (ag *AppGenesis) ValidateAndComplete() error {
}

if ag.GenesisTime.IsZero() {
ag.GenesisTime = cmttime.Now()
ag.GenesisTime = time.Now().Round(0).UTC()
Copy link
Member

@julienrbrt julienrbrt Oct 30, 2023

Choose a reason for hiding this comment

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

TM has this as a helper, should we just create it in the SDK instead and use it at the remaining places?

Copy link
Member

Choose a reason for hiding this comment

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

na, we want to avoid more sdk deps 😄

Copy link
Member

Choose a reason for hiding this comment

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

Then we should add a rule in https://github.com/crypto-com/cosmos-sdk-codeql 😅
This exists: https://github.com/crypto-com/cosmos-sdk-codeql/blob/main/src/system-time.ql, which is good, but it should not trigger with time.Now().Round(0).UTC() and advise to use time.Now().Round(0).UTC() otherwise.

Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants