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

delete CHAIN_TYPE prefix from batch info chain type #128

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

sh-cha
Copy link
Contributor

@sh-cha sh-cha commented Dec 13, 2024

Summary by CodeRabbit

  • New Features

    • Simplified naming for BatchInfo chain types to enhance clarity and consistency.
  • Bug Fixes

    • Updated validation logic for ChainType in various message structures to reflect new naming conventions.
  • Tests

    • Adjusted test cases to utilize updated BatchInfo chain type constants, ensuring consistency across the test suite.
  • Chores

    • Streamlined JSON marshaling and unmarshaling processes for BatchInfo_ChainType, removing unnecessary complexity.

@sh-cha sh-cha self-assigned this Dec 13, 2024
@sh-cha sh-cha requested a review from a team as a code owner December 13, 2024 05:29
Copy link

coderabbitai bot commented Dec 13, 2024

Walkthrough

This pull request includes significant changes to the BatchInfo_ChainType enum and related structures across multiple files. The primary focus is on renaming enum values to remove the "CHAIN_TYPE_" prefix for clarity and consistency. Corresponding updates are made to the handling of these enums in various methods and tests, ensuring that the new names are correctly reflected throughout the codebase. Additionally, modifications are made to the validation logic and JSON marshaling processes, streamlining the representation of the BatchInfo structure without altering its functionality.

Changes

File Path Change Summary
api/opinit/ophost/v1/types.pulsar.go Renamed enum values in BatchInfo_ChainType from CHAIN_TYPE_ prefix to simplified names. Updated corresponding maps and GetChainType method.
contrib/launchtools/config.go Changed BatchSubmissionTarget type from ophosttypes.BatchInfo_ChainType to ophosttypes.BatchInfo. Updated logic in Finalize method.
contrib/launchtools/config_test.go Updated BatchSubmissionTarget value in tests from ophosttypes.BatchInfo_CHAIN_TYPE_CELESTIA to ophosttypes.BatchInfo_CELESTIA.
contrib/launchtools/utils/address.go Updated case statements in DeriveDAAddress function to use new enum names.
proto/opinit/ophost/v1/types.proto Renamed enum values in BatchInfo message from CHAIN_TYPE_ prefix to simplified names.
x/opchild/keeper/genesis_test.go Updated ChainType field in BatchInfo from ophosttypes.BatchInfo_CHAIN_TYPE_INITIA to ophosttypes.BatchInfo_INITIA.
x/opchild/keeper/msg_server_test.go Adjusted ChainType in BridgeInfo structure from ophosttypes.BatchInfo_CHAIN_TYPE_INITIA to ophosttypes.BatchInfo_INITIA. Enhanced error handling in tests.
x/opchild/keeper/querier_test.go Updated ChainType in BatchInfo from ophosttypes.BatchInfo_CHAIN_TYPE_INITIA to ophosttypes.BatchInfo_INITIA.
x/ophost/keeper/batch_info_test.go Updated ChainType in BatchInfo instances from types.BatchInfo_CHAIN_TYPE_INITIA to types.BatchInfo_INITIA and types.BatchInfo_CHAIN_TYPE_CELESTIA to types.BatchInfo_CELESTIA.
x/ophost/keeper/bridge_test.go Updated BatchInfo field in BridgeConfig from types.BatchInfo_CHAIN_TYPE_INITIA to types.BatchInfo_INITIA.
x/ophost/keeper/genesis_test.go Updated ChainType in BatchInfo for BridgeConfig and BatchInfoWithOutput from types.BatchInfo_CHAIN_TYPE_INITIA to types.BatchInfo_INITIA.
x/ophost/keeper/msg_server.go Adjusted emission of BatchChainType in CreateBridge and UpdateBatchInfo methods to use String() instead of StringWithoutPrefix().
x/ophost/keeper/msg_server_test.go Updated ChainType in BatchInfo across multiple test functions from types.BatchInfo_CHAIN_TYPE_INITIA to types.BatchInfo_INITIA.
x/ophost/keeper/output_test.go Updated ChainType in BatchInfo across multiple test functions from types.BatchInfo_CHAIN_TYPE_INITIA to types.BatchInfo_INITIA.
x/ophost/keeper/querier_test.go Updated ChainType in BatchInfo across multiple test functions, including newBatchInfo variable.
x/ophost/types/bridge_config.go Renamed constants in validation methods for BatchInfo_ChainType and updated JSON marshaling logic. Removed jsonpb methods.
x/ophost/types/bridge_config_test.go Updated references to BatchInfo_CHAIN_TYPE_* constants to new simplified names.
x/ophost/types/tx.go Updated validation logic in MsgUpdateBatchInfo struct to use new constant names for ChainType.

Possibly related PRs

Suggested reviewers

  • beer-1

🐰 In the meadow where changes bloom,
The enums dance, dispelling gloom.
No more "CHAIN_TYPE" to be found,
Just simple names, clarity abound.
With tests refined and logic clear,
We hop along, full of cheer! 🐇✨


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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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

codecov bot commented Dec 13, 2024

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 49.41%. Comparing base (f0c2a63) to head (54c9bd7).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
x/ophost/types/bridge_config.go 75.00% 1 Missing ⚠️
x/ophost/types/tx.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #128      +/-   ##
==========================================
- Coverage   49.43%   49.41%   -0.03%     
==========================================
  Files          57       57              
  Lines        4262     4256       -6     
==========================================
- Hits         2107     2103       -4     
+ Misses       1722     1720       -2     
  Partials      433      433              
Files with missing lines Coverage Δ
x/ophost/keeper/msg_server.go 56.60% <100.00%> (ø)
x/ophost/types/bridge_config.go 24.19% <75.00%> (-3.75%) ⬇️
x/ophost/types/tx.go 10.50% <0.00%> (ø)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
x/ophost/keeper/bridge_test.go (1)

20-20: LGTM! Consider adding negative test cases.

The enum value updates from BatchInfo_CHAIN_TYPE_INITIA to BatchInfo_INITIA are consistent across all test cases.

Consider adding test cases to verify handling of invalid chain types to ensure proper validation:

func Test_InvalidBridgeConfig(t *testing.T) {
    ctx, input := createDefaultTestInput(t)
    config := types.BridgeConfig{
        // ... other fields ...
        BatchInfo: types.BatchInfo{
            Submitter:  addrsStr[0],
            ChainType: types.BatchInfo_UNSPECIFIED, // or invalid value
        },
    }
    err := input.OPHostKeeper.SetBridgeConfig(ctx, 1, config)
    require.Error(t, err)
    require.Contains(t, err.Error(), "invalid chain type")
}

Also applies to: 37-37, 46-46

x/ophost/keeper/querier_test.go (1)

22-22: LGTM! Consider adding edge case tests.

The BatchInfo.ChainType enum value changes are consistently applied across all query tests. While the current coverage is good, consider adding edge cases:

  1. Invalid chain type values
  2. Chain type conversion errors
  3. Empty/nil chain type handling

Also applies to: 49-49, 58-58, 192-192, 268-268, 274-274

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ed9c06 and 54c9bd7.

⛔ Files ignored due to path filters (1)
  • x/ophost/types/types.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (18)
  • api/opinit/ophost/v1/types.pulsar.go (3 hunks)
  • contrib/launchtools/config.go (1 hunks)
  • contrib/launchtools/config_test.go (1 hunks)
  • contrib/launchtools/utils/address.go (1 hunks)
  • proto/opinit/ophost/v1/types.proto (1 hunks)
  • x/opchild/keeper/genesis_test.go (1 hunks)
  • x/opchild/keeper/msg_server_test.go (2 hunks)
  • x/opchild/keeper/querier_test.go (1 hunks)
  • x/ophost/keeper/batch_info_test.go (5 hunks)
  • x/ophost/keeper/bridge_test.go (3 hunks)
  • x/ophost/keeper/genesis_test.go (6 hunks)
  • x/ophost/keeper/msg_server.go (2 hunks)
  • x/ophost/keeper/msg_server_test.go (11 hunks)
  • x/ophost/keeper/output_test.go (3 hunks)
  • x/ophost/keeper/querier_test.go (5 hunks)
  • x/ophost/types/bridge_config.go (4 hunks)
  • x/ophost/types/bridge_config_test.go (3 hunks)
  • x/ophost/types/tx.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • x/ophost/keeper/msg_server.go
🔇 Additional comments (17)
contrib/launchtools/config_test.go (1)

20-20: LGTM! Verify other enum usages.

The enum value update from BatchInfo_CHAIN_TYPE_CELESTIA to BatchInfo_CELESTIA is consistent with the PR objective.

Let's verify that all enum usages have been updated consistently:

✅ Verification successful

All enum usages have been updated correctly

The search results confirm that all usages of the BatchInfo enum are using the new CELESTIA value without the CHAIN_TYPE_ prefix. This includes:

  • Proto-generated code in types.pb.go
  • Test files across different packages
  • Configuration and utility code
  • API definitions

No instances of the old CHAIN_TYPE_CELESTIA enum value were found, indicating the update has been applied consistently throughout the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining CHAIN_TYPE prefixes in enum values
rg -i "CHAIN_TYPE_" --type go

Length of output: 29


Script:

#!/bin/bash
# Let's first find all files that might contain BatchInfo enum definitions or usages
rg -l "BatchInfo" --type go

# Then let's look for any enum values with CELESTIA to see the context
rg "CELESTIA" --type go

Length of output: 3684

x/opchild/keeper/genesis_test.go (1)

44-44: LGTM! Genesis state handling is preserved.

The enum value update from BatchInfo_CHAIN_TYPE_INITIA to BatchInfo_INITIA is consistent with the PR objective and the genesis state handling remains correct.

contrib/launchtools/utils/address.go (1)

50-52: LGTM! Enum values correctly updated

The switch cases have been properly updated to use the new enum values without the "CHAIN_TYPE_" prefix, maintaining the same functionality.

x/ophost/keeper/batch_info_test.go (1)

15-15: LGTM! Test cases properly updated

All BatchInfo struct initializations have been consistently updated to use the new enum values without the "CHAIN_TYPE_" prefix. The test cases maintain their original functionality and coverage.

Also applies to: 28-28, 41-41, 54-54, 67-67

x/ophost/types/bridge_config.go (2)

22-22: LGTM! Validation logic properly updated

The validation methods have been correctly updated to use the new enum value BatchInfo_UNSPECIFIED. The additional validation for chain type values remains intact.

Also applies to: 54-57


81-81: LGTM! JSON handling simplified

The JSON marshaling and unmarshaling have been streamlined:

  • Using standard String() method for marshaling
  • Simplified unmarshaling by directly using the uppercase string value

Also applies to: 92-97

proto/opinit/ophost/v1/types.proto (1)

70-74: LGTM! Enum values simplified for better readability

The removal of the "CHAIN_TYPE_" prefix from enum values improves code clarity while maintaining the same functionality. The numeric values and descriptions remain unchanged.

x/ophost/types/bridge_config_test.go (1)

23-23: LGTM! Test cases updated consistently

All references to chain type enums have been updated to use the new simplified names while maintaining the same test coverage and validation logic.

Also applies to: 44-44, 51-51, 84-84

x/opchild/keeper/querier_test.go (1)

63-63: LGTM! Chain type reference updated consistently

The enum reference has been updated to use the new simplified name while maintaining the same test functionality.

x/ophost/keeper/output_test.go (1)

93-93: LGTM! Verify enum usage consistency.

The BatchInfo.ChainType enum value changes are consistent across all test functions, maintaining test coverage and correctness.

Also applies to: 152-152, 199-199

✅ Verification successful

Enum usage is consistent across the codebase

The verification confirms that:

  • No instances of old enum values (BatchInfo_CHAIN_TYPE_) were found
  • The new enum value (BatchInfo_INITIA) is consistently used across all relevant files:
    • Test files in x/ophost module
    • Generated protobuf files
    • Child module (x/opchild) references
    • Launch tools configuration
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent usage of new enum values across the codebase
# Expect: Only new enum values (BatchInfo_INITIA) should be found, no old values (BatchInfo_CHAIN_TYPE_INITIA)

# Check for any remaining old enum values
rg "BatchInfo_CHAIN_TYPE_" 

# Verify consistent usage of new enum values
rg "BatchInfo_INITIA"

Length of output: 5284

x/ophost/keeper/genesis_test.go (1)

22-22: LGTM! Genesis state handling remains intact.

The BatchInfo.ChainType enum value changes are consistently applied across genesis export and import/export tests. The tests continue to verify correct state handling with both INITIA and CELESTIA chain types.

Also applies to: 31-31, 70-72, 103-105, 170-172

✅ Verification successful

LGTM! The BatchInfo.ChainType changes are consistently tested

The verification shows comprehensive test coverage for both BatchInfo_INITIA and BatchInfo_CELESTIA chain types across multiple test files:

  • Genesis tests properly verify state import/export with both chain types
  • Message server tests cover chain type updates and validations
  • Bridge configuration tests include both chain types
  • Batch info tests verify handling of both chain types
  • Test coverage spans across different packages (ophost, opchild)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify test coverage for genesis state handling
# Expect: Test cases should cover both chain types

# Check test coverage for both chain types
rg -B 2 -A 2 "BatchInfo_INITIA|BatchInfo_CELESTIA" --type go

Length of output: 19356

x/ophost/types/tx.go (1)

374-374: LGTM: Enum value renamed correctly

The change from BatchInfo_CHAIN_TYPE_UNSPECIFIED to BatchInfo_UNSPECIFIED is consistent with the PR objective of removing the CHAIN_TYPE prefix while maintaining the same validation logic.

contrib/launchtools/config.go (1)

140-149: LGTM: Enum values renamed consistently

The changes align with the PR objective of removing the CHAIN_TYPE prefix:

  • BatchInfo_UNSPECIFIED for unspecified chain type
  • BatchInfo_CELESTIA for Celestia chain type
  • BatchInfo_INITIA for Initia chain type

The interactive prompt logic remains unchanged.

x/ophost/keeper/msg_server_test.go (1)

42-42: LGTM: Test cases updated consistently

All test cases have been updated to use the new enum values without the CHAIN_TYPE prefix. The changes maintain the same test coverage and functionality while using the simplified enum names.

Also applies to: 67-67, 105-105, 168-168, 196-196, 268-268, 318-318, 368-368, 380-380, 393-393, 400-400, 408-408, 430-430, 475-475

x/opchild/keeper/msg_server_test.go (2)

295-297: LGTM! Enum value correctly updated

The change from BatchInfo_CHAIN_TYPE_INITIA to BatchInfo_INITIA aligns with the simplified enum naming convention while maintaining the same functionality.


347-349: LGTM! Enum value correctly updated

The change from BatchInfo_CHAIN_TYPE_INITIA to BatchInfo_INITIA is consistent with the simplified enum naming convention.

api/opinit/ophost/v1/types.pulsar.go (1)

3485-3489: LGTM! Enum values consistently renamed

The BatchInfo_ChainType enum values have been simplified by removing the redundant "CHAIN_TYPE_" prefix. The changes are consistent across all definitions and references, including:

  • Enum value definitions
  • Name/value mapping tables
  • Default value reference

This improves code readability while maintaining the same functionality.

Also applies to: 3495-3502, 3714-3714

Copy link
Member

@beer-1 beer-1 left a comment

Choose a reason for hiding this comment

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

LGTM, but good to test this update does not affect any client programs like initia.js or launch cmd or weavecli before merging this.

Copy link
Member

@beer-1 beer-1 left a comment

Choose a reason for hiding this comment

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

I have checked, it does not affect to client side.

@beer-1 beer-1 merged commit 7da22a7 into main Dec 17, 2024
9 checks passed
@beer-1 beer-1 deleted the fix/change-chain-type-name branch December 17, 2024 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants