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: yaci query #35

Merged
merged 1 commit into from
Nov 13, 2024
Merged

fix: yaci query #35

merged 1 commit into from
Nov 13, 2024

Conversation

fmorency
Copy link
Contributor

@fmorency fmorency commented Nov 12, 2024

This PR fixes the YACI query so all messages (up to 1 level deep) get processed, not only the first one.

Relates: #34
Fixes #33

Summary by CodeRabbit

  • New Features
    • Improved transaction fetching efficiency with updated query logic for MsgSend types.
    • Enhanced readability and maintainability of transaction queries.

@fmorency fmorency self-assigned this Nov 12, 2024
Copy link

coderabbitai bot commented Nov 12, 2024

Walkthrough

The changes involve modifications to the useSendTxIncludingAddressQuery and useSendTxQuery functions within the hooks/useQueries.ts file. The updates simplify the query construction for fetching MsgSend transaction messages by adopting a new collection syntax (cs). This approach replaces the previous nested structure, enhancing the clarity and maintainability of the code.

Changes

Files Change Summary
hooks/useQueries.ts Updated useSendTxIncludingAddressQuery and useSendTxQuery to use cs syntax for filtering MsgSend messages, simplifying query logic.

Assessment against linked issues

Objective Addressed Explanation
Process all messages, not only the first

🐰 In the code where queries play,
A new syntax leads the way!
Filtering messages, clear and bright,
Simplified queries bring delight!
With each change, we hop along,
Enhancing logic, making it strong! 🌟


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

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.

Project coverage is 59.40%. Comparing base (a93ab38) to head (ea49874).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
hooks/useQueries.ts 0.00% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #35      +/-   ##
==========================================
+ Coverage   59.39%   59.40%   +0.01%     
==========================================
  Files         148      148              
  Lines       13830    13826       -4     
==========================================
  Hits         8214     8214              
+ Misses       5616     5612       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

🧹 Outside diff range and nitpick comments (1)
hooks/useQueries.ts (1)

Line range hint 787-841: Add test coverage for the updated queries.

The changes involve critical query functionality but lack test coverage. Consider adding tests that verify:

  1. Direct MsgSend transactions
  2. Nested group proposal MsgSend transactions
  3. Different address scenarios (sender/receiver)
  4. Edge cases and error handling

Would you like me to help create a test suite for these scenarios?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 787-787: hooks/useQueries.ts#L787
Added line #L787 was not covered by tests


[warning] 789-792: hooks/useQueries.ts#L789-L792
Added lines #L789 - L792 were not covered by tests


[warning] 794-798: hooks/useQueries.ts#L794-L798
Added lines #L794 - L798 were not covered by tests


[warning] 800-801: hooks/useQueries.ts#L800-L801
Added lines #L800 - L801 were not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a93ab38 and ea49874.

📒 Files selected for processing (1)
  • hooks/useQueries.ts (2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
hooks/useQueries.ts

[warning] 787-787: hooks/useQueries.ts#L787
Added line #L787 was not covered by tests


[warning] 789-792: hooks/useQueries.ts#L789-L792
Added lines #L789 - L792 were not covered by tests


[warning] 794-798: hooks/useQueries.ts#L794-L798
Added lines #L794 - L798 were not covered by tests


[warning] 800-801: hooks/useQueries.ts#L800-L801
Added lines #L800 - L801 were not covered by tests


[warning] 841-841: hooks/useQueries.ts#L841
Added line #L841 was not covered by tests

@@ -842,7 +838,7 @@
export const useSendTxQuery = () => {
const fetchTransactions = async () => {
const baseUrl = 'https://testnet-indexer.liftedinit.tech/transactions';
const query = `data->tx->body->messages->0->>@type=eq./cosmos.bank.v1beta1.MsgSend`;
const query = `data->tx->body->messages.cs.[{"@type": "/cosmos.bank.v1beta1.MsgSend"}]`;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider handling nested messages consistently.

While the query works for direct MsgSend messages, it might miss transactions within group proposals. Consider updating it to match the pattern used in useSendTxIncludingAddressQuery for consistency.

-    const query = `data->tx->body->messages.cs.[{"@type": "/cosmos.bank.v1beta1.MsgSend"}]`;
+    const query = `or(
+      data->tx->body->messages.cs.[{"@type": "/cosmos.bank.v1beta1.MsgSend"}],
+      data->tx->body->messages.cs.[{"messages": [{"@type": "/cosmos.bank.v1beta1.MsgSend"}]}]
+    )`;
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const query = `data->tx->body->messages.cs.[{"@type": "/cosmos.bank.v1beta1.MsgSend"}]`;
const query = `or(
data->tx->body->messages.cs.[{"@type": "/cosmos.bank.v1beta1.MsgSend"}],
data->tx->body->messages.cs.[{"messages": [{"@type": "/cosmos.bank.v1beta1.MsgSend"}]}]
)`;
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 841-841: hooks/useQueries.ts#L841
Added line #L841 was not covered by tests

Comment on lines +787 to +801
// Build query for both direct MsgSend and nested (1 level) group proposal MsgSend
const query = `
or=(
and(
data->tx->body->messages->0->>@type.eq./cosmos.bank.v1beta1.MsgSend,
or(
data->tx->body->messages->0->>fromAddress.eq.${address},
data->tx->body->messages->0->>toAddress.eq.${address}
)
and=(
or(
data->tx->body->messages.cs.[{"@type": "/cosmos.bank.v1beta1.MsgSend"}],
data->tx->body->messages.cs.[{"messages": [{"@type": "/cosmos.bank.v1beta1.MsgSend"}]}]
),
and(
data->tx->body->messages->0->>@type.eq./cosmos.group.v1.MsgSubmitProposal,
data->tx->body->messages->0->messages->0->>@type.eq./cosmos.bank.v1beta1.MsgSend,
or(
data->tx->body->messages->0->messages->0->>fromAddress.eq.${address},
data->tx->body->messages->0->messages->0->>toAddress.eq.${address}
)
or(
data->tx->body->messages.cs.[{"fromAddress": "${address}"}],
data->tx->body->messages.cs.[{"toAddress": "${address}"}],
data->tx->body->messages.cs.[{"messages": [{"fromAddress": "${address}"}]}],
data->tx->body->messages.cs.[{"messages": [{"toAddress": "${address}"}]}]
)
)`;
)
`;
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Test coverage is missing for the updated query.

The changes in hooks/useQueries.ts do not have corresponding tests to verify the new query logic.

🔗 Analysis chain

Query implementation looks good but needs test coverage.

The updated query correctly handles both direct MsgSend and nested group proposal MsgSend messages, aligning with the PR objective. The implementation uses PostgreSQL's containment operator efficiently.

Let's verify the query structure:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for existing test files and patterns
# Look for test files
echo "Searching for test files..."
fd -e test.ts -e spec.ts

# Look for similar query patterns
echo "Searching for similar query patterns..."
rg -A 2 'data->tx->body->messages\.cs\.'

Length of output: 1186

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 787-787: hooks/useQueries.ts#L787
Added line #L787 was not covered by tests


[warning] 789-792: hooks/useQueries.ts#L789-L792
Added lines #L789 - L792 were not covered by tests


[warning] 794-798: hooks/useQueries.ts#L794-L798
Added lines #L794 - L798 were not covered by tests


[warning] 800-801: hooks/useQueries.ts#L800-L801
Added lines #L800 - L801 were not covered by tests

@fmorency fmorency merged commit 465a526 into liftedinit:main Nov 13, 2024
3 of 4 checks passed
@fmorency fmorency deleted the fix-yaci-query branch November 13, 2024 21:22
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.

Fix YACI query
1 participant