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

feat/ibc_connection_module_queries #322

Merged
merged 5 commits into from
Apr 25, 2024
Merged

Conversation

aarmoa
Copy link
Collaborator

@aarmoa aarmoa commented Apr 25, 2024

  • Added support for IBC Core Connection module queries
  • Added unit tests
  • Added example scripts

Solves CHAIN-83

Summary by CodeRabbit

  • New Features

    • Introduced new functionalities in the "IBC Connection" module to support asynchronous queries for IBC connections, client connections, client states, consensus states, and connection parameters.
    • Enhanced the async_client with new methods for improved IBC connection handling.
  • Refactor

    • Updated the cookies management logic to utilize responses from all gRPC calls for better efficiency.
  • Documentation

    • Updated CHANGELOG.md to reflect recent changes and additions.
  • Tests

    • Added new test cases for the IBCConnectionGrpcApi class, ensuring robust functionality through simulated gRPC interactions.

…e. Included example scripts and unit tests
@aarmoa aarmoa requested a review from nicolasbaum April 25, 2024 03:00
Copy link
Contributor

coderabbitai bot commented Apr 25, 2024

Walkthrough

The recent update enhances the IBC Connection module with support for various queries using asynchronous gRPC calls. It also improves cookie management logic and updates import paths in the pyinjective library.

Changes

Files Change Summary
CHANGELOG.md Added support for all queries in the "IBC Connection" module and refactored cookies management logic.
examples/chain_client/ibc/connection/query/1_Connection.py
examples/chain_client/ibc/connection/query/2_Connections.py
examples/chain_client/ibc/connection/query/3_ClientConnections.py
examples/chain_client/ibc/connection/query/4_ConnectionClientState.py
examples/chain_client/ibc/connection/query/5_ConnectionConsensusState.py
examples/chain_client/ibc/connection/query/6_ConnectionParams.py
Introduced new Python scripts for fetching IBC connection details using async clients in the Injective Protocol network.
pyinjective/async_client.py
pyinjective/core/ibc/connection/grpc/ibc_connection_grpc_api.py
Updated IBC client functionality, changed import paths, and added methods for IBC connection handling.
tests/core/ibc/client/grpc/test_ibc_client_grpc_api.py
tests/core/ibc/connection/grpc/configurable_ibc_connection_query_servicer.py
tests/core/ibc/connection/grpc/test_ibc_connection_grpc_api.py
Updated test cases for IBC client and introduced new test cases for IBC connection handling using gRPC calls.
.github/workflows/pre-commit.yml
.github/workflows/release.yml
.github/workflows/run-tests.yml
Updated GitHub Actions versions in workflow files for various tasks.

🐰🎉
A hop, a skip, a code deploy,
In the fields of gRPC, we enjoy.
New paths we trace, with async grace,
Connections link, in cyberspace.
Celebrate, for the code rabbits play! 🌟
🐰🎉


Recent Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 58f62c2 and 0631678.
Files selected for processing (1)
  • .github/workflows/run-tests.yml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/run-tests.yml

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

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

Out of diff range and nitpick comments (2)
tests/core/ibc/connection/grpc/test_ibc_connection_grpc_api.py (1)

21-23: Consider using a more descriptive name for the fixture ibc_connection_servicer to reflect its purpose more clearly.

tests/core/ibc/client/grpc/test_ibc_client_grpc_api.py (1)

8-8: Consider adding a comment above the import statement to explain why the import path was changed, especially if it was due to architectural changes or improvements.

Comment on lines +26 to +85
class TestIBCConnectionGrpcApi:
@pytest.mark.asyncio
async def test_fetch_connection(
self,
ibc_connection_servicer,
):
version = ibc_connection.Version(
identifier="connection-0",
features=["ORDER_ORDERED", "ORDER_UNORDERED"],
)
prefix = ibc_commitment.MerklePrefix(key_prefix=b"prefix")
counterparty = ibc_connection.Counterparty(
client_id="07-tendermint-0",
connection_id="connection-0",
prefix=prefix,
)
connection = ibc_connection.ConnectionEnd(
client_id="07-tendermint-0",
versions=[version],
state=3,
counterparty=counterparty,
delay_period=5,
)
proof = b"proof"
proof_height = ibc_client.Height(
revision_number=1,
revision_height=2,
)

ibc_connection_servicer.connection_responses.append(
ibc_connection_query.QueryConnectionResponse(
connection=connection,
proof=proof,
proof_height=proof_height,
)
)

api = self._api_instance(servicer=ibc_connection_servicer)

result_connection = await api.fetch_connection(connection_id=counterparty.connection_id)
expected_connection = {
"connection": {
"clientId": connection.client_id,
"versions": [{"identifier": version.identifier, "features": version.features}],
"state": ibc_connection.State.Name(connection.state),
"counterparty": {
"clientId": counterparty.client_id,
"connectionId": counterparty.connection_id,
"prefix": {"keyPrefix": base64.b64encode(prefix.key_prefix).decode()},
},
"delayPeriod": str(connection.delay_period),
},
"proof": base64.b64encode(proof).decode(),
"proofHeight": {
"revisionNumber": str(proof_height.revision_number),
"revisionHeight": str(proof_height.revision_height),
},
}

assert result_connection == expected_connection
Copy link
Contributor

Choose a reason for hiding this comment

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

The test case test_fetch_connection is well-structured and covers the basic functionality of fetching a connection. However, consider adding negative test cases to handle scenarios where the connection does not exist or the server returns an error.

Would you like me to help by adding some negative test cases?

Comment on lines +1 to +25
import asyncio

from google.protobuf import symbol_database

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
network = Network.testnet()
client = AsyncClient(network)

connection_id = "connection-0"
revision_number = 0
revision_height = 7379538

state = await client.fetch_ibc_connection_consensus_state(
connection_id=connection_id, revision_number=revision_number, revision_height=revision_height
)
print(state)


if __name__ == "__main__":
symbol_db = symbol_database.Default()
asyncio.get_event_loop().run_until_complete(main())
Copy link
Contributor

Choose a reason for hiding this comment

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

Check for potential file duplication or incorrect content.

This script appears identical to 5_ConnectionConsensusState.py. Please verify if this is intentional or if there has been a mistake in file naming or content duplication.

Comment on lines +1 to +43
from collections import deque

from pyinjective.proto.ibc.core.connection.v1 import (
query_pb2 as ibc_connection_query,
query_pb2_grpc as ibc_connection_query_grpc,
)


class ConfigurableIBCConnectionQueryServicer(ibc_connection_query_grpc.QueryServicer):
def __init__(self):
super().__init__()
self.connection_responses = deque()
self.connections_responses = deque()
self.client_connections_responses = deque()
self.connection_client_state_responses = deque()
self.connection_consensus_state_responses = deque()
self.connection_params_responses = deque()

async def Connection(self, request: ibc_connection_query.QueryConnectionRequest, context=None, metadata=None):
return self.connection_responses.pop()

async def Connections(self, request: ibc_connection_query.QueryConnectionsRequest, context=None, metadata=None):
return self.connections_responses.pop()

async def ClientConnections(
self, request: ibc_connection_query.QueryClientConnectionsRequest, context=None, metadata=None
):
return self.client_connections_responses.pop()

async def ConnectionClientState(
self, request: ibc_connection_query.QueryConnectionClientStateRequest, context=None, metadata=None
):
return self.connection_client_state_responses.pop()

async def ConnectionConsensusState(
self, request: ibc_connection_query.QueryConnectionConsensusStateRequest, context=None, metadata=None
):
return self.connection_consensus_state_responses.pop()

async def ConnectionParams(
self, request: ibc_connection_query.QueryConnectionParamsRequest, context=None, metadata=None
):
return self.connection_params_responses.pop()
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure robust handling of empty deques in servicer methods.

The methods in ConfigurableIBCConnectionQueryServicer pop items from deques without checking if they are empty. This could lead to IndexError if a deque is empty. Consider adding checks or default values to handle these cases safely.

Copy link

socket-security bot commented Apr 25, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
pypi/ckzg@1.4.2 None 0 243 kB jtraglia

🚮 Removed packages: pypi/pyyaml@6.0.1

View full report↗︎

@aarmoa aarmoa merged commit 0de78e7 into dev Apr 25, 2024
12 checks passed
@aarmoa aarmoa deleted the feat/ibc_connection_module_queries branch April 25, 2024 13:53
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