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

Problem: url encoded characters are not properly handled in contract_by_denom #1560

Merged
merged 3 commits into from
Aug 30, 2024

Conversation

mmsqe
Copy link
Collaborator

@mmsqe mmsqe commented Aug 29, 2024

decode fix is in grpc-gateway v2, to avoid encode twice we can also pass denom as query string

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added support for a new token mapping in the integration configuration, enhancing compatibility with the Inter-Blockchain Communication (IBC) protocol.
  • Bug Fixes

    • Improved handling of URL-encoded characters in the contract querying API, ensuring accurate contract retrieval and clearer error reporting.
  • Tests

    • Enhanced the test suite with new cases to verify contract querying behavior, improving the robustness of integration tests.

@mmsqe mmsqe requested a review from a team as a code owner August 29, 2024 14:25
@mmsqe mmsqe requested review from yihuang and thomas-nguy and removed request for a team August 29, 2024 14:25
Copy link
Contributor

coderabbitai bot commented Aug 29, 2024

Walkthrough

The recent changes include updates to the CHANGELOG.md to document a fix in the contract_by_denom API, modifications to the token mapping configuration in genesis_token_mapping.jsonnet, and enhancements to the test suite in test_exported_genesis.py. Additionally, significant improvements were made to the ContractByDenom function in grpc_query.go, incorporating URL decoding for the denom field to properly handle URL-encoded characters.

Changes

Files Change Summary
CHANGELOG.md Added entry for a fix related to URL-encoded characters in the contract_by_denom API.
client/docs/swagger-ui/swagger.yaml Updated API endpoint for querying contract addresses by changing denom from a path to a query parameter.
integration_tests/configs/genesis_token_mapping.jsonnet Introduced a new token mapping entry for IBC integration.
integration_tests/test_exported_genesis.py Added a new test case for querying contracts by denomination, including API requests and response validation.
proto/cronos/query.proto Enhanced comments and modified HTTP GET options for the ContractByDenom RPC method.
x/cronos/keeper/grpc_query.go Enhanced ContractByDenom function with URL decoding for the denom field and improved error handling.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant Keeper

    Client->>API: Request contract by denom
    API->>Keeper: Call ContractByDenom(req)
    Keeper->>Keeper: Decode req.Denom
    alt Decoding Successful
        Keeper->>Keeper: Query contracts with decoded denom
        Keeper-->>API: Return contract information
    else Decoding Failed
        Keeper-->>API: Return error
    end
    API-->>Client: Return response
Loading

🐇 "In the meadow, changes bloom,
New paths to hop, dispel the gloom.
With tokens mapped and tests so bright,
Contracts dance in the soft moonlight.
URL decoded, all is clear,
Hoppy days are finally here!" 🐇✨


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

codecov bot commented Aug 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.12%. Comparing base (eb0a15d) to head (1fe746a).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #1560       +/-   ##
===========================================
+ Coverage   15.24%   36.12%   +20.88%     
===========================================
  Files          67       97       +30     
  Lines        4874     7725     +2851     
===========================================
+ Hits          743     2791     +2048     
- Misses       4037     4585      +548     
- Partials       94      349      +255     

see 47 files with indirect coverage changes

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 UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eb0a15d and af4eed6.

Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • integration_tests/configs/genesis_token_mapping.jsonnet (1 hunks)
  • integration_tests/test_exported_genesis.py (2 hunks)
  • x/cronos/keeper/grpc_query.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
Additional context used
GitHub Check: codecov/patch
x/cronos/keeper/grpc_query.go

[warning] 25-27: x/cronos/keeper/grpc_query.go#L25-L27
Added lines #L25 - L27 were not covered by tests


[warning] 31-31: x/cronos/keeper/grpc_query.go#L31
Added line #L31 was not covered by tests


[warning] 35-35: x/cronos/keeper/grpc_query.go#L35
Added line #L35 was not covered by tests


[warning] 40-40: x/cronos/keeper/grpc_query.go#L40
Added line #L40 was not covered by tests

Additional comments not posted (14)
integration_tests/test_exported_genesis.py (8)

2-2: LGTM!

The import statement for urllib.parse is necessary for URL encoding/decoding.


6-6: LGTM!

The import statement for requests is necessary for making HTTP requests.


40-46: LGTM!

The test case for querying a contract by its denomination is comprehensive and ensures the correctness of the API response.


47-47: LGTM!

The code correctly retrieves the API port using the ports.api_port function.


48-49: LGTM!

The code correctly URL encodes the denomination using urllib.parse.quote to ensure it is safe for use in a URL.


50-50: LGTM!

The code correctly constructs the URL for the API request using the encoded denomination and the API port.


51-51: LGTM!

The code correctly makes the HTTP GET request to the constructed URL and retrieves the response.


52-52: LGTM!

The code correctly validates the API response against the expected output to ensure it matches.

x/cronos/keeper/grpc_query.go (5)

7-7: LGTM!

The import statement for net/url is necessary for URL decoding.


25-28: LGTM!

The code correctly URL decodes the denomination using url.QueryUnescape to ensure it is properly interpreted.

Tools
GitHub Check: codecov/patch

[warning] 25-27: x/cronos/keeper/grpc_query.go#L25-L27
Added lines #L25 - L27 were not covered by tests


31-31: LGTM!

The code correctly queries the external contract using the decoded denomination.

Tools
GitHub Check: codecov/patch

[warning] 31-31: x/cronos/keeper/grpc_query.go#L31
Added line #L31 was not covered by tests


35-35: LGTM!

The code correctly queries the auto contract using the decoded denomination.

Tools
GitHub Check: codecov/patch

[warning] 35-35: x/cronos/keeper/grpc_query.go#L35
Added line #L35 was not covered by tests


40-40: LGTM!

The code correctly handles the case when no contracts are found and returns an appropriate error message.

Tools
GitHub Check: codecov/patch

[warning] 40-40: x/cronos/keeper/grpc_query.go#L40
Added line #L40 was not covered by tests

integration_tests/configs/genesis_token_mapping.jsonnet (1)

59-62: LGTM!

The new entry expands the configuration to accommodate an additional token mapping.

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 UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between af4eed6 and 1fe746a.

Files ignored due to path filters (2)
  • x/cronos/types/query.pb.go is excluded by !**/*.pb.go
  • x/cronos/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • client/docs/swagger-ui/swagger.yaml (2 hunks)
  • integration_tests/test_exported_genesis.py (2 hunks)
  • proto/cronos/query.proto (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • CHANGELOG.md
  • integration_tests/test_exported_genesis.py
Additional comments not posted (2)
client/docs/swagger-ui/swagger.yaml (1)

Line range hint 1-1: File is empty.

There are no code changes to review in this file.

proto/cronos/query.proto (1)

15-17: LGTM!

The changes improve the semantic understanding of the method's functionality and adjust the endpoint's URL structure.

@mmsqe mmsqe added this pull request to the merge queue Aug 30, 2024
Merged via the queue into crypto-org-chain:main with commit 825c551 Aug 30, 2024
37 checks passed
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