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

test: update mockery configuration and regenerate mocks #955

Open
wants to merge 17 commits into
base: v1.3-dev
Choose a base branch
from

Conversation

lklimek
Copy link
Collaborator

@lklimek lklimek commented Oct 11, 2024

Issue being fixed or feature implemented

Current mocking solution with mockery using go:generate is deprecated.

What was done?

  • created .mockery.yaml
  • updated Makefile and scripts/mockery_generate.sh
  • deleted and regenerated all mocks

How Has This Been Tested?

GHA

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features
    • Introduced a new configuration file for mock generation settings.
  • Bug Fixes
    • Simplified the error-checking process for generated mocks.
  • Refactor
    • Updated method signatures across various mocks to use crypto.QuorumHash instead of bytes.HexBytes.
    • Removed several mock implementations that are no longer needed.
  • Chores
    • Simplified the script for invoking mock generation without additional constraints.

Base automatically changed from build/go-1.23 to v1.3-dev October 16, 2024 11:24
Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The pull request introduces several changes across multiple files, primarily focusing on mock implementations and configuration for testing. Key updates include the introduction of a new .mockery.yaml configuration file for mock generation, modifications to the Makefile and a GitHub Actions workflow file to streamline mock generation processes, and updates to method signatures in mock types to align with new data types. Additionally, several mock files have been removed, indicating a shift in the project's mock structure and dependencies.

Changes

File Path Change Summary
.github/workflows/check-generated.yml Updated go-version from 1.23 to 1.23.2; simplified condition for checking generated mocks.
.mockery.yaml New configuration file for mock generation with specified settings and interfaces.
Makefile Modified mockery target to directly execute ./scripts/mockery_generate.sh.
cmd/tenderdash/commands/reindex_event_test.go Changed mockEventSink type from *mocks.EventSink to *imocks.EventSink.
dash/core/mocks/client.go Updated QuorumInfo method to use crypto.QuorumHash instead of bytes.HexBytes.
internal/blocksync/mocks/block_client.go Deleted mock implementation of BlockClient.
internal/consensus/mocks/fast_sync_reactor.go Deleted mock implementation of BlockSyncReactor.
internal/proxy/mocks/app_conn_mempool.go Deleted mock implementation of AppConnMempool.
internal/proxy/mocks/app_conn_query.go Deleted mock implementation of AppConnQuery.
internal/proxy/mocks/app_conn_snapshot.go Deleted mock implementation of AppConnSnapshot.
internal/state/mocks/event_sink.go Deleted mock implementation of EventSink.
internal/statesync/mocks/Metricer.go Deleted mock implementation of Metricer.
rpc/client/mocks/abci_client.go Deleted mock implementation of ABCIClient.
rpc/client/mocks/events_client.go Deleted mock implementation of EventsClient.
rpc/client/mocks/evidence_client.go Deleted mock implementation of EvidenceClient.
rpc/client/mocks/history_client.go Deleted mock implementation of HistoryClient.
rpc/client/mocks/mempool_client.go Deleted mock implementation of MempoolClient.
rpc/client/mocks/network_client.go Deleted mock implementation of NetworkClient.
rpc/client/mocks/sign_client.go Deleted mock implementation of SignClient.
rpc/client/mocks/status_client.go Deleted mock implementation of StatusClient.
rpc/client/mocks/subscription_client.go Deleted mock implementation of SubscriptionClient.
scripts/mockery_generate.sh Simplified command execution logic for invoking Mockery without additional flags.
types/mocks/privvalidator.go Updated method signatures to replace bytes.HexBytes with crypto.QuorumHash.

Poem

In the garden of code, we leap and bound,
With mocks and scripts, new paths are found.
A YAML to guide, a workflow refined,
In the world of testing, joy intertwined.
So hop with delight, let changes take flight,
For every new feature, we celebrate 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>, 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
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: 1

🧹 Outside diff range and nitpick comments (3)
.mockery.yaml (2)

1-9: Consider enabling with-expecter for more powerful mocking capabilities.

The global configuration settings are well-structured and follow good practices. However, you might want to consider setting with-expecter: true. This would generate expecter structs, allowing for more powerful and flexible mocking scenarios, especially useful for complex testing situations.

The rest of the configuration looks good:

  • The directory structure and naming conventions are clear and intuitive.
  • Using warn-level logging and disabling version strings will keep the output clean.
  • Setting all: false gives precise control over which interfaces are mocked.

10-71: Comprehensive package list, but consider addressing potential naming conflicts.

The package list for mock generation is thorough and covers key components of the Tenderdash project. It's great to see that various crucial interfaces are included, which will facilitate effective testing and dependency injection throughout the codebase.

However, there are two suggestions for improvement:

  1. Potential naming conflicts: Some packages (e.g., abci/client and dash/core) both have a Client interface. This might lead to naming conflicts in the generated mocks. Consider using more specific names or prefixing the mock names with the package name to avoid confusion.

  2. Add explanatory comments: It would be beneficial to add brief comments explaining the purpose of mocking each interface, especially for less obvious ones. This can help other developers understand the testing strategy and the role of each mock.

cmd/tenderdash/commands/reindex_event_test.go (1)

Line range hint 1-203: Overall assessment: Changes align with PR objectives.

The modifications in this file successfully update the mocking implementation as intended. The test logic remains unchanged, which suggests that the new mock is compatible with the existing test structure. This approach minimizes the risk of introducing new bugs while achieving the goal of updating the mocking solution.

To further improve the PR:

  1. Consider adding a comment explaining the reason for the mock update, which would help future developers understand the change.
  2. Ensure that all other files using EventSink mocks have been similarly updated for consistency.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f8ebd34 and 24c796a.

📒 Files selected for processing (23)
  • .github/workflows/check-generated.yml (2 hunks)
  • .mockery.yaml (1 hunks)
  • Makefile (1 hunks)
  • cmd/tenderdash/commands/reindex_event_test.go (2 hunks)
  • dash/core/mocks/client.go (3 hunks)
  • internal/blocksync/mocks/block_client.go (0 hunks)
  • internal/consensus/mocks/fast_sync_reactor.go (0 hunks)
  • internal/proxy/mocks/app_conn_mempool.go (0 hunks)
  • internal/proxy/mocks/app_conn_query.go (0 hunks)
  • internal/proxy/mocks/app_conn_snapshot.go (0 hunks)
  • internal/state/mocks/event_sink.go (0 hunks)
  • internal/statesync/mocks/Metricer.go (0 hunks)
  • rpc/client/mocks/abci_client.go (0 hunks)
  • rpc/client/mocks/events_client.go (0 hunks)
  • rpc/client/mocks/evidence_client.go (0 hunks)
  • rpc/client/mocks/history_client.go (0 hunks)
  • rpc/client/mocks/mempool_client.go (0 hunks)
  • rpc/client/mocks/network_client.go (0 hunks)
  • rpc/client/mocks/sign_client.go (0 hunks)
  • rpc/client/mocks/status_client.go (0 hunks)
  • rpc/client/mocks/subscription_client.go (0 hunks)
  • scripts/mockery_generate.sh (1 hunks)
  • types/mocks/privvalidator.go (15 hunks)
💤 Files with no reviewable changes (16)
  • internal/blocksync/mocks/block_client.go
  • internal/consensus/mocks/fast_sync_reactor.go
  • internal/proxy/mocks/app_conn_mempool.go
  • internal/proxy/mocks/app_conn_query.go
  • internal/proxy/mocks/app_conn_snapshot.go
  • internal/state/mocks/event_sink.go
  • internal/statesync/mocks/Metricer.go
  • rpc/client/mocks/abci_client.go
  • rpc/client/mocks/events_client.go
  • rpc/client/mocks/evidence_client.go
  • rpc/client/mocks/history_client.go
  • rpc/client/mocks/mempool_client.go
  • rpc/client/mocks/network_client.go
  • rpc/client/mocks/sign_client.go
  • rpc/client/mocks/status_client.go
  • rpc/client/mocks/subscription_client.go
✅ Files skipped from review due to trivial changes (1)
  • scripts/mockery_generate.sh
🧰 Additional context used
🔇 Additional comments (19)
.github/workflows/check-generated.yml (2)

38-38: Simplified diff check for generated mocks

The removal of the --stat option from the git diff command simplifies the check. This change focuses the output solely on whether there are differences, without providing statistics about the changes.

This simplification is beneficial as it:

  1. Reduces noise in the CI output
  2. Maintains the core functionality of detecting changes in generated mocks
  3. Potentially speeds up the check process slightly

The error message (lines 39-44) still provides clear instructions on what to do if changes are detected, so no important information is lost with this simplification.


26-26: Verify the Go version number

The update to a newer Go version is good practice. However, the version "1.23.2" seems unusual, as Go versions typically follow a different pattern (e.g., 1.20, 1.21, etc.).

Please confirm that this is the correct version number. If it's a typo, consider updating it to the latest stable Go version.

To verify the latest stable Go version, you can run:

✅ Verification successful

Go version "1.23.2" verified as the latest stable release.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Fetch the latest stable Go version
curl -sSL https://golang.org/VERSION?m=text

Length of output: 82

cmd/tenderdash/commands/reindex_event_test.go (2)

16-16: LGTM: New import for updated mocking solution.

The addition of the imocks import aligns with the PR objective of updating the mocking solution. This change is consistent with the migration from the current deprecated mocking solution to the new configuration.


140-140: LGTM: Updated mock type consistent with new import.

The change from *mocks.EventSink to *imocks.EventSink is consistent with the new import and aligns with the PR objectives of updating the mocking solution.

To ensure consistency across the codebase, please run the following script to verify that all EventSink mocks have been updated:

✅ Verification successful

LGTM: Updated mock type in reindex_event_test.go is correct.
The change from *mocks.EventSink to *imocks.EventSink in cmd/tenderdash/commands/reindex_event_test.go aligns with the PR objectives.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all EventSink mocks have been updated to use imocks.

# Test: Search for any remaining uses of mocks.EventSink
rg --type go 'mocks\.EventSink'

# Test: Confirm new usage of imocks.EventSink
rg --type go 'imocks\.EventSink'

Length of output: 1006

dash/core/mocks/client.go (3)

9-10: LGTM: New import added correctly.

The new import for the crypto package is correctly added and is necessary for the updated QuorumInfo method signature.


Line range hint 155-170: LGTM: Method body updated consistently.

The QuorumInfo method body has been correctly updated to use the new crypto.QuorumHash type in type assertions and function calls. These changes are consistent with the method signature update and maintain the existing error handling and return logic.


Line range hint 1-240: Summary: Mock file updated successfully.

The changes to this mock file are consistent with the PR objectives. The QuorumInfo method has been updated to use the new crypto.QuorumHash type, and all related code has been adjusted accordingly. These changes should improve type safety and consistency in the project.

To ensure full compatibility, please verify that:

  1. The actual Client interface in the main codebase has been updated to match this mock.
  2. Any tests using this mock have been updated to use the new crypto.QuorumHash type.

You can use the following script to check for the interface definition:

#!/bin/bash
# Search for the Client interface definition
rg --type go 'type\s+Client\s+interface' -A 20
types/mocks/privvalidator.go (11)

28-36: LGTM: Method signature and implementation updated correctly

The ExtractIntoValidator method has been successfully updated to use crypto.QuorumHash instead of bytes.HexBytes for the quorumHash parameter. The implementation logic has been adjusted accordingly to handle the new type.

Also applies to: 36-43


48-55: LGTM: Return type and implementation updated correctly

The GetFirstQuorumHash method has been successfully updated to return crypto.QuorumHash instead of bytes.HexBytes. The implementation logic has been adjusted accordingly to handle the new return type.

Also applies to: 55-57, 57-64, 64-75


Line range hint 78-87: LGTM: Method signature and implementation updated correctly

The GetHeight method has been successfully updated to use crypto.QuorumHash instead of bytes.HexBytes for the quorumHash parameter. The implementation logic has been adjusted accordingly to handle the new type.

Also applies to: 87-90, 90-96, 96-103


Line range hint 106-115: LGTM: Method signature and implementation updated correctly

The GetPrivateKey method has been successfully updated to use crypto.QuorumHash instead of bytes.HexBytes for the quorumHash parameter. The implementation logic has been adjusted accordingly to handle the new type.

Also applies to: 115-118, 118-126, 126-133


136-143: LGTM: Return type and implementation updated correctly

The GetProTxHash method has been successfully updated to return crypto.ProTxHash instead of bytes.HexBytes. The implementation logic has been adjusted accordingly to handle the new return type.

Also applies to: 143-145, 145-148, 148-152, 152-163


Line range hint 166-175: LGTM: Method signature and implementation updated correctly

The GetPubKey method has been successfully updated to use crypto.QuorumHash instead of bytes.HexBytes for the quorumHash parameter. The implementation logic has been adjusted accordingly to handle the new type.

Also applies to: 175-178, 178-186, 186-193


Line range hint 196-205: LGTM: Method signature and implementation updated correctly

The GetThresholdPublicKey method has been successfully updated to use crypto.QuorumHash instead of bytes.HexBytes for the quorumHash parameter. The implementation logic has been adjusted accordingly to handle the new type.

Also applies to: 205-208, 208-216, 216-223


Line range hint 226-235: LGTM: Method signature and implementation updated correctly

The SignProposal method has been successfully updated to use crypto.QuorumHash instead of bytes.HexBytes for the quorumHash parameter. The implementation logic has been adjusted accordingly to handle the new type.

Also applies to: 235-238, 238-246, 246-253


256-264: LGTM: Method signature and implementation updated correctly

The SignVote method has been successfully updated to use crypto.QuorumHash instead of bytes.HexBytes for the quorumHash parameter. The implementation logic has been adjusted accordingly to handle the new type.

Also applies to: 264-270


274-276: LGTM: Method signature updated correctly

The UpdatePrivateKey method has been successfully updated to use crypto.QuorumHash instead of bytes.HexBytes for the quorumHash parameter.


Line range hint 1-292: Summary: Successful update of PrivValidator mock

This review has confirmed that all method signatures in the PrivValidator mock have been successfully updated to use crypto.QuorumHash instead of bytes.HexBytes for the quorumHash parameter. The implementation logic for each method has been adjusted accordingly to handle the new type.

These changes are consistent with the PR objectives of updating the mocking solution and align with the shift from bytes.HexBytes to crypto.QuorumHash in the main codebase. The updates should ensure that the mock accurately reflects the behavior of the actual PrivValidator implementation.

No issues or inconsistencies were found in the changes. The mock should now be compatible with the updated interfaces in the main codebase.

Makefile (1)

339-339: LGTM. Verify mock generation consistency.

The simplification of the mockery target by directly calling the script is a good change. It aligns with the PR objectives of updating the mockery configuration.

To ensure this change doesn't affect the mock generation process or its output, please run the following verification:

This script will help verify that the mock generation process produces consistent results with the new implementation.

dash/core/mocks/client.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

1 participant