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/load_official_tokens_list #226

Merged
merged 3 commits into from
Jun 6, 2024
Merged

Conversation

aarmoa
Copy link
Collaborator

@aarmoa aarmoa commented Jun 6, 2024

Solves CHAIN-101

Summary by CodeRabbit

  • New Features

    • Introduced a unified TokenMetadata interface for retrieving token information.
    • Added URLs for mainnet, testnet, and devnet token lists, and updated network configurations accordingly.
  • Bug Fixes

    • Prevented account initialization requests during unit tests by setting Keyring to nil.
  • Tests

    • Added new tests for loading token metadata from URLs and handling errors during token loading.
    • Set up a mock HTTP server for testing market assistant functionality.
  • Enhancements

    • Simplified token representation functions by consolidating them into a single function using the new TokenMetadata interface.
    • Updated ExchangeClient to include a method for retrieving network information.

…om the official tokens lists for each environment
@aarmoa aarmoa requested a review from nicolasbaum June 6, 2024 02:54
Copy link

coderabbitai bot commented Jun 6, 2024

Walkthrough

The recent updates primarily enhance token management across various components. Major changes include integrating a TokenMetadata interface, adding URLs for token lists in different environments, and modifying unit tests to use mock data. These improvements streamline token representation and loading, ensuring consistency and flexibility in handling token information across the client.

Changes

Files Change Summaries
client/chain/chain_test.go Set Keyring field to nil to prevent account initialization during unit tests.
client/chain/markets_assistant.go Added TokenMetadata interface and consolidated token representation functions.
client/chain/markets_assistant_test.go Added imports, mock HTTP server setup, and network object initialization for testing.
client/common/network.go Added URLs for token lists and updated Network struct with OfficialTokensListUrl field.
client/core/tokens_file_loader.go Introduced functionality to load token metadata from a specified file URL.
client/core/tokens_file_loader_test.go Added test functions for loading tokens and handling errors during token loading.
client/exchange/exchange.go Added GetNetwork() method to ExchangeClient interface and its implementation.
client/exchange/exchange_test_support.go Added Network field and GetNetwork() method to MockExchangeClient struct.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant MarketsAssistant
    participant TokenMetadata
    participant Network
    participant ExchangeClient

    User->>MarketsAssistant: Request token representation
    MarketsAssistant->>TokenMetadata: Fetch token details
    TokenMetadata-->>MarketsAssistant: Provide token information
    MarketsAssistant-->>User: Return token representation

    User->>ExchangeClient: Request network information
    ExchangeClient->>Network: Fetch network details
    Network-->>ExchangeClient: Provide token list URL
    ExchangeClient-->>User: Return network information

Poem

In the world of tokens, changes flow,
Metadata now, a unified show.
URLs for lists on every net,
Mock tests ensure no bugs are met.
Tokens load with seamless grace,
In Injective's ever-evolving space. 🌟


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

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.

@aarmoa aarmoa changed the title (feat) Added logic in the markets assistant to load all the tokens fr… feat/load_official_tokens_list Jun 6, 2024
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 68f05f6 and 2218318.

Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum
Files selected for processing (8)
  • client/chain/chain_test.go (1 hunks)
  • client/chain/markets_assistant.go (5 hunks)
  • client/chain/markets_assistant_test.go (3 hunks)
  • client/common/network.go (8 hunks)
  • client/core/tokens_file_loader.go (1 hunks)
  • client/core/tokens_file_loader_test.go (1 hunks)
  • client/exchange/exchange.go (2 hunks)
  • client/exchange/exchange_test_support.go (3 hunks)
Files skipped from review due to trivial changes (1)
  • client/chain/chain_test.go
Additional comments not posted (13)
client/core/tokens_file_loader.go (1)

9-22: The TokenMetadata struct is well-defined and covers all necessary token attributes.

client/core/tokens_file_loader_test.go (2)

12-62: The test TestLoadTokensFromUrl is well-implemented and covers the successful scenario of loading tokens.


64-73: The test TestLoadTokensFromUrlReturnsNoTokensWhenRequestErrorHappens correctly handles the error scenario, ensuring robust error handling in LoadTokens.

client/chain/markets_assistant_test.go (2)

Line range hint 5-93: The test TestMarketAssistantCreationUsingMarketsFromExchange is comprehensive, testing the initialization and functionality of MarketsAssistant with mock data.


Line range hint 90-125: The test TestMarketAssistantCreationWithAllTokens effectively verifies the initialization of MarketsAssistant with all tokens, ensuring comprehensive coverage.

client/chain/markets_assistant.go (2)

24-31: The TokenMetadata interface is clearly defined, providing essential methods for token attribute access.


Line range hint 32-288: The MarketsAssistant struct and its methods are well-implemented, effectively managing market and token data with robust initialization and unique symbol handling.

client/common/network.go (2)

18-20: Constants for token list URLs are correctly defined.


204-204: Addition of OfficialTokensListUrl to the Network struct is appropriate for managing token list URLs based on the network environment.

client/exchange/exchange_test_support.go (2)

20-20: Addition of the Network field to the MockExchangeClient struct enhances testing capabilities by allowing simulation of network configurations.


308-310: Implementation of the GetNetwork method in MockExchangeClient is correct and necessary for accessing the network configuration in tests.

client/exchange/exchange.go (2)

93-93: Addition of GetNetwork() method to the ExchangeClient interface is correctly implemented.


965-967: Implementation of GetNetwork() in exchangeClient correctly returns the network configuration.

@@ -218,6 +221,7 @@ func LoadNetwork(name string, node string) Network {
ChainCookieAssistant: &DisabledCookieAssistant{},
ExchangeCookieAssistant: &DisabledCookieAssistant{},
ExplorerCookieAssistant: &DisabledCookieAssistant{},
OfficialTokensListUrl: MainnetTokensListUrl,
Copy link

@coderabbitai coderabbitai bot Jun 6, 2024

Choose a reason for hiding this comment

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

The initialization of OfficialTokensListUrl in LoadNetwork is correctly implemented for different network types.

Consider adding a default case in the switch statement to handle unexpected network names gracefully.

+ default:
+   panic("Unsupported network type")

Also applies to: 241-241, 257-257, 312-312, 352-352, 366-366

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
OfficialTokensListUrl: MainnetTokensListUrl,
OfficialTokensListUrl: MainnetTokensListUrl,
+ default:
+ panic("Unsupported network type")

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with 🤖 here. Makes sense to handle this

Copy link

Choose a reason for hiding this comment

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

@keithbaum, thank you for your feedback and agreement! If there's anything more you need help with regarding this or any other aspect of the project, feel free to let me know. Happy coding! 🚀

Comment on lines +49 to +67
func LoadTokens(tokensFileUrl string) ([]TokenMetadata, error) {
var tokensMetadata []TokenMetadata
response, err := http.Get(tokensFileUrl)
if err != nil {
return tokensMetadata, err
}
if 400 <= response.StatusCode {
return tokensMetadata, fmt.Errorf("failed to load tokens from %s: %s", tokensFileUrl, response.Status)
}
defer response.Body.Close()

decoder := json.NewDecoder(response.Body)
err = decoder.Decode(&tokensMetadata)
if err != nil {
return make([]TokenMetadata, 0), err
}

return tokensMetadata, nil
}
Copy link

Choose a reason for hiding this comment

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

Consider refining the error handling in LoadTokens to cover all client errors (status codes 400-499) instead of just 400 and above.

- if 400 <= response.StatusCode {
+ if response.StatusCode >= 400 && response.StatusCode < 500 {
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
func LoadTokens(tokensFileUrl string) ([]TokenMetadata, error) {
var tokensMetadata []TokenMetadata
response, err := http.Get(tokensFileUrl)
if err != nil {
return tokensMetadata, err
}
if 400 <= response.StatusCode {
return tokensMetadata, fmt.Errorf("failed to load tokens from %s: %s", tokensFileUrl, response.Status)
}
defer response.Body.Close()
decoder := json.NewDecoder(response.Body)
err = decoder.Decode(&tokensMetadata)
if err != nil {
return make([]TokenMetadata, 0), err
}
return tokensMetadata, nil
}
func LoadTokens(tokensFileUrl string) ([]TokenMetadata, error) {
var tokensMetadata []TokenMetadata
response, err := http.Get(tokensFileUrl)
if err != nil {
return tokensMetadata, err
}
if response.StatusCode >= 400 && response.StatusCode < 500 {
return tokensMetadata, fmt.Errorf("failed to load tokens from %s: %s", tokensFileUrl, response.Status)
}
defer response.Body.Close()
decoder := json.NewDecoder(response.Body)
err = decoder.Decode(&tokensMetadata)
if err != nil {
return make([]TokenMetadata, 0), err
}
return tokensMetadata, nil
}

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2218318 and ce23fb7.

Files selected for processing (3)
  • client/chain/markets_assistant_test.go (3 hunks)
  • client/core/tokens_file_loader_test.go (1 hunks)
  • client/exchange/exchange_test_support.go (3 hunks)
Files skipped from review as they are similar to previous changes (3)
  • client/chain/markets_assistant_test.go
  • client/core/tokens_file_loader_test.go
  • client/exchange/exchange_test_support.go

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ce23fb7 and 0a1185e.

Files selected for processing (1)
  • client/common/network.go (8 hunks)
Files skipped from review as they are similar to previous changes (1)
  • client/common/network.go

@aarmoa aarmoa merged commit b0aed65 into dev Jun 6, 2024
4 checks passed
@aarmoa aarmoa deleted the feat/load_official_tokens_list branch June 6, 2024 12:49
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.

None yet

2 participants