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

fix cosmos messages #158

Merged
merged 1 commit into from
Oct 31, 2024
Merged

fix cosmos messages #158

merged 1 commit into from
Oct 31, 2024

Conversation

beer-1
Copy link
Member

@beer-1 beer-1 commented Oct 31, 2024

Description

Closes: #XXXX


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
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • 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.

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 base64 encoding for arguments in various test functions and request structures, enhancing data handling capabilities.
    • Updated request structures to clarify field names, improving clarity and interoperability.
  • Bug Fixes

    • Adjusted expected data formats in tests to align with new specifications for Cosmos message formats.
  • Documentation

    • Updated comments and documentation to reflect changes in data encoding and structure.

@beer-1 beer-1 self-assigned this Oct 31, 2024
@beer-1 beer-1 requested a review from a team as a code owner October 31, 2024 05:31
Copy link

coderabbitai bot commented Oct 31, 2024

Walkthrough

The pull request introduces modifications across multiple files to incorporate base64 encoding for various data types. A new dependency, base64, is added to the Cargo.toml file for the e2e-move-tests package. Changes are made to the cosmos.rs test file to replace hexadecimal encoding with base64 encoding for certain arguments. Additionally, the initia_stdlib and minitia_stdlib modules are updated to reflect these changes, including adjustments to data structures and function signatures to accommodate base64 encoded strings.

Changes

File Path Change Summary
crates/e2e-move-tests/Cargo.toml Added dependency: base64 = { workspace = true }
crates/e2e-move-tests/src/tests/cosmos.rs Updated test functions to use base64 encoding for arg1 and arg2; modified expected data format keys.
precompile/modules/initia_stdlib/sources/cosmos.move Changed args fields to vector<String> for base64 encoding; updated code_bytes to String; renamed fields in PayFeeRequest.
precompile/modules/minitia_stdlib/sources/cosmos.move Changed args fields to vector<String> for base64 encoding; updated code_bytes to String; renamed fields in PayFeeRequest.

Possibly related PRs

🐰 In the meadow, a change takes flight,
Base64 now shines, oh what a sight!
Arguments transformed, clear and bright,
With each little hop, we code with delight!
Encoding anew, our tests take a leap,
In the world of data, our promises we keep! 🌼


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

@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 (1)
crates/e2e-move-tests/src/tests/cosmos.rs (1)

446-448: LGTM! Base64 encoding is correctly implemented.

The implementation correctly uses the standard base64 engine for encoding binary data.

Consider extracting the base64 engine initialization to avoid repetition. Here's a suggested implementation:

// At the top of the file with other constants
const BASE64: base64::engine::GeneralPurpose = base64::engine::general_purpose::STANDARD;

Then replace the repeated initialization with the constant:

-    let base64 = base64::engine::general_purpose::STANDARD;
-    let arg1_base64 = base64.encode(arg1.clone());
+    let arg1_base64 = BASE64.encode(arg1.clone());

Also applies to: 537-540, 581-582

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7d2dbd5 and 2b04af7.

📒 Files selected for processing (4)
  • crates/e2e-move-tests/Cargo.toml (1 hunks)
  • crates/e2e-move-tests/src/tests/cosmos.rs (5 hunks)
  • precompile/modules/initia_stdlib/sources/cosmos.move (9 hunks)
  • precompile/modules/minitia_stdlib/sources/cosmos.move (9 hunks)
🔇 Additional comments (10)
crates/e2e-move-tests/Cargo.toml (1)

25-25: Verify workspace configuration for base64 dependency.

The addition of the base64 dependency is aligned with the codebase's dependency management approach and supports the transition from hex to base64 encoding for cosmos messages.

Let's verify the workspace configuration:

✅ Verification successful

Base64 dependency is properly configured in workspace

The base64 dependency is correctly configured in the workspace's dependencies section with version "0.21.7", and the e2e-move-tests crate properly references it using workspace = true. This addition is consistent with the workspace's dependency management approach and supports the transition from hex to base64 encoding for cosmos messages.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify base64 dependency configuration in workspace
# Expected: base64 should be defined in workspace dependencies

# Check if base64 is properly configured in workspace
rg '"base64"' -A 1 Cargo.toml

# Verify no duplicate base64 dependencies exist
rg 'base64.*=.*{.*}' **/Cargo.toml

Length of output: 208


Script:

#!/bin/bash
# Let's try a different approach to verify the workspace configuration

# Check workspace dependencies in root Cargo.toml
echo "=== Checking workspace dependencies ==="
cat Cargo.toml

# List all Cargo.toml files that mention base64
echo -e "\n=== Finding base64 usage across Cargo.toml files ==="
rg -l "base64" **/Cargo.toml

# Check the specific content of e2e-move-tests/Cargo.toml
echo -e "\n=== Checking e2e-move-tests/Cargo.toml ==="
cat crates/e2e-move-tests/Cargo.toml

Length of output: 9418

precompile/modules/initia_stdlib/sources/cosmos.move (3)

14-14: LGTM! Base64 encoding changes are well-documented.

The changes to use base64 encoded strings instead of raw bytes are consistent and well-documented. The field type changes in the structs and the addition of the base64 module import align with the goal of standardizing base64 encoding across the codebase.

Also applies to: 82-82, 147-147, 149-149, 177-177


93-93: Verify base64 encoding compatibility with external systems.

The implementation of base64 encoding is correct and consistent across all functions. The use of vector::map for encoding arrays of arguments is an efficient approach.

Let's verify that the base64 encoding implementation matches the encoding used in the test files:

Also applies to: 158-159, 188-188

✅ Verification successful

Based on the search results, I can now provide a conclusive response about the base64 encoding implementation:

Base64 encoding implementation is verified and consistent with external systems

The implementation is verified to be compatible with external systems because:

  • The base64 module is implemented as a native function using the standard base64 encoding (STANDARD variant) in the Rust implementation
  • The encoding is consistently used in both test files and production code
  • The e2e tests verify the encoding compatibility by comparing encoded values between Move and Rust implementations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for base64 encoding usage in test files to verify consistency
rg -A 3 "base64.*encode" "tests/"

Length of output: 80


Script:

#!/bin/bash
# Let's first find test files in the repository
fd -t f "test" -E "node_modules"

# Then search for base64 usage across all files
rg -g "!node_modules" "base64" -A 3

Length of output: 27884


364-365: Verify impact of breaking field name changes in PayFeeRequest.

The renaming of fields from source_port/source_channel to source_port_id/source_channel_id improves clarity but introduces a breaking change.

Let's verify the impact on dependent code:

Also applies to: 389-390

✅ Verification successful

Field renaming in PayFeeRequest is consistently applied across the codebase

The field renaming from source_port/source_channel to source_port_id/source_channel_id has been consistently applied in both the initia and minitia stdlib modules. The struct is only defined and used within these modules, with no instances of the old field names remaining in the codebase.

  • precompile/modules/initia_stdlib/sources/cosmos.move: Updated struct definition and usage
  • precompile/modules/minitia_stdlib/sources/cosmos.move: Matching changes in minitia stdlib
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of the old field names to ensure all occurrences are updated
rg -l "source_port[^_]|source_channel[^_]" --type move

Length of output: 85


Script:

#!/bin/bash
# Search for any occurrences of the old or new field names without file type restriction
rg -l "source_port|source_channel"

Length of output: 280


Script:

#!/bin/bash
# Search for struct PayFeeRequest to understand its usage
rg -A 5 "struct PayFeeRequest"

Length of output: 1031


Script:

#!/bin/bash
# Search for PayFeeRequest instantiation or field access
rg "PayFeeRequest"

Length of output: 382

precompile/modules/minitia_stdlib/sources/cosmos.move (4)

14-14: LGTM: Base64 import added for standardized binary encoding.

The addition of the base64 module import aligns with the PR's objective to standardize binary data encoding across the codebase.


82-82: LGTM: Request structures updated to use base64 encoded strings.

The changes consistently update binary data fields to use base64 encoded strings, improving data handling consistency across the module. The added comments clearly indicate the expected encoding format.

Also applies to: 147-149, 177-177


364-365: LGTM: Field names improved for clarity.

The renaming of fields from source_port/source_channel to source_port_id/source_channel_id improves clarity and better reflects their purpose in the ICS-29 specification.

Also applies to: 389-390


93-93: Verify base64 encoding transformation correctness.

The implementation correctly transforms binary data to base64 encoded strings. However, we should verify that all consumers of these functions are prepared to handle base64 encoded data.

Also applies to: 158-159, 188-188

✅ Verification successful

Base64 encoding transformation is correctly integrated

The base64 encoding changes are consistent and properly integrated:

  • All base64 encoding operations use base64::to_string() uniformly
  • The encoding is used in both minitia and initia stdlib modules
  • The encoded data is passed to stargate() function which expects base64 encoded strings
  • Other modules like minitswap.move already use the same base64 encoding pattern for their data
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct callers of these functions to verify they handle base64 encoded data
echo "Searching for move_execute callers..."
rg -l "move_execute.*vector<u8>" --type move

echo "Searching for move_script callers..."
rg -l "move_script.*vector<u8>" --type move

echo "Searching for move_script_with_json callers..."
rg -l "move_script_with_json.*vector<u8>" --type move

Length of output: 506


Script:

#!/bin/bash
# Search for direct callers of these functions without file type restriction
echo "Searching for move_execute callers..."
rg -l "move_execute.*vector" -g "*.move"

echo "Searching for move_script callers..."
rg -l "move_script.*vector" -g "*.move"

echo "Searching for move_script_with_json callers..."
rg -l "move_script_with_json.*vector" -g "*.move"

# Also search for base64 usage to understand encoding/decoding patterns
echo "Searching for base64 usage..."
rg "base64::(encode|decode|to_string|from_string)" -g "*.move" -A 2

Length of output: 2902

crates/e2e-move-tests/src/tests/cosmos.rs (2)

11-11: LGTM! Base64 import is correctly structured.

The import brings in both the base64 module and the Engine trait, which is necessary for the encoding operations.


401-401: LGTM! Field names updated for consistency with Cosmos SDK.

The field names source_channel_id and source_port_id now match the standard Cosmos SDK message format.

Copy link
Contributor

@sh-cha sh-cha left a comment

Choose a reason for hiding this comment

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

lgtm

@beer-1 beer-1 merged commit 6ebb22a into main Oct 31, 2024
5 of 6 checks passed
@beer-1 beer-1 deleted the fix/cosmos-messages branch October 31, 2024 05:54
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