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

Update the MsgMarketCommitmentSettle cli stuff use the keyring if a from is provided. #2001

Merged
merged 3 commits into from
May 23, 2024

Conversation

SpicyLemon
Copy link
Contributor

@SpicyLemon SpicyLemon commented May 23, 2024

Description

This PR makes the provenanced query exchange commitment-settlement-fee-calc command use the keyring to get the from address (just like the related tx command would do).

Prior to this PR, you could provide the admin address using the '--from' flag, but it didn't use the keyring, so it had to be an address. That means that, if you wanted to use a named keyring entry when doing the tx, you couldn't provide the same flags to the query command (to check it before you try it). After this PR, you can provide the same --from value to both commands.


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

Summary by CodeRabbit

  • New Features

    • Improved CLI query for commitment settlement fee calculation to utilize keyring, enhancing security and reliability.
  • Bug Fixes

    • Enhanced error handling for address conversion from Bech32 format, providing better fallback mechanisms.
  • Refactor

    • Updated client context initialization across multiple test files to streamline keyring integration.
  • Tests

    • Added new test cases for various flag scenarios in commitment settlement fee calculation queries.

Copy link
Contributor

coderabbitai bot commented May 23, 2024

Walkthrough

The recent updates primarily focus on enhancing the commitment-settlement-fee-calc CLI query by integrating keyring functionalities. This change necessitated refactoring test setups and adding keyring-related logic to ensure smooth operation. The updates aim to improve security and functionality when handling client contexts in various test scenarios.

Changes

File Path Change Summary
CHANGELOG.md Updated to reflect the new keyring usage in commitment-settlement-fee-calc CLI query.
x/exchange/client/cli/cli_test.go Refactored newClientContext to include keyring; added clientContextWithKeyring function.
x/exchange/client/cli/flags_test.go Replaced newClientContextWithCodec(t) with newClientContext(t) in multiple test functions.
x/exchange/client/cli/query_setup.go Enhanced Bech32 address conversion logic with added error handling and fallback.
x/exchange/client/cli/query_setup_test.go Replaced newClientContextWithCodec(t) with newClientContext(t) and added new test cases.
x/exchange/client/cli/tx_setup_test.go Updated clientCtx initialization from newClientContextWithCodec(t) to newClientContext(t) in two tests.

🐇
In the realm of code so bright and keen,
Keyrings now join the settlement scene.
Tests refactored, logic refined,
With Bech32, errors are confined.
The CLI’s stronger, secure, and neat,
A coder’s work, truly a feat!
🌟


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.

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.

@SpicyLemon SpicyLemon marked this pull request as ready for review May 23, 2024 18:54
@SpicyLemon SpicyLemon requested a review from a team as a code owner May 23, 2024 18:54
@SpicyLemon SpicyLemon enabled auto-merge (squash) May 23, 2024 19:05
@SpicyLemon SpicyLemon merged commit 9561f93 into main May 23, 2024
26 of 35 checks passed
@SpicyLemon SpicyLemon deleted the dwedul/use-keyring-in-exchange-queries branch May 23, 2024 19:08
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: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9eb2170 and 89eb7d1.
Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • x/exchange/client/cli/cli_test.go (3 hunks)
  • x/exchange/client/cli/flags_test.go (6 hunks)
  • x/exchange/client/cli/query_setup.go (1 hunks)
  • x/exchange/client/cli/query_setup_test.go (2 hunks)
  • x/exchange/client/cli/tx_setup_test.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • x/exchange/client/cli/flags_test.go
Additional comments not posted (27)
x/exchange/client/cli/cli_test.go (3)

1315-1319: Refactored newClientContext to include keyring setup aligns with PR objectives.


1337-1349: Properly sets up keyring in client context with error handling.


1331-1335: Ensure sensitive keyring constants are securely managed.

#!/bin/bash
# Description: Verify that keyring constants are not exposed inappropriately.

# Test: Search for the keyring constants usage. Expect: No exposure in logs or other insecure places.
rg --type go $'keyringName|keyringMnemonic|keyringAddr'
x/exchange/client/cli/query_setup_test.go (1)

71-71: Change from newClientContextWithCodec to newClientContext aligns with the PR's objective to simplify client context setup.

x/exchange/client/cli/tx_setup_test.go (22)

Line range hint 73-91: The test function TestSetupCmdTxCreateAsk correctly sets up and validates the command flags for creating an ask in the market exchange context.


Line range hint 93-126: The test function TestMakeMsgCreateAsk thoroughly tests the message creation logic for an "ask" order under various scenarios, including error handling.


Line range hint 128-146: The test function TestSetupCmdTxCreateBid correctly sets up and validates the command flags for creating a bid in the market exchange context.


Line range hint 148-181: The test function TestMakeMsgCreateBid thoroughly tests the message creation logic for a "bid" order under various scenarios, including error handling.


Line range hint 183-201: The test function TestSetupCmdTxCommitFunds correctly sets up and validates the command flags for committing funds in the market exchange context.


Line range hint 203-236: The test function TestMakeMsgCommitFunds thoroughly tests the message creation logic for committing funds under various scenarios, including error handling.


Line range hint 238-256: The test function TestSetupCmdTxCancelOrder correctly sets up and validates the command flags for canceling an order in the market exchange context.


Line range hint 258-291: The test function TestMakeMsgCancelOrder thoroughly tests the message creation logic for canceling an order under various scenarios, including error handling.


Line range hint 293-311: The test function TestSetupCmdTxFillBids correctly sets up and validates the command flags for filling bids in the market exchange context.


Line range hint 313-346: The test function TestMakeMsgFillBids thoroughly tests the message creation logic for filling bids under various scenarios, including error handling.


Line range hint 348-366: The test function TestSetupCmdTxFillAsks correctly sets up and validates the command flags for filling asks in the market exchange context.


Line range hint 368-401: The test function TestMakeMsgFillAsks thoroughly tests the message creation logic for filling asks under various scenarios, including error handling.


Line range hint 403-421: The test function TestSetupCmdTxMarketSettle correctly sets up and validates the command flags for market settlement in the market exchange context.


Line range hint 423-456: The test function TestMakeMsgMarketSettle thoroughly tests the message creation logic for market settlement under various scenarios, including error handling.


Line range hint 458-476: The test function TestSetupCmdTxMarketCommitmentSettle correctly sets up and validates the command flags for market commitment settlement in the market exchange context.


Line range hint 478-735: The test function TestMakeMsgMarketCommitmentSettle thoroughly tests the message creation logic for market commitment settlement under various scenarios, including error handling.


Line range hint 737-755: The test function TestSetupCmdTxMarketReleaseCommitments correctly sets up and validates the command flags for releasing market commitments in the market exchange context.


Line range hint 757-794: The test function TestMakeMsgMarketReleaseCommitments thoroughly tests the message creation logic for releasing market commitments under various scenarios, including error handling.


Line range hint 796-814: The test function TestSetupCmdTxMarketSetOrderExternalID correctly sets up and validates the command flags for setting an external ID on a market order in the market exchange context.


Line range hint 816-849: The test function TestMakeMsgMarketSetOrderExternalID thoroughly tests the message creation logic for setting an external ID on a market order under various scenarios, including error handling.


Line range hint 851-869: The test function TestSetupCmdTxMarketWithdraw correctly sets up and validates the command flags for withdrawing from a market in the market exchange context.


Line range hint 871-904: The test function TestMakeMsgMarketWithdraw thoroughly tests the message creation logic for withdrawing from a market under various scenarios, including error handling.

CHANGELOG.md (1)

95-95: The update to the CHANGELOG.md correctly reflects the integration of keyring functionality into the commitment-settlement-fee-calc CLI query as described in the PR summary and AI-generated summary.

Comment on lines +477 to +481
if addr, err := sdk.AccAddressFromBech32(clientCtx.From); err == nil {
clientCtx.FromAddress = addr
} else {
clientCtx.FromAddress, clientCtx.From, _, errs[1] = client.GetFromFields(clientCtx, clientCtx.Keyring, clientCtx.From)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Enhance error handling in address conversion logic.

The current implementation attempts to convert the from address from Bech32 format and falls back to the keyring if it fails. Consider adding more detailed error handling or logging to provide clearer feedback on what went wrong in case of an error. This could improve debugging and user experience.

-			clientCtx.FromAddress, clientCtx.From, _, errs[1] = client.GetFromFields(clientCtx, clientCtx.Keyring, clientCtx.From)
+			clientCtx.FromAddress, clientCtx.From, _, errs[1] = client.GetFromFields(clientCtx, clientCtx.Keyring, clientCtx.From)
+			if errs[1] != nil {
+				// Log or handle the error appropriately
+			}

Committable suggestion was skipped due low confidence.

SpicyLemon added a commit that referenced this pull request May 23, 2024
…rom is provided. (#2001)

* Update the MsgMarketCommitmentSettle cli stuff use the keyring if a from is provided.

* Add changelog entry.

* Add test case for unknown keyring name.
SpicyLemon added a commit that referenced this pull request May 24, 2024
…rom is provided. (#2001) (#2002)

* Update the MsgMarketCommitmentSettle cli stuff use the keyring if a from is provided.

* Add changelog entry.

* Add test case for unknown keyring name.
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.

3 participants