Skip to content

Feat/tendermint module queries#313

Merged
aarmoa merged 15 commits intodevfrom
feat/tendermint_module_queries
Mar 14, 2024
Merged

Feat/tendermint module queries#313
aarmoa merged 15 commits intodevfrom
feat/tendermint_module_queries

Conversation

@aarmoa
Copy link
Copy Markdown
Collaborator

@aarmoa aarmoa commented Mar 14, 2024

  • Added support for all queries in the chain 'tendermint' module

Summary by CodeRabbit

  • New Features
    • Added support for all queries in the 'tendermint' module in version 1.5.0.
    • Introduced new functionalities to fetch and display node information, syncing status, latest block, block by height, and validator sets using an async client for various networks.
  • Documentation
    • Updated the CHANGELOG.md with a summary of new features and improvements.
  • Tests
    • Added new test cases for the Tendermint module functionalities and deprecation warnings.
  • Chores
    • Updated the version number in pyproject.toml from "1.4.0-pre" to "1.5.0-pre".

@aarmoa aarmoa requested a review from nicolasbaum March 14, 2024 14:33
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 14, 2024

Walkthrough

The update enhances the 'tendermint' module in version 1.5.0, expanding the async client's capabilities for interacting with the Tendermint blockchain. It introduces features for querying node information, syncing status, latest blocks, blocks by height, and validator sets. These enhancements are distributed across Python scripts, the core library, and test suites, bolstering support for Tendermint queries within the Injective Protocol ecosystem.

Changes

Files Change Summary
CHANGELOG.md
pyproject.toml
Updated version to 1.5.0, adding support for all 'tendermint' module queries.
examples/chain_client/tendermint/query/... Introduced new files for querying various Tendermint data using an async client.
pyinjective/async_client.py
.../core/tx/grpc/tendermint_grpc_api.py
Enhanced Tendermint module with new methods and TendermintGrpcApi class functionalities.
tests/.../configurable_tendermint_query_servicer.py
tests/.../test_tendermint_grpc_api.py
tests/test_async_client_deprecation_warnings.py
Added test suites for Tendermint features and a deprecation warning test.

🐇✨
In the digital fields where data blocks play,
A new update hops, making quite the display.
With queries so swift, through networks it bounds,
Fetching, printing, syncing, all in leaps and rounds.
"To version 1.5.0!" the rabbit declares,
A hop forward in tech, as the blockchain it fares.
🌟🐾


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-tests 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 76.40%. Comparing base (54e4622) to head (cdd4bb9).

Files Patch % Lines
pyinjective/async_client.py 64.00% 9 Missing ⚠️
pyinjective/core/tx/grpc/tendermint_grpc_api.py 95.12% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #313      +/-   ##
==========================================
+ Coverage   76.16%   76.40%   +0.24%     
==========================================
  Files          50       51       +1     
  Lines        4111     4170      +59     
  Branches      351      353       +2     
==========================================
+ Hits         3131     3186      +55     
- Misses        875      878       +3     
- Partials      105      106       +1     

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

Copy link
Copy Markdown
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.

Review Status

Actionable comments generated: 11

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 54e4622 and 75a982e.
Files selected for processing (13)
  • CHANGELOG.md (1 hunks)
  • examples/chain_client/tendermint/query/1_GetNodeInfo.py (1 hunks)
  • examples/chain_client/tendermint/query/2_GetSyncing.py (1 hunks)
  • examples/chain_client/tendermint/query/3_GetLatestBlock.py (1 hunks)
  • examples/chain_client/tendermint/query/4_GetBlockByHeight.py (1 hunks)
  • examples/chain_client/tendermint/query/5_GetLatestValidatorSet.py (1 hunks)
  • examples/chain_client/tendermint/query/6_GetValidatorSetByHeight.py (1 hunks)
  • pyinjective/async_client.py (6 hunks)
  • pyinjective/core/tx/grpc/tenderming_grpc_api.py (1 hunks)
  • pyproject.toml (1 hunks)
  • tests/core/tx/grpc/configurable_tendermint_query_servicer.py (1 hunks)
  • tests/core/tx/grpc/test_tendermint_grpc_api.py (1 hunks)
  • tests/test_async_client_deprecation_warnings.py (4 hunks)
Check Runs (1)
codecov/patch completed (9)
  • pyinjective/async_client.py: 391-391: Added line #L391 was not covered by tests
  • pyinjective/async_client.py: 508-509: Added lines #L508 - L509 were not covered by tests
  • pyinjective/async_client.py: 1236-1236: Added line #L1236 was not covered by tests
  • pyinjective/async_client.py: 1239-1239: Added line #L1239 was not covered by tests
  • pyinjective/async_client.py: 1253-1253: Added line #L1253 was not covered by tests
  • pyinjective/async_client.py: 1256-1256: Added line #L1256 was not covered by tests
  • pyinjective/async_client.py: 1261-1261: Added line #L1261 was not covered by tests
  • pyinjective/async_client.py: 1266-1266: Added line #L1266 was not covered by tests
  • pyinjective/core/tx/grpc/tenderming_grpc_api.py: 52-52: Added line #L52 was not covered by tests
Files skipped from review due to trivial changes (1)
  • pyproject.toml
Additional comments: 12
examples/chain_client/tendermint/query/5_GetLatestValidatorSet.py (1)
  • 1-19: The script 5_GetLatestValidatorSet.py correctly demonstrates fetching the latest validator set. However, the import from google.protobuf import symbol_database and its instantiation symbol_db = symbol_database.Default() are not used within the script. Unless there's a side-effect or requirement not visible in this context, consider removing these to clean up the code.
examples/chain_client/tendermint/query/6_GetValidatorSetByHeight.py (1)
  • 1-22: The script 6_GetValidatorSetByHeight.py effectively demonstrates fetching a validator set by height with pagination. As in the previous script, the google.protobuf.symbol_database import and instantiation appear unused. If these are not required for the script's functionality, removing them would streamline the code.
tests/core/tx/grpc/configurable_tendermint_query_servicer.py (1)
  • 1-43: The ConfigurableTendermintQueryServicer class is a well-designed component for setting up mock responses in tests, enhancing the flexibility and robustness of testing tendermint queries. This approach allows for comprehensive testing of various scenarios without the need for a live network connection. Good job on implementing this testing utility.
tests/core/tx/grpc/test_tendermint_grpc_api.py (4)
  • 16-18: Creating a fixture for ConfigurableTendermintQueryServicer is a good practice as it promotes test reusability and maintainability.
  • 21-385: The test methods within TestTxGrpcApi are well-structured and follow asynchronous testing patterns with pytest.mark.asyncio, which is appropriate for testing async functions.

However, consider adding more comprehensive assertions to validate the structure and data types of the responses, ensuring they match expected formats beyond just value equality.

  • 72-73: Using a dummy metadata provider function (_dummy_metadata_provider) is a clever way to isolate tests from external dependencies. However, ensure that this approach does not skip important integration points that should be tested, especially regarding metadata handling.
  • 386-387: The _dummy_metadata_provider method is defined but not used within the test suite. If it's intended for future use, consider adding a comment explaining its purpose. Otherwise, it might be better to remove it to keep the code clean.
tests/test_async_client_deprecation_warnings.py (4)
  • 9-9: Adding the import for tendermint_query is necessary for the new Tendermint-related tests. This change aligns with the PR's objective to enhance Tendermint module support.
  • 37-37: The addition of ConfigurableTendermintQueryServicer as a fixture is crucial for testing the new Tendermint functionalities. It's good to see thorough testing being considered for the new features.
  • 111-113: The tendermint_servicer fixture is well-defined and follows the pattern of other service fixtures in the file. This consistency is important for maintainability.
  • 1711-1727: The new test method test_get_latest_block_deprecation_warning correctly tests for a deprecation warning when using get_latest_block, which is being replaced by fetch_latest_block. This change is consistent with the PR's goal to update and deprecate older methods in favor of new implementations. However, it's essential to ensure that all references to the deprecated method are updated across the codebase.
Verification successful

The verification process confirms that the deprecated method get_latest_block is only referenced in its definition and the test designed to check for its deprecation warning. This is consistent with the goal of deprecating older methods in favor of new implementations, as mentioned in the review comment. Therefore, the review comment is accurate.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining usage of the deprecated `get_latest_block` method.
rg --type py 'get_latest_block\('

Length of output: 236

pyinjective/async_client.py (1)
  • 197-202: Initialization of self.tendermint_api with TendermintGrpcApi is correctly done, ensuring that the Tendermint API is available for use within the AsyncClient class.


from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import Network
from pyinjective.core.tx.grpc.tenderming_grpc_api import TendermintGrpcApi
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot Mar 14, 2024

Choose a reason for hiding this comment

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

The import path for TendermintGrpcApi seems to contain a typo: tenderming_grpc_api should likely be tendermint_grpc_api.

- from pyinjective.core.tx.grpc.tenderming_grpc_api import TendermintGrpcApi
+ from pyinjective.core.tx.grpc.tendermint_grpc_api import TendermintGrpcApi

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.

Suggested change
from pyinjective.core.tx.grpc.tenderming_grpc_api import TendermintGrpcApi
from pyinjective.core.tx.grpc.tendermint_grpc_api import TendermintGrpcApi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Typo here ^

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@keithbaum, the verification confirms that the correct filename is indeed tendermint_grpc_api.py, and the initial suggestion to correct the typo was accurate. Thank you for pointing out the typo, and the suggested correction is as follows:

- from pyinjective.core.tx.grpc.tenderming_grpc_api import TendermintGrpcApi
+ from pyinjective.core.tx.grpc.tendermint_grpc_api import TendermintGrpcApi

This correction aligns with the actual filename in the repository, ensuring the import statement is correct.

Analysis chain
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the correct filename in the repository to verify the typo correction.
fd 'tendermint_grpc_api.py'

Length of output: 74

Comment thread pyinjective/async_client.py Outdated
from pyinjective.core.market import BinaryOptionMarket, DerivativeMarket, SpotMarket
from pyinjective.core.network import Network
from pyinjective.core.token import Token
from pyinjective.core.tx.grpc.tenderming_grpc_api import TendermintGrpcApi
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The import path for TendermintGrpcApi contains a typo: tenderming_grpc_api should be tendermint_grpc_api.

- from pyinjective.core.tx.grpc.tenderming_grpc_api import TendermintGrpcApi
+ from pyinjective.core.tx.grpc.tendermint_grpc_api import TendermintGrpcApi

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.

Suggested change
from pyinjective.core.tx.grpc.tenderming_grpc_api import TendermintGrpcApi
from pyinjective.core.tx.grpc.tendermint_grpc_api import TendermintGrpcApi

Comment on lines +1 to +16
import asyncio

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


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

syncing = await client.fetch_syncing()
print(syncing)


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

Choose a reason for hiding this comment

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

The script 2_GetSyncing.py is well-structured and follows good practices for asynchronous programming in Python. It correctly initializes the AsyncClient and fetches the syncing status. However, consider adding error handling around the await client.fetch_syncing() call to gracefully handle potential exceptions that could arise from network issues or API changes.

Comment on lines +1 to +16
import asyncio

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


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

node_info = await client.fetch_node_info()
print(node_info)


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

Choose a reason for hiding this comment

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

The script 1_GetNodeInfo.py is concise and follows asynchronous programming conventions. Like the previous script, adding error handling for the await client.fetch_node_info() call would improve the robustness of the script by managing exceptions that might occur during the API call.

Comment on lines +1 to +16
import asyncio

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


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

latest_block = await client.fetch_latest_block()
print(latest_block)


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

Choose a reason for hiding this comment

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

The script 3_GetLatestBlock.py effectively demonstrates how to retrieve the latest block information asynchronously. Consistent with previous scripts, incorporating error handling around the await client.fetch_latest_block() call would enhance the script's reliability in handling potential runtime exceptions.

Comment on lines +1 to +16
import asyncio

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


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

block = await client.fetch_block_by_height(height=15793860)
print(block)


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

Choose a reason for hiding this comment

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

The script 4_GetBlockByHeight.py is clear and demonstrates fetching a block by height. For improved usability, consider adding a comment to explain that the height value is a placeholder and should be replaced with the desired block height by the user. Additionally, implementing error handling for the await client.fetch_block_by_height(height=15793860) call would make the script more robust.

Comment on lines +1 to +69
from typing import Any, Callable, Dict, Optional

from grpc.aio import Channel

from pyinjective.client.model.pagination import PaginationOption
from pyinjective.proto.cosmos.base.tendermint.v1beta1 import (
query_pb2 as tendermint_query,
query_pb2_grpc as tendermint_query_grpc,
)
from pyinjective.utils.grpc_api_request_assistant import GrpcApiRequestAssistant


class TendermintGrpcApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
self._stub = tendermint_query_grpc.ServiceStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)

async def fetch_node_info(self) -> Dict[str, Any]:
request = tendermint_query.GetNodeInfoRequest()
response = await self._execute_call(call=self._stub.GetNodeInfo, request=request)

return response

async def fetch_syncing(self) -> Dict[str, Any]:
request = tendermint_query.GetSyncingRequest()
response = await self._execute_call(call=self._stub.GetSyncing, request=request)

return response

async def fetch_latest_block(self) -> Dict[str, Any]:
request = tendermint_query.GetLatestBlockRequest()
response = await self._execute_call(call=self._stub.GetLatestBlock, request=request)

return response

async def fetch_block_by_height(self, height: int) -> Dict[str, Any]:
request = tendermint_query.GetBlockByHeightRequest(height=height)
response = await self._execute_call(call=self._stub.GetBlockByHeight, request=request)

return response

async def fetch_latest_validator_set(self) -> Dict[str, Any]:
request = tendermint_query.GetLatestValidatorSetRequest()
response = await self._execute_call(call=self._stub.GetLatestValidatorSet, request=request)

return response

async def fetch_validator_set_by_height(
self, height: int, pagination: Optional[PaginationOption] = None
) -> Dict[str, Any]:
if pagination is None:
pagination = PaginationOption()
request = tendermint_query.GetValidatorSetByHeightRequest(
height=height, pagination=pagination.create_pagination_request()
)
response = await self._execute_call(call=self._stub.GetValidatorSetByHeight, request=request)

return response

async def abci_query(
self, path: str, data: Optional[bytes] = None, height: Optional[int] = None, prove: bool = False
) -> Dict[str, Any]:
request = tendermint_query.ABCIQueryRequest(path=path, data=data, height=height, prove=prove)
response = await self._execute_call(call=self._stub.ABCIQuery, request=request)

return response

async def _execute_call(self, call: Callable, request) -> Dict[str, Any]:
return await self._assistant.execute_call(call=call, request=request)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The TendermintGrpcApi class is comprehensive and provides a wide range of functionalities for interacting with the Tendermint gRPC API. It's well-structured and follows best practices for asynchronous programming and gRPC interactions. However, it appears that the default pagination logic introduced in line 52 might not be covered by tests. Ensuring coverage for this logic is important for validating its behavior and handling edge cases.

Copy link
Copy Markdown
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.

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 75a982e and 136174c.
Files selected for processing (1)
  • pyinjective/core/tx/grpc/tendermint_grpc_api.py (1 hunks)

Comment on lines +13 to +68
class TendermintGrpcApi:
def __init__(self, channel: Channel, metadata_provider: Callable):
self._stub = tendermint_query_grpc.ServiceStub(channel)
self._assistant = GrpcApiRequestAssistant(metadata_provider=metadata_provider)

async def fetch_node_info(self) -> Dict[str, Any]:
request = tendermint_query.GetNodeInfoRequest()
response = await self._execute_call(call=self._stub.GetNodeInfo, request=request)

return response

async def fetch_syncing(self) -> Dict[str, Any]:
request = tendermint_query.GetSyncingRequest()
response = await self._execute_call(call=self._stub.GetSyncing, request=request)

return response

async def fetch_latest_block(self) -> Dict[str, Any]:
request = tendermint_query.GetLatestBlockRequest()
response = await self._execute_call(call=self._stub.GetLatestBlock, request=request)

return response

async def fetch_block_by_height(self, height: int) -> Dict[str, Any]:
request = tendermint_query.GetBlockByHeightRequest(height=height)
response = await self._execute_call(call=self._stub.GetBlockByHeight, request=request)

return response

async def fetch_latest_validator_set(self) -> Dict[str, Any]:
request = tendermint_query.GetLatestValidatorSetRequest()
response = await self._execute_call(call=self._stub.GetLatestValidatorSet, request=request)

return response

async def fetch_validator_set_by_height(
self, height: int, pagination: Optional[PaginationOption] = None
) -> Dict[str, Any]:
if pagination is None:
pagination = PaginationOption()
request = tendermint_query.GetValidatorSetByHeightRequest(
height=height, pagination=pagination.create_pagination_request()
)
response = await self._execute_call(call=self._stub.GetValidatorSetByHeight, request=request)

return response

async def abci_query(
self, path: str, data: Optional[bytes] = None, height: Optional[int] = None, prove: bool = False
) -> Dict[str, Any]:
request = tendermint_query.ABCIQueryRequest(path=path, data=data, height=height, prove=prove)
response = await self._execute_call(call=self._stub.ABCIQuery, request=request)

return response

async def _execute_call(self, call: Callable, request) -> Dict[str, Any]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The TendermintGrpcApi class is well-structured and provides a comprehensive set of methods for interacting with the Tendermint gRPC API. Each method is designed to fetch specific information, such as node info, syncing status, latest block, block by height, latest validator set, validator set by height, and perform an ABCI query. The use of asynchronous programming ensures that these operations do not block the main thread, which is crucial for performance in I/O-bound tasks like network requests.

A few points to consider for further refinement:

  • Error Handling: It's important to ensure robust error handling around the gRPC calls. Consider catching exceptions specific to gRPC calls and handling them appropriately, possibly logging the errors or retrying the calls under certain conditions.
  • Type Annotations: The return type of each method is annotated as Dict[str, Any], which is quite generic. If possible, providing more specific type annotations would enhance code readability and maintainability by making the expected structure of the responses clearer.
  • Documentation: Adding docstrings to each method would greatly improve the understandability of the code. These should describe the purpose of the method, its parameters, its return type, and any exceptions it might raise.
  • Pagination Handling: For methods that support pagination, such as fetch_validator_set_by_height, consider documenting how pagination is handled and what the caller should expect in terms of response structure, especially how to retrieve subsequent pages.

Overall, the implementation aligns well with the objectives of enhancing the software by adding comprehensive support for Tendermint module queries. These suggestions aim to further improve the code's robustness, clarity, and maintainability.

Copy link
Copy Markdown
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.

Review Status

Actionable comments generated: 3

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 136174c and 6b102f2.
Files selected for processing (2)
  • pyinjective/async_client.py (6 hunks)
  • tests/core/tx/grpc/test_tendermint_grpc_api.py (1 hunks)
Check Runs (1)
codecov/patch completed (9)
  • pyinjective/async_client.py: 391-391: Added line #L391 was not covered by tests
  • pyinjective/async_client.py: 508-509: Added lines #L508 - L509 were not covered by tests
  • pyinjective/async_client.py: 1236-1236: Added line #L1236 was not covered by tests
  • pyinjective/async_client.py: 1239-1239: Added line #L1239 was not covered by tests
  • pyinjective/async_client.py: 1253-1253: Added line #L1253 was not covered by tests
  • pyinjective/async_client.py: 1256-1256: Added line #L1256 was not covered by tests
  • pyinjective/async_client.py: 1261-1261: Added line #L1261 was not covered by tests
  • pyinjective/async_client.py: 1266-1266: Added line #L1266 was not covered by tests
Files skipped from review as they are similar to previous changes (1)
  • tests/core/tx/grpc/test_tendermint_grpc_api.py
Additional comments: 3
pyinjective/async_client.py (3)
  • 42-42: The import of TendermintGrpcApi is correctly added to support the new Tendermint module functionalities.
  • 53-53: The import of ed25519_keys is added, presumably for handling validator set responses. Ensure that this import is utilized within the code to justify its presence.
  • 197-202: Initialization of self.tendermint_api with TendermintGrpcApi is correctly done, aligning with the PR's objective to enhance Tendermint module support.

Comment on lines +390 to +391
block = await self.fetch_latest_block()
self.timeout_height = int(block["block"]["header"]["height"]) + DEFAULT_TIMEOUTHEIGHT
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The method sync_timeout_height is not covered by tests. It's crucial to ensure that the functionality for syncing the timeout height is correctly implemented and does not introduce any unexpected behavior.

Would you like me to help generate tests for this method or open a GitHub issue to track this task?

Comment on lines +508 to +509
latest_block = await self.fetch_latest_block()
return latest_block["block"]["header"]["chainId"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The method get_chain_id is not covered by tests. Considering this method fetches the chain ID from the latest block, it's essential to verify its correctness and reliability through testing.

Would you like assistance in creating tests for this method or should I open a GitHub issue to ensure it's tracked?

Comment on lines +1234 to +1268
# region Tendermint module
async def fetch_node_info(self) -> Dict[str, Any]:
return await self.tendermint_api.fetch_node_info()

async def fetch_syncing(self) -> Dict[str, Any]:
return await self.tendermint_api.fetch_syncing()

async def get_latest_block(self) -> tendermint_query.GetLatestBlockResponse:
"""
This method is deprecated and will be removed soon. Please use `fetch_latest_block` instead
"""
warn("This method is deprecated. Use fetch_latest_block instead", DeprecationWarning, stacklevel=2)
req = tendermint_query.GetLatestBlockRequest()
return await self.stubCosmosTendermint.GetLatestBlock(req)

async def fetch_latest_block(self) -> Dict[str, Any]:
return await self.tendermint_api.fetch_latest_block()

async def fetch_block_by_height(self, height: int) -> Dict[str, Any]:
return await self.tendermint_api.fetch_block_by_height(height=height)

async def fetch_latest_validator_set(self) -> Dict[str, Any]:
return await self.tendermint_api.fetch_latest_validator_set()

async def fetch_validator_set_by_height(
self, height: int, pagination: Optional[PaginationOption] = None
) -> Dict[str, Any]:
return await self.tendermint_api.fetch_validator_set_by_height(height=height, pagination=pagination)

async def abci_query(
self, path: str, data: Optional[bytes] = None, height: Optional[int] = None, prove: bool = False
) -> Dict[str, Any]:
return await self.tendermint_api.abci_query(path=path, data=data, height=height, prove=prove)

# endregion
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The newly added methods in the Tendermint module (fetch_node_info, fetch_syncing, fetch_latest_block, fetch_block_by_height, fetch_latest_validator_set, fetch_validator_set_by_height, and abci_query) are crucial for interacting with the Tendermint gRPC API. However, several of these methods are not covered by tests, which is essential for ensuring their correct functionality and integration.

Would you like help in creating tests for these Tendermint module methods, or should I open a GitHub issue to track this task?

@nicolasbaum nicolasbaum self-requested a review March 14, 2024 15:04
Copy link
Copy Markdown
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.

Review Status

Actionable comments generated: 2

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 6b102f2 and cdd4bb9.
Files selected for processing (11)
  • CHANGELOG.md (1 hunks)
  • examples/chain_client/3_MessageBroadcaster.py (1 hunks)
  • examples/chain_client/5_MessageBroadcasterWithoutSimulation.py (1 hunks)
  • examples/chain_client/exchange/8_MsgCancelSpotOrder.py (1 hunks)
  • examples/chain_client/exchange/9_MsgBatchUpdateOrders.py (1 hunks)
  • pyinjective/denoms_devnet.ini (4 hunks)
  • pyinjective/denoms_mainnet.ini (9 hunks)
  • pyinjective/denoms_testnet.ini (5 hunks)
  • tests/core/test_gas_limit_estimator.py (10 hunks)
  • tests/test_async_client_deprecation_warnings.py (5 hunks)
  • tests/test_composer_deprecation_warnings.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/test_async_client_deprecation_warnings.py
Additional comments: 41
examples/chain_client/3_MessageBroadcaster.py (1)
  • 59-59: The function call has been updated from composer.MsgBatchUpdateOrders to composer.msg_batch_update_orders. This change aligns with Python's naming conventions for methods, promoting readability and consistency. Ensure that all references to this function throughout the codebase have been updated accordingly.
examples/chain_client/5_MessageBroadcasterWithoutSimulation.py (1)
  • 59-59: The function call has been updated from composer.MsgBatchUpdateOrders to composer.msg_batch_update_orders. This change is consistent with Python's naming conventions and improves readability. Ensure that all references to this function throughout the codebase have been updated accordingly.
examples/chain_client/exchange/8_MsgCancelSpotOrder.py (1)
  • 38-38: The function call has been updated from composer.MsgCancelSpotOrder to composer.msg_cancel_spot_order. This change adheres to Python's naming conventions, enhancing readability and consistency. Verify that all references to this function throughout the codebase have been updated accordingly.
examples/chain_client/exchange/9_MsgBatchUpdateOrders.py (1)
  • 121-121: The function call has been renamed from composer.MsgBatchUpdateOrders to composer.msg_batch_update_orders. This change is in line with Python's naming conventions, improving readability and consistency. Ensure that all references to this function throughout the codebase have been updated accordingly.
CHANGELOG.md (1)
  • 9-11: The update for version 1.4.1 mentions updates to example scripts that were still using deprecated methods. Ensure that all example scripts have been reviewed and updated accordingly to prevent any potential issues with deprecated methods.
pyinjective/denoms_devnet.ini (5)
  • 167-170: The tick sizes and quantities for the Devnet Spot PROJ/INJ pair have been updated. Ensure these values align with the intended precision and liquidity requirements for this trading pair.
  • 181-188: New trading pair Devnet Spot QUNT/INJ added with specific configurations. Verify that the min_price_tick_size and min_quantity_tick_size are appropriate for the market dynamics of this pair.
  • 190-197: New trading pair Devnet Spot HDRO/INJ added. It's crucial to ensure that the large min_price_tick_size and min_quantity_tick_size values are suitable for the expected trading volume and liquidity.
  • 317-320: The HDRO token configuration has been added. Confirm that the peggy_denom and decimals are correctly set up to match the token's specifications on the blockchain.
  • 341-344: The QUNT token configuration has been introduced. It's important to verify the accuracy of the peggy_denom and decimals to ensure seamless integration with the blockchain.
pyinjective/denoms_testnet.ini (9)
  • 145-152: New trading pair Testnet Spot TEST2/INJ added. Ensure the min_price_tick_size and min_quantity_tick_size are set correctly to facilitate accurate and efficient trading.
  • 154-161: New trading pair Testnet Spot TEST2/USDT added. It's important to verify that the tick sizes and quantities are appropriate for the market conditions of this pair.
  • 226-233: The configuration for Testnet Spot Inj has been updated. Double-check that the min_price_tick_size and min_quantity_tick_size adjustments are in line with the desired trading precision and liquidity.
  • 235-242: New trading pair Testnet Spot MT/INJ added. Confirm that the min_price_tick_size and min_quantity_tick_size values are suitable for the expected trading volume and liquidity of this pair.
  • 253-260: New trading pair Testnet Spot HDRO/INJ added. It's crucial to ensure that the min_price_tick_size and min_quantity_tick_size values are appropriate for the market dynamics of this pair.
  • 468-471: The HDRO token configuration has been added. Verify that the peggy_denom and decimals are correctly set up to match the token's specifications on the blockchain.
  • 476-479: The MT token configuration has been updated. Ensure that the peggy_denom and decimals accurately reflect the token's properties for seamless integration with the blockchain.
  • 492-499: New token configurations for TEST1 and TEST2 have been introduced. Confirm the accuracy of peggy_denom and decimals to ensure correct handling of these tokens on the testnet.
  • 528-531: The hINJ token configuration has been added. It's important to verify the peggy_denom and decimals to ensure they align with the token's blockchain specifications.
tests/core/test_gas_limit_estimator.py (10)
  • 160-160: The change from composer.MsgBatchUpdateOrders to composer.msg_batch_update_orders in the method call for creating a batch update order message for spot orders is consistent with the PR's objective to refactor and enhance the codebase. However, ensure that the composer class's method names are consistently used throughout the codebase to maintain readability and prevent confusion.
  • 197-197: The modification to use composer.msg_batch_update_orders for creating derivative orders aligns with the PR's goal of code enhancement. It's important to verify that all references to the old method name have been updated across the entire project to ensure consistency and avoid runtime errors.
  • 252-252: Switching to composer.msg_batch_update_orders for creating binary options orders is a positive change that supports the PR's objectives. Double-check that the new method is implemented correctly in the composer class and that its usage is consistent across the project.
  • 287-287: The update to use composer.msg_batch_update_orders for canceling spot orders is in line with the PR's aim to refactor the code. It's crucial to ensure that the method's implementation in the composer class handles all order types correctly and that the change is reflected wherever necessary in the project.
  • 321-321: Changing to composer.msg_batch_update_orders for canceling derivative orders reflects the PR's intention to improve the code structure. Confirm that the composer class's method is thoroughly tested for handling derivative orders and that the project consistently uses the new method name.
  • 355-355: The transition to composer.msg_batch_update_orders for canceling binary options orders supports the PR's goal of code enhancement. Ensure that the method in the composer class is correctly implemented to handle binary options orders and that the change is consistently applied across the project.
  • 374-374: Using composer.msg_batch_update_orders to cancel all orders for a spot market is a good practice that aligns with the PR's objectives. Verify that the composer class's method adequately supports this functionality and that the change is uniformly applied throughout the project.
  • 394-394: The modification to use composer.msg_batch_update_orders for canceling all orders in a derivative market is consistent with the PR's aim. It's essential to ensure that the method in the composer class is fully functional for this purpose and that the project consistently adopts the new method name.
  • 414-414: Switching to composer.msg_batch_update_orders for canceling all orders in a binary options market supports the PR's objectives. Confirm that the composer class's method is correctly implemented for this functionality and that the change is consistently applied across the project.
  • 443-443: The change to use composer.msg_batch_update_orders within an exec message for creating spot orders is in line with the PR's goal of code enhancement. Ensure that the composer class's method is properly tested in this context and that the change is uniformly adopted in the project.
tests/test_composer_deprecation_warnings.py (3)
  • 53-64: The test test_coin_deprecation_warning correctly checks for a deprecation warning when using the Coin method. However, it's important to ensure that the new method coin exists and is properly documented to guide users towards the updated usage.
  • 66-66: The renaming of teste_order_data_deprecation_warning to test_order_data_deprecation_warning corrects a typographical error in the method name, improving readability and consistency in naming conventions.
  • 537-550: The addition of test_msg_withdraw_delegator_reward_deprecation_warning extends the test coverage to include deprecation warnings for the MsgWithdrawDelegatorReward method. Similar to the previous test, ensure that the new method msg_withdraw_delegator_reward is available and documented for users.
pyinjective/denoms_mainnet.ini (9)
  • 685-692: The configuration for Mainnet Spot DOJO/INJ has been added correctly, following the established pattern for such configurations. Ensure that the base and quote values align with the expected precision for these tokens.
  • 712-719: The configuration for Mainnet Spot ANDR/INJ introduces a significant min_price_tick_size of 10000000 and a min_display_price_tick_size of 0.00001, which seems unusually high compared to other configurations. Verify that these values are intended and consistent with the trading strategy for this pair.
  • 721-728: The configuration for Mainnet Spot hINJ/INJ is consistent with the pattern for spot pairs. The min_price_tick_size and min_display_price_tick_size are set to 0.0001, which is standard for pairs involving INJ.
  • 739-746: The configuration for Mainnet Spot PHUC/INJ uses a min_price_tick_size of 10000 and a min_display_price_tick_size of 0.00000001, which is consistent with other configurations involving INJ. Ensure the min_quantity_tick_size and min_display_quantity_tick_size are appropriate for the expected trading volume.
  • 757-764: The configuration for Mainnet Spot WHALE/INJ introduces a min_price_tick_size and min_display_price_tick_size that are consistent with high-value tokens. This configuration should be verified for accuracy given the unique nature of the WHALE token.
  • 766-773: The configuration for Mainnet Spot HDRO/INJ follows the established pattern. Given the novelty of the HDRO token, ensure that the tick sizes and quantities are aligned with the market expectations for this token.
  • 775-782: The configuration for Mainnet Spot PYTH/INJ has a higher min_price_tick_size and min_display_price_tick_size compared to other INJ pairs. Confirm that these values are intended to reflect the trading characteristics of the PYTH token.
  • 982-989: The configuration for Mainnet Derivative W/USDT PERP is correctly added, following the pattern for derivative pairs. Ensure that the min_price_tick_size and min_display_price_tick_size are appropriate for the volatility and trading strategy of this derivative.
  • 1000-1007: The configuration for Mainnet Derivative DOGE/USDT PERP uses a min_price_tick_size and min_display_price_tick_size that are consistent with the expected volatility of DOGE. However, the min_quantity_tick_size and min_display_quantity_tick_size are set to 10, which might be high for a derivative. Confirm these values are correct.

Comment thread CHANGELOG.md
Comment on lines +5 to +7
## [1.5.0] - 9999-99-99
### Added
- Added support for all queries in the chain 'tendermint' module
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The entry for version 1.5.0 uses a placeholder date 9999-99-99. It's important to replace this with the actual release date before the changelog is finalized.

- ## [1.5.0] - 9999-99-99
+ ## [1.5.0] - <actual release date>

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.

Suggested change
## [1.5.0] - 9999-99-99
### Added
- Added support for all queries in the chain 'tendermint' module
## [1.5.0] - <actual release date>
### Added
- Added support for all queries in the chain 'tendermint' module

Comment on lines +856 to +863
[0x3b7fb1d9351f7fa2e6e0e5a11b3639ee5e0486c33a6a74f629c3fc3c3043efd5]
description = 'Mainnet Derivative BONK/USDT PERP'
base = 0
quote = 6
min_price_tick_size = 0.01
min_display_price_tick_size = 0.00000001
min_quantity_tick_size = 10000
min_display_quantity_tick_size = 10000
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The configuration for Mainnet Derivative BONK/USDT PERP introduces a min_price_tick_size of 0.01 and a min_display_price_tick_size of 0.00000001, which seems to be an error given the mismatch in scale. The min_quantity_tick_size and min_display_quantity_tick_size also appear to be unusually high. This configuration should be reviewed for potential errors.

- min_display_price_tick_size = 0.00000001
+ min_display_price_tick_size = 0.01
- min_display_quantity_tick_size = 10000
+ min_display_quantity_tick_size = 0.01

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.

Suggested change
[0x3b7fb1d9351f7fa2e6e0e5a11b3639ee5e0486c33a6a74f629c3fc3c3043efd5]
description = 'Mainnet Derivative BONK/USDT PERP'
base = 0
quote = 6
min_price_tick_size = 0.01
min_display_price_tick_size = 0.00000001
min_quantity_tick_size = 10000
min_display_quantity_tick_size = 10000
[0x3b7fb1d9351f7fa2e6e0e5a11b3639ee5e0486c33a6a74f629c3fc3c3043efd5]
description = 'Mainnet Derivative BONK/USDT PERP'
base = 0
quote = 6
min_price_tick_size = 0.01
min_display_price_tick_size = 0.01
min_quantity_tick_size = 10000
min_display_quantity_tick_size = 0.01

@aarmoa aarmoa merged commit 8adf955 into dev Mar 14, 2024
@aarmoa aarmoa deleted the feat/tendermint_module_queries branch March 14, 2024 20:15
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