Skip to content

feat(core): add coretest package #20487

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

Merged
merged 18 commits into from
Jun 5, 2024
Merged

feat(core): add coretest package #20487

merged 18 commits into from
Jun 5, 2024

Conversation

testinginprod
Copy link
Contributor

@testinginprod testinginprod commented May 30, 2024

Description

This change adds a new package to core, called coretest.

It adds the tidwall dependency, which is an extrmely light weight one as it can be seen from the go.sum.

The purpose of this PR is to make testing of modules fully depending on core easier.

This will also help in removing some dependencies of the SDK.


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 (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • 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.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

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

Summary by CodeRabbit

  • New Features

    • Introduced a lightweight in-memory database for efficient key-value storage.
    • Added a key-value store service for managing context-specific data.
  • Refactor

    • Updated test setups across multiple files to use new context and key-value store service functions.
  • Tests

    • Added comprehensive test cases for memory database and key-value store service functionalities.
  • Chores

    • Added new configurations for automated dependency updates, PR labeling, and CI workflows.
    • Introduced a changelog and SonarQube configuration for the core testing project.

unknown unknown added 2 commits May 30, 2024 10:56
# Conflicts:
#	orm/go.sum
#	server/v2/stf/go.sum
@testinginprod testinginprod requested a review from a team May 30, 2024 10:09
Copy link
Contributor

coderabbitai bot commented May 30, 2024

Important

Review skipped

Review was skipped due to path filters

Files ignored due to path filters (26)
  • client/v2/go.mod is excluded by !**/*.mod
  • go.mod is excluded by !**/*.mod
  • server/v2/cometbft/go.mod is excluded by !**/*.mod
  • simapp/go.mod is excluded by !**/*.mod
  • tests/go.mod is excluded by !**/*.mod
  • x/accounts/defaults/lockup/go.mod is excluded by !**/*.mod
  • x/accounts/go.mod is excluded by !**/*.mod
  • x/auth/go.mod is excluded by !**/*.mod
  • x/authz/go.mod is excluded by !**/*.mod
  • x/bank/go.mod is excluded by !**/*.mod
  • x/circuit/go.mod is excluded by !**/*.mod
  • x/consensus/go.mod is excluded by !**/*.mod
  • x/consensus/go.sum is excluded by !**/*.sum
  • x/distribution/go.mod is excluded by !**/*.mod
  • x/epochs/go.mod is excluded by !**/*.mod
  • x/evidence/go.mod is excluded by !**/*.mod
  • x/feegrant/go.mod is excluded by !**/*.mod
  • x/gov/go.mod is excluded by !**/*.mod
  • x/group/go.mod is excluded by !**/*.mod
  • x/mint/go.mod is excluded by !**/*.mod
  • x/nft/go.mod is excluded by !**/*.mod
  • x/params/go.mod is excluded by !**/*.mod
  • x/protocolpool/go.mod is excluded by !**/*.mod
  • x/slashing/go.mod is excluded by !**/*.mod
  • x/staking/go.mod is excluded by !**/*.mod
  • x/upgrade/go.mod is excluded by !**/*.mod

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

Walkthrough

The updates introduce a coretesting package for creating dummy contexts and an in-memory database for testing purposes. This package replaces the previous colltest package across multiple test files. Additionally, the updates include new configurations for CI/CD workflows and dependency management, ensuring the new testing utilities are integrated and maintained efficiently.

Changes

Files/Paths Change Summary
core/coretesting/context.go Added dummyCtx type and functions for creating/testing dummy contexts.
core/coretesting/memdb.go Introduced a lightweight in-memory database with CRUD operations and iterators.
core/coretesting/memdb_test.go Added test cases for MemDB functionalities.
core/coretesting/services_test.go Added test cases for KVStoreService functionality.
core/coretesting/store.go Introduced KVStoreService and kvStoreService type for managing key-value stores within a context.
collections/indexed_map_test.go Updated to use coretesting.Context() and KVStoreService instead of colltest.MockStore().
collections/lookup_map_test.go Updated to use coretesting.Context() and KVStoreService instead of colltest.MockStore().
collections/triple_test.go Updated to use coretesting.Context() and KVStoreService instead of colltest.MockStore().
collections/collections_test.go Replaced colltest.MockStore() with coretesting functions for context and KV store service initialization.
collections/indexes/indexes_test.go Refactored to use coretesting functions for context and KV store service setup.
x/accounts/accountstd/test_util.go Updated to use coretesting.Context() and KVStoreService instead of colltest.MockStore().
x/accounts/genesis_test.go Refactored test setup to use coretesting functions instead of colltest.MockStore().
x/accounts/internal/implementation/context_test.go Replaced colltest.MockStore() with coretesting functions.
x/accounts/utils_test.go Updated to use coretesting functions for test setup.
x/auth/migrations/v5/migrate_test.go Replaced colltest with coretesting for context and KV store service initialization.
go.work.example Added import statement for ./core/testing.
.github/dependabot.yml Added update configuration for core/testing directory.
.github/pr_labeler.yml Added entry for core/testing path.
.github/workflows/test.yml Introduced new job for testing coretesting and integrated with SonarCloud.
core/testing/CHANGELOG.md Added guidelines and templates for creating human-readable changelogs.
core/testing/sonar-project.properties Configured SonarQube analysis for the core/testing project.

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.

@github-actions github-actions bot added the C:orm label May 30, 2024
@github-actions github-actions bot removed the C:orm label May 30, 2024
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: 3

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ac49374 and 8b625cd.

Files ignored due to path filters (4)
  • core/go.mod is excluded by !**/*.mod
  • core/go.sum is excluded by !**/*.sum
  • runtime/v2/go.mod is excluded by !**/*.mod
  • runtime/v2/go.sum is excluded by !**/*.sum
Files selected for processing (5)
  • core/coretesting/context.go (1 hunks)
  • core/coretesting/memdb.go (1 hunks)
  • core/coretesting/memdb_test.go (1 hunks)
  • core/coretesting/services_test.go (1 hunks)
  • core/coretesting/store.go (1 hunks)
Additional context used
Path-based instructions (5)
core/coretesting/store.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

core/coretesting/services_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

core/coretesting/context.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

core/coretesting/memdb_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

core/coretesting/memdb.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (9)
core/coretesting/services_test.go (3)

14-19: Test case checks for panic on invalid context.

Consider revisiting this test if the implementation of OpenKVStore is changed to handle errors instead of panicking.


21-28: Properly tests key-value operations in KVStoreService.


30-34: Test verifies module name storage in KVStoreService.

core/coretesting/context.go (1)

11-15: Function Context correctly initializes a dummyCtx.

core/coretesting/memdb_test.go (2)

11-23: Tests cover basic operations (Set, Get, Delete) of memDB.


24-58: Comprehensive tests for both normal and reverse iterators in memDB.

core/coretesting/memdb.go (3)

21-100: memDB type and its methods are well-defined and appropriate for in-memory database operations.


102-116: item type and byKeys function are correctly implemented for key comparison in B-tree.


118-253: memIterator type and its methods provide robust iterator functionality for memDB.

Comment on lines 10 to 15
func KVStoreService(ctx context.Context, moduleName string) store.KVStoreService {
unwrap(ctx).stores[moduleName] = newMemDB()
return kvStoreService{
moduleName: moduleName,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential panic risk in KVStoreService.

Consider handling the error when the context is not of type dummyCtx gracefully instead of panicking. This will improve the robustness of the code.

- unwrap(ctx).stores[moduleName] = newMemDB()
+ dummy, ok := unwrap(ctx)
+ if !ok {
+     return nil, fmt.Errorf("invalid context type")
+ }
+ dummy.stores[moduleName] = newMemDB()

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func KVStoreService(ctx context.Context, moduleName string) store.KVStoreService {
unwrap(ctx).stores[moduleName] = newMemDB()
return kvStoreService{
moduleName: moduleName,
}
}
func KVStoreService(ctx context.Context, moduleName string) store.KVStoreService {
dummy, ok := unwrap(ctx)
if !ok {
return nil, fmt.Errorf("invalid context type")
}
dummy.stores[moduleName] = newMemDB()
return kvStoreService{
moduleName: moduleName,
}
}

Comment on lines 21 to 27
func (k kvStoreService) OpenKVStore(ctx context.Context) store.KVStore {
kv, ok := unwrap(ctx).stores[k.moduleName]
if !ok {
panic(fmt.Sprintf("KVStoreService %s not found", k.moduleName))
}
return kv
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace panic with error handling in OpenKVStore.

Using panic can lead to abrupt termination of the application. Consider returning an error to allow the caller to handle the situation more gracefully.

- panic(fmt.Sprintf("KVStoreService %s not found", k.moduleName))
+ return nil, fmt.Errorf("KVStoreService %s not found", k.moduleName)

Committable suggestion was skipped due low confidence.

Comment on lines 38 to 44
func unwrap(ctx context.Context) *dummyCtx {
dummy, ok := ctx.(*dummyCtx)
if !ok {
panic(fmt.Sprintf("invalid context.Context, wanted dummy got: %T", ctx))
}
return dummy
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling type assertion failure gracefully in unwrap.

Panicking on a type assertion failure can cause abrupt application termination. It's better to return an error and let the caller handle it.

- panic(fmt.Sprintf("invalid context.Context, wanted dummy got: %T", ctx))
+ return nil, fmt.Errorf("invalid context.Context, wanted dummy got: %T", ctx)

Committable suggestion was skipped due low confidence.

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.

i think test or testing is a better name. Will wait for others to post thoughts before approving. We can discuss on the team call today

@facundomedica
Copy link
Member

The reason why we don't use the MemDB from github.com/cosmos/cosmos-db directly is to avoid imports right? If that's so, sounds good to me. Also +1 to the package name, test should be good enough as we'd be importing it as ../core/test/..

@testinginprod
Copy link
Contributor Author

not attached to name, it's just that it is bound to be imported as :

import coretest "cosmossdk.io/core/test"

so I'd just call it "coretest" or "coretesting" up to you to avoid neededing to manually rename it in every file which is imported

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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8b625cd and 1dd4d19.

Files ignored due to path filters (2)
  • collections/go.mod is excluded by !**/*.mod
  • collections/go.sum is excluded by !**/*.sum
Files selected for processing (5)
  • collections/indexed_map_test.go (3 hunks)
  • collections/lookup_map_test.go (1 hunks)
  • collections/triple_test.go (2 hunks)
  • core/coretesting/memdb.go (1 hunks)
  • core/coretesting/memdb_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • core/coretesting/memdb_test.go
Additional context used
Path-based instructions (4)
collections/lookup_map_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

collections/triple_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

collections/indexed_map_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

core/coretesting/memdb.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (9)
collections/lookup_map_test.go (2)

6-6: Import of coretesting aligns with the PR's goal to facilitate easier testing.


13-14: The use of coretesting.Context() and coretesting.KVStoreService(ctx, "test") is a good practice as it simplifies the setup for testing by providing a standardized context and KV store service. This should enhance test consistency and maintainability.

collections/triple_test.go (2)

6-6: Import of coretesting aligns with the PR's goal to facilitate easier testing.


22-23: The use of coretesting.Context() and coretesting.KVStoreService(ctx, "test") is a good practice as it simplifies the setup for testing by providing a standardized context and KV store service. This should enhance test consistency and maintainability.

collections/indexed_map_test.go (2)

6-6: Import of coretesting aligns with the PR's goal to facilitate easier testing.


48-50: The use of coretesting.Context() and coretesting.KVStoreService(ctx, "test") is a good practice as it simplifies the setup for testing by providing a standardized context and KV store service. This should enhance test consistency and maintainability.

core/coretesting/memdb.go (3)

1-1: The package declaration is correct and appropriately namespaced under coretesting.


3-9: Proper imports are used, including the new tidwall/btree dependency which is central to the functionality of the in-memory database.


17-17: Implementation of the memDB struct and its methods correctly adheres to the store.KVStore interface. The use of btree.BTreeG for efficient key-value storage and operations is a good choice given the performance characteristics of B-trees.

Also applies to: 19-19, 21-24, 26-34, 36-39, 41-45, 47-51, 53-60, 62-70, 74-100, 102-253

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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1dd4d19 and aafa2b5.

Files ignored due to path filters (2)
  • collections/go.mod is excluded by !**/*.mod
  • collections/go.sum is excluded by !**/*.sum
Files selected for processing (2)
  • collections/collections_test.go (1 hunks)
  • collections/indexes/indexes_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • collections/collections_test.go
Additional context used
Path-based instructions (1)
collections/indexes/indexes_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (1)
collections/indexes/indexes_test.go (1)

11-13: The refactoring of deps() to use coretesting for context and KV store service initialization looks good.

Verification successful

The refactoring of deps() to use coretesting for context and KV store service initialization looks good. The usage of coretesting.Context() and coretesting.KVStoreService(ctx, "test") is consistent across multiple test files.

  • collections/lookup_map_test.go
  • collections/triple_test.go
  • collections/collections_test.go
  • collections/indexed_map_test.go
  • collections/indexes/indexes_test.go
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of `coretesting.Context()` and `coretesting.KVStoreService(ctx, "test")` with the rest of the codebase.

# Test: Search for the usage of `coretesting.Context()` and `coretesting.KVStoreService(ctx, "test")` in other test files.
rg --type go $'coretesting.Context()\ncoretesting.KVStoreService'

Length of output: 257



Script:

#!/bin/bash
# Description: Verify the integration of `coretesting.Context()` and `coretesting.KVStoreService(ctx, "test")` with the rest of the codebase.

# Test: Search for the usage of `coretesting.Context()` in other test files.
rg --multiline --type go 'coretesting.Context()'

# Test: Search for the usage of `coretesting.KVStoreService(ctx, "test")` in other test files.
rg --multiline --type go 'coretesting.KVStoreService(ctx, "test")'

Length of output: 524

Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

Generally like the direction of this.

In the long run coretesting should probably be sufficient for running unit tests of your module with all dependencies on external module mocked via gomock. So in coretesting we'd have a mock of everthing in core (either custom like the store stuff here or generated with gomock) plus a basic test module manager/router system.

@cool-develope
Copy link
Contributor

not attached to name, it's just that it is bound to be imported as :

import coretest "cosmossdk.io/core/test"

so I'd just call it "coretest" or "coretesting" up to you to avoid neededing to manually rename it in every file which is imported

for me, core/coretesting is a little weird since we are using corestore 'core/store', coreapp 'core/app'. To explicit the purpose of it, vote on core/testutil

@aaronc
Copy link
Member

aaronc commented May 30, 2024

An alternative is having the directory as core/testing and package name as coretesting. This will create import aliases automatically that look like coretesting cosmossdk.io/core/testing which I kind of like and is common in go.

@kocubinski
Copy link
Member

Some concerns surfaced from discussion in team call:

  • Placing testing code in core would create core releases when we update test utilities, which seems undesirable. We want core to be pretty stable and move slowly.
  • Test code in core might trend towards it becoming another grab bag of utility functions, it shouldn't be.

Can we consider moving this to another go.mod or creating (like @aaronc suggests) core/testing/go.mod ?

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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between de3a0be and dc743b7.

Files ignored due to path filters (27)
  • client/v2/go.mod is excluded by !**/*.mod
  • collections/go.mod is excluded by !**/*.mod
  • collections/go.sum is excluded by !**/*.sum
  • go.mod is excluded by !**/*.mod
  • server/v2/cometbft/go.mod is excluded by !**/*.mod
  • simapp/go.mod is excluded by !**/*.mod
  • tests/go.mod is excluded by !**/*.mod
  • x/accounts/defaults/lockup/go.mod is excluded by !**/*.mod
  • x/accounts/go.mod is excluded by !**/*.mod
  • x/auth/go.mod is excluded by !**/*.mod
  • x/authz/go.mod is excluded by !**/*.mod
  • x/bank/go.mod is excluded by !**/*.mod
  • x/circuit/go.mod is excluded by !**/*.mod
  • x/consensus/go.mod is excluded by !**/*.mod
  • x/distribution/go.mod is excluded by !**/*.mod
  • x/epochs/go.mod is excluded by !**/*.mod
  • x/evidence/go.mod is excluded by !**/*.mod
  • x/feegrant/go.mod is excluded by !**/*.mod
  • x/gov/go.mod is excluded by !**/*.mod
  • x/group/go.mod is excluded by !**/*.mod
  • x/mint/go.mod is excluded by !**/*.mod
  • x/nft/go.mod is excluded by !**/*.mod
  • x/params/go.mod is excluded by !**/*.mod
  • x/protocolpool/go.mod is excluded by !**/*.mod
  • x/slashing/go.mod is excluded by !**/*.mod
  • x/staking/go.mod is excluded by !**/*.mod
  • x/upgrade/go.mod is excluded by !**/*.mod
Files selected for processing (1)
  • x/accounts/genesis_test.go (2 hunks)
Additional context used
Path-based instructions (1)
x/accounts/genesis_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Learnings (1)
x/accounts/genesis_test.go (1)
User: likhita-809
PR: cosmos/cosmos-sdk#18471
File: x/protocolpool/keeper/genesis.go:12-51
Timestamp: 2023-11-22T12:32:39.368Z
Learning: - The user `likhita-809` has confirmed the changes suggested in the previous interaction.
- The file in question is `x/protocolpool/keeper/genesis.go` from a Cosmos SDK module.
- The changes involve optimizing the `InitGenesis` function by removing redundant code and ensuring proper handling of start times for budget proposals.
golangci-lint
x/accounts/genesis_test.go

9-9: use of internal package cosmossdk.io/x/accounts/internal/implementation not allowed (typecheck)

Additional comments not posted (2)
x/accounts/genesis_test.go (2)

38-41: Ensure consistent error handling in newKeeper as previously noted.


14-17: Ensure consistent error handling in newKeeper.

Verification successful

Ensure consistent error handling in newKeeper.

The extracted code segments show that the newKeeper function is used in multiple test files, and error handling appears to be consistent across these usages. Specifically, errors are checked using require.NoError(t, err) after the newKeeper function is called.

  • x/accounts/msg_server_test.go
  • x/accounts/keeper_test.go
  • x/accounts/query_server_test.go
  • x/accounts/genesis_test.go
  • x/accounts/utils_test.go

The error handling in these files is consistent with the pattern observed in the genesis_test.go file.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `newKeeper` function handles errors consistently across the codebase.

# Test: Search for the function usage. Expect: Consistent error handling.
rg --type go $'newKeeper'

Length of output: 1043



Script:

#!/bin/bash
# Extract relevant code segments around the `newKeeper` calls in each file to verify error handling.

# Extract 5 lines before and after the `newKeeper` call in each file.
rg --type go -A 5 -B 5 'newKeeper' x/accounts/utils_test.go x/accounts/query_server_test.go x/accounts/keeper_test.go x/accounts/genesis_test.go x/accounts/msg_server_test.go

Length of output: 5864

Comment on lines +22 to +28
_, addr1, err := k.Init(ctx, testAccountType, []byte("sender"), &types.Empty{}, nil)
require.NoError(t, err)
_, err = k.Execute(ctx, addr1, []byte("sender"), &types.UInt64Value{Value: 10}, nil)
require.NoError(t, err)

// we set counter to 20
_, addr2, err := k.Init(ctx, "test", []byte("sender"), &types.Empty{}, nil)
_, addr2, err := k.Init(ctx, testAccountType, []byte("sender"), &types.Empty{}, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor repeated code for account initialization and execution.

- _, addr1, err := k.Init(ctx, testAccountType, []byte("sender"), &types.Empty{}, nil)
- require.NoError(t, err)
- _, err = k.Execute(ctx, addr1, []byte("sender"), &types.UInt64Value{Value: 10}, nil)
- require.NoError(t, err)
- _, addr2, err := k.Init(ctx, testAccountType, []byte("sender"), &types.Empty{}, nil)
- require.NoError(t, err)
- _, err = k.Execute(ctx, addr2, []byte("sender"), &types.UInt64Value{Value: 20}, nil)
- require.NoError(t, err)
+ for i, value := range []uint64{10, 20} {
+     _, addr, err := k.Init(ctx, testAccountType, []byte("sender"), &types.Empty{}, nil)
+     require.NoError(t, err)
+     _, err = k.Execute(ctx, addr, []byte("sender"), &types.UInt64Value{Value: value}, nil)
+     require.NoError(t, err)
+     if i == 0 {
+         addr1 = addr
+     } else {
+         addr2 = addr
+     }
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
_, addr1, err := k.Init(ctx, testAccountType, []byte("sender"), &types.Empty{}, nil)
require.NoError(t, err)
_, err = k.Execute(ctx, addr1, []byte("sender"), &types.UInt64Value{Value: 10}, nil)
require.NoError(t, err)
// we set counter to 20
_, addr2, err := k.Init(ctx, "test", []byte("sender"), &types.Empty{}, nil)
_, addr2, err := k.Init(ctx, testAccountType, []byte("sender"), &types.Empty{}, nil)
for i, value := range []uint64{10, 20} {
_, addr, err := k.Init(ctx, testAccountType, []byte("sender"), &types.Empty{}, nil)
require.NoError(t, err)
_, err = k.Execute(ctx, addr, []byte("sender"), &types.UInt64Value{Value: value}, nil)
require.NoError(t, err)
if i == 0 {
addr1 = addr
} else {
addr2 = addr
}
}

@@ -6,26 +6,26 @@
"github.com/cosmos/gogoproto/types"
"github.com/stretchr/testify/require"

"cosmossdk.io/collections/colltest"
"cosmossdk.io/x/accounts/internal/implementation"
Copy link
Contributor

Choose a reason for hiding this comment

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

Use of internal package not allowed.

- import "cosmossdk.io/x/accounts/internal/implementation"
+ // Consider refactoring to avoid using internal packages directly.

Committable suggestion was skipped due to low confidence.

Tools
golangci-lint

9-9: use of internal package cosmossdk.io/x/accounts/internal/implementation not allowed (typecheck)

@tac0turtle
Copy link
Member

can we make sure codecov is above 70% and its added to the go.work.example file

@testinginprod
Copy link
Contributor Author

can we make sure codecov is above 70% and its added to the go.work.example file

codecov is at +80%, added to go work!

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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dc743b7 and dd79f90.

Files selected for processing (2)
  • core/testing/context.go (1 hunks)
  • go.work.example (1 hunks)
Files skipped from review due to trivial changes (1)
  • go.work.example
Additional context used
Path-based instructions (1)
core/testing/context.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

golangci-lint
core/testing/context.go

24-24: func unwrap is unused (unused)

Additional comments not posted (3)
core/testing/context.go (3)

11-18: The implementation of Context() function looks good and adheres to the intended functionality of creating a dummy context for testing.


20-22: The dummyCtx struct is well-defined and supports the functionality required for testing with dummy contexts.


24-31: The function unwrap is currently marked as unused. If this function is intended for future use or external use not visible in this context, please ensure it is appropriately documented or utilized to avoid confusion.

Verification successful

The unwrap function in core/testing/context.go is indeed used in other parts of the codebase, specifically in core/testing/store.go and core/testing/services_test.go. This confirms that the function is not unused.

  • core/testing/store.go:11
  • core/testing/store.go:22
  • core/testing/services_test.go:32
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of the `unwrap` function in the codebase.

# Test: Search for the function usage. Expect: At least one occurrence.
rg --type go $'unwrap'

Length of output: 101398



Script:

#!/bin/bash
# Description: Verify the exact usage of the `unwrap` function in relevant files.

# Test: Search for the `unwrap` function calls in specific files.
rg --type go --word-regexp --line-number 'unwrap' core/testing/store.go core/testing/services_test.go core/testing/context.go

Length of output: 407

Tools
golangci-lint

24-24: func unwrap is unused (unused)

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

@testinginprod
Copy link
Contributor Author

@julienrbrt I've addressed your review, lmk if all is fine.

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 (1)
core/testing/CHANGELOG.md (1)

Line range hint 39-39: Reduce multiple consecutive blank lines to a single blank line.

- ## [Unreleased]
- 
+ ## [Unreleased]
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dd79f90 and 9e1b33b.

Files selected for processing (5)
  • .github/dependabot.yml (1 hunks)
  • .github/pr_labeler.yml (1 hunks)
  • .github/workflows/test.yml (1 hunks)
  • core/testing/CHANGELOG.md (1 hunks)
  • core/testing/sonar-project.properties (1 hunks)
Files skipped from review due to trivial changes (2)
  • .github/pr_labeler.yml
  • core/testing/sonar-project.properties
Additional context used
Path-based instructions (1)
core/testing/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Markdownlint
core/testing/CHANGELOG.md

39-39: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines

Additional comments not posted (1)
.github/dependabot.yml (1)

64-72: The new dependabot configuration for /core/testing is correctly set up.

Comment on lines +338 to +367
test-coretesting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
check-latest: true
cache: true
cache-dependency-path: core/testing/go.sum
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
core/testing/**/*.go
core/testing/go.mod
core/testing/go.sum
- name: tests
if: env.GIT_DIFF
run: |
cd core/testing
go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock' ./...
- name: sonarcloud
if: ${{ env.GIT_DIFF && !github.event.pull_request.draft && env.SONAR_TOKEN != null }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: core/testing/
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The Go version used in the test-coretesting job is 1.20, while all other test jobs use 1.22. To maintain consistency and avoid potential discrepancies during runtime, please update the Go version in the test-coretesting job to 1.22.

  • File: .github/workflows/test.yml
  • Lines: 342-345
  • Current Configuration:
    - uses: actions/setup-go@v5
      with:
        go-version: "1.20"
        check-latest: true
        cache: true
        cache-dependency-path: core/testing/go.sum

Category:

Analysis chain

The configuration for the test-coretesting job appears well-integrated with the existing workflow structure. However, ensure that the Go version (1.20) used here aligns with the versions used in other test jobs, which are mostly 1.22. This consistency is crucial for avoiding potential discrepancies during runtime due to version differences.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify Go version consistency across all test jobs.

# Test: Search for Go version settings in test jobs. Expect: Consistent version across all jobs.
rg --type yaml 'go-version: "1.22"' .github/workflows/test.yml

Length of output: 1021

@tac0turtle
Copy link
Member

Some consensus tests are failing due to other changes. It seems to be from the tx validator or @julienrbrt

@julienrbrt
Copy link
Member

Some consensus tests are failing due to other changes. It seems to be from the tx validator or @julienrbrt

Yes, it's missing a x/tx replace there

@testinginprod
Copy link
Contributor Author

probably a merge conflict that I did not resolve correctly, should be fixed now.

@testinginprod testinginprod added this pull request to the merge queue Jun 5, 2024
@testinginprod testinginprod removed this pull request from the merge queue due to a manual request Jun 5, 2024
@testinginprod testinginprod enabled auto-merge June 5, 2024 22:03
@testinginprod testinginprod added this pull request to the merge queue Jun 5, 2024
Merged via the queue into main with commit fe22e9a Jun 5, 2024
83 of 86 checks passed
@testinginprod testinginprod deleted the tip/coretest-init branch June 5, 2024 22:15
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.

7 participants