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

chore: main to develop #381

Closed
wants to merge 1 commit into from
Closed

chore: main to develop #381

wants to merge 1 commit into from

Conversation

CalicoNino
Copy link
Contributor

@CalicoNino CalicoNino commented Oct 18, 2024

…(#380)

  • revert: cosmos submodule only (revert: cosmos submodule only #362)

  • revert: cosmos submodule only

  • fix: rem

  • fix: rem

  • fix: update

  • feat: add msg client

  • fix: paths

  • fix: try chaosnet ibc

  • fix: path again

  • fix: try hm

  • fix: fixes to pass

  • feat: eth protos (feat: eth protos #366)

  • fix: eth protos

  • fix: client

  • fix: fixes

  • fix: try older nibiru

  • fix: index

  • fix: mainnet

  • fix: import

  • revert: build change

  • chore: tests (chore: tests #367)

  • fix: all query tests

  • chore: final tests

  • fix: buf

  • fix: fix

  • fix: pull latest

  • fix: build

  • fix: build

  • refactor(faucet)!: set default tokens (refactor(faucet)!: set default tokens #369)

  • chore: develop -> main (chore: develop -> main #368)

  • revert: cosmos submodule only (revert: cosmos submodule only #362)

  • revert: cosmos submodule only

  • fix: rem

  • fix: rem

  • fix: update

  • feat: add msg client

  • fix: paths

  • fix: try chaosnet ibc

  • fix: path again

  • fix: try hm

  • fix: fixes to pass

  • feat: eth protos (feat: eth protos #366)

  • fix: eth protos

  • fix: client

  • fix: fixes

  • fix: try older nibiru

  • fix: index

  • fix: mainnet

  • fix: import

  • revert: build change

  • chore: tests (chore: tests #367)

  • fix: all query tests

  • chore: final tests

  • fix: buf

  • fix: fix

  • fix: pull latest

  • fix: build

  • fix: build

  • chore(release): 4.5.1

4.5.1 (2024-08-09)

Miscellaneous Chores

[skip ci]

  • fix(faucet): remove unused tokens from default faucet request

  • fix: bump test


4.5.1 (2024-08-09)

Miscellaneous Chores

[skip ci]

  • fix(faucet): remove unused tokens from default faucet request

  • fix: bump test



4.5.2 (2024-09-24)

Miscellaneous Chores

[skip ci]


4.5.1 (2024-08-09)

Miscellaneous Chores

[skip ci]

  • fix(faucet): remove unused tokens from default faucet request

  • fix: bump test



4.5.2 (2024-09-24)

Miscellaneous Chores

[skip ci]

  • feat: nibiru account parser

  • refactor: throw if baseaccount is undefined

  • test: fixing tests

  • chore: removing unnecessary ?

  • refactor: matching cosmjs implementation

  • chore: removing t.json

  • chore: pr comments


  • chore: remove stats and update default feature flags

  • feat: cosmwasmclient extension & signingcosmwasmclient implementation (feat: cosmwasmclient extension & signingcosmwasmclient implementation #379)

  • feat: nibicosmwasmclient

  • feat: nibi signing cosm wasm client

  • refactor: adding nibi account parser to nibi signingcosmwasmclient

  • test: remove unused test file

  • test: take signingcosmwasmclient from coverage

  • chore: fix coverage


Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced NibiCosmWasmClient for enhanced interaction with CosmWasm smart contracts.
    • Added NibiSigningCosmWasmClient for signing transactions and managing contract interactions.
    • New functions for converting Ethereum accounts to Cosmos accounts.
  • Bug Fixes

    • Removed deprecated statistical methods and related test cases to streamline functionality.
  • Chores

    • Updated pre-commit hooks and Jest configuration for improved development workflow.
    • Added new dependencies to support recent features.
  • Documentation

    • Enhanced test coverage for account-related functionalities.

…380)

* revert: cosmos submodule only (#362)

* revert: cosmos submodule only

* fix: rem

* fix: rem

* fix: update

* feat: add msg client

* fix: paths

* fix: try chaosnet ibc

* fix: path again

* fix: try hm

* fix: fixes to pass

* feat: eth protos (#366)

* fix: eth protos

* fix: client

* fix: fixes

* fix: try older nibiru

* fix: index

* fix: mainnet

* fix: import

* revert: build change

* chore: tests (#367)

* fix: all query tests

* chore: final tests

* fix: buf

* fix: fix

* fix: pull latest

* fix: build

* fix: build

* refactor(faucet)!: set default tokens (#369)

* chore: develop -> main (#368)

* revert: cosmos submodule only (#362)

* revert: cosmos submodule only

* fix: rem

* fix: rem

* fix: update

* feat: add msg client

* fix: paths

* fix: try chaosnet ibc

* fix: path again

* fix: try hm

* fix: fixes to pass

* feat: eth protos (#366)

* fix: eth protos

* fix: client

* fix: fixes

* fix: try older nibiru

* fix: index

* fix: mainnet

* fix: import

* revert: build change

* chore: tests (#367)

* fix: all query tests

* chore: final tests

* fix: buf

* fix: fix

* fix: pull latest

* fix: build

* fix: build

* chore(release): 4.5.1

### [4.5.1](v4.5.0...v4.5.1) (2024-08-09)

### Miscellaneous Chores

* develop -> main ([#368](#368)) ([c6d6570](c6d6570)), closes [#362](#362) [#366](#366) [#367](#367)

 [skip ci]

* fix(faucet): remove unused tokens from default faucet request

* fix: bump test

---------

Co-authored-by: Cameron Gilbert <[email protected]>
Co-authored-by: semantic-release-bot <[email protected]>

* chore: main to develop (#375)

* chore: develop -> main (#370)

* revert: cosmos submodule only (#362)

* revert: cosmos submodule only

* fix: rem

* fix: rem

* fix: update

* feat: add msg client

* fix: paths

* fix: try chaosnet ibc

* fix: path again

* fix: try hm

* fix: fixes to pass

* feat: eth protos (#366)

* fix: eth protos

* fix: client

* fix: fixes

* fix: try older nibiru

* fix: index

* fix: mainnet

* fix: import

* revert: build change

* chore: tests (#367)

* fix: all query tests

* chore: final tests

* fix: buf

* fix: fix

* fix: pull latest

* fix: build

* fix: build

* refactor(faucet)!: set default tokens (#369)

* chore: develop -> main (#368)

* revert: cosmos submodule only (#362)

* revert: cosmos submodule only

* fix: rem

* fix: rem

* fix: update

* feat: add msg client

* fix: paths

* fix: try chaosnet ibc

* fix: path again

* fix: try hm

* fix: fixes to pass

* feat: eth protos (#366)

* fix: eth protos

* fix: client

* fix: fixes

* fix: try older nibiru

* fix: index

* fix: mainnet

* fix: import

* revert: build change

* chore: tests (#367)

* fix: all query tests

* chore: final tests

* fix: buf

* fix: fix

* fix: pull latest

* fix: build

* fix: build

* chore(release): 4.5.1

### [4.5.1](v4.5.0...v4.5.1) (2024-08-09)

### Miscellaneous Chores

* develop -> main ([#368](#368)) ([c6d6570](c6d6570)), closes [#362](#362) [#366](#366) [#367](#367)

 [skip ci]

* fix(faucet): remove unused tokens from default faucet request

* fix: bump test

---------

Co-authored-by: Cameron Gilbert <[email protected]>
Co-authored-by: semantic-release-bot <[email protected]>

---------

Co-authored-by: Kevin Yang <[email protected]>
Co-authored-by: semantic-release-bot <[email protected]>

* chore(github): Add project automation for https://tinyurl.com/25uty9w5

* chore(release): 4.5.2

### [4.5.2](v4.5.1...v4.5.2) (2024-09-24)

### Miscellaneous Chores

* develop -> main ([#370](#370)) ([ec2a25b](ec2a25b)), closes [#362](#362) [#366](#366) [#367](#367) [#369](#369) [#368](#368) [#362](#362) [#366](#366) [#367](#367) [#362](#362) [#366](#366) [#367](#367)
* **github:** Add project automation for https://tinyurl.com/25uty9w5 ([c2c27e5](c2c27e5))

 [skip ci]

---------

Co-authored-by: Cameron Gilbert <[email protected]>
Co-authored-by: Kevin Yang <[email protected]>
Co-authored-by: semantic-release-bot <[email protected]>
Co-authored-by: Unique Divine <[email protected]>

* feat: account parser (#374)

* chore: develop -> main (#370)

* revert: cosmos submodule only (#362)

* revert: cosmos submodule only

* fix: rem

* fix: rem

* fix: update

* feat: add msg client

* fix: paths

* fix: try chaosnet ibc

* fix: path again

* fix: try hm

* fix: fixes to pass

* feat: eth protos (#366)

* fix: eth protos

* fix: client

* fix: fixes

* fix: try older nibiru

* fix: index

* fix: mainnet

* fix: import

* revert: build change

* chore: tests (#367)

* fix: all query tests

* chore: final tests

* fix: buf

* fix: fix

* fix: pull latest

* fix: build

* fix: build

* refactor(faucet)!: set default tokens (#369)

* chore: develop -> main (#368)

* revert: cosmos submodule only (#362)

* revert: cosmos submodule only

* fix: rem

* fix: rem

* fix: update

* feat: add msg client

* fix: paths

* fix: try chaosnet ibc

* fix: path again

* fix: try hm

* fix: fixes to pass

* feat: eth protos (#366)

* fix: eth protos

* fix: client

* fix: fixes

* fix: try older nibiru

* fix: index

* fix: mainnet

* fix: import

* revert: build change

* chore: tests (#367)

* fix: all query tests

* chore: final tests

* fix: buf

* fix: fix

* fix: pull latest

* fix: build

* fix: build

* chore(release): 4.5.1

### [4.5.1](v4.5.0...v4.5.1) (2024-08-09)

### Miscellaneous Chores

* develop -> main ([#368](#368)) ([c6d6570](c6d6570)), closes [#362](#362) [#366](#366) [#367](#367)

 [skip ci]

* fix(faucet): remove unused tokens from default faucet request

* fix: bump test

---------

Co-authored-by: Cameron Gilbert <[email protected]>
Co-authored-by: semantic-release-bot <[email protected]>

---------

Co-authored-by: Kevin Yang <[email protected]>
Co-authored-by: semantic-release-bot <[email protected]>

* chore(github): Add project automation for https://tinyurl.com/25uty9w5

* chore(release): 4.5.2

### [4.5.2](v4.5.1...v4.5.2) (2024-09-24)

### Miscellaneous Chores

* develop -> main ([#370](#370)) ([ec2a25b](ec2a25b)), closes [#362](#362) [#366](#366) [#367](#367) [#369](#369) [#368](#368) [#362](#362) [#366](#366) [#367](#367) [#362](#362) [#366](#366) [#367](#367)
* **github:** Add project automation for https://tinyurl.com/25uty9w5 ([c2c27e5](c2c27e5))

 [skip ci]

* feat: nibiru account parser

* refactor: throw if baseaccount is undefined

* test: fixing tests

* chore: removing unnecessary ?

* refactor: matching cosmjs implementation

* chore: removing t.json

* chore: pr comments

---------

Co-authored-by: Cameron Gilbert <[email protected]>
Co-authored-by: Kevin Yang <[email protected]>
Co-authored-by: semantic-release-bot <[email protected]>
Co-authored-by: Unique Divine <[email protected]>

* chore: remove stats and update default feature flags

* feat: cosmwasmclient extension & signingcosmwasmclient implementation (#379)

* feat: nibicosmwasmclient

* feat: nibi signing cosm wasm client

* refactor: adding nibi account parser to nibi signingcosmwasmclient

* test: remove unused test file

* test: take signingcosmwasmclient from coverage

* chore: fix coverage

---------

Co-authored-by: Kevin Yang <[email protected]>
Co-authored-by: semantic-release-bot <[email protected]>
Co-authored-by: Calico Nino <[email protected]>
Co-authored-by: Unique Divine <[email protected]>
@CalicoNino CalicoNino self-assigned this Oct 18, 2024
Copy link
Contributor

coderabbitai bot commented Oct 18, 2024

Walkthrough

The pull request introduces several modifications across multiple files, primarily focusing on the removal of statistical functionalities from the heart monitor module and the introduction of new client classes for interacting with CosmWasm smart contracts. Key changes include the addition of a pre-commit hook command, updates to Jest configuration for coverage exclusions, and enhancements to account handling in the Cosmos ecosystem. The overall structure remains intact, but significant functionalities related to statistics have been eliminated.

Changes

File Change Summary
.husky/pre-commit Added command yarn generate-barrels after yarn lint-staged.
jest.config.ts Excluded src/sdk/core/cosmwasmclient.ts and src/sdk/core/signingcosmwasmclient.ts from coverage collection.
package.json Added dependency "pako": "^2.1.0" and development dependency "@types/pako": "^2.0.3".
src/gql/heart-monitor/heart-monitor.test.ts Removed imports and test cases related to statistics.
src/gql/heart-monitor/heart-monitor.ts Removed stats method from IHeartMonitor interface and HeartMonitor class, along with related imports.
src/gql/query/index.ts Removed export of ./stats module.
src/gql/query/stats.ts Deleted file containing statistical query functionality, including types and interfaces.
src/gql/utils/defaultObjects.ts Removed several constants related to statistics and updated feature flags.
src/sdk/core/cosmwasmclient.ts Introduced NibiCosmWasmClient class for enhanced CosmWasm interactions.
src/sdk/core/signingcosmwasmclient.ts Introduced NibiSigningCosmWasmClient class for enhanced signing functionalities.
src/sdk/tx/account.test.ts Added unit tests for accountFromEthAccount and accountFromNibiru functions.
src/sdk/tx/account.ts Introduced accountFromEthAccount and accountFromNibiru functions for account handling.
src/sdk/tx/index.ts Added export statement for ./account module.
src/sdk/tx/txClient.ts Updated to use NibiSigningCosmWasmClient and its options in the NibiruTxClient class.

Assessment against linked issues

Objective Addressed Explanation
Revert cosmos submodule as we no longer need to generate protos for it (#362) The changes do not address the need to revert the cosmos submodule.

Possibly related PRs

🐰 In the code, I hop and play,
With barrels generated every day.
Stats are gone, but clients are here,
For smart contracts, let’s give a cheer!
New functions added, tests in sight,
In the Cosmos world, we take flight! 🌟


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

🧹 Outside diff range and nitpick comments (6)
.husky/pre-commit (1)

Line range hint 1-5: LGTM! Consider optimizing the pre-commit hook.

The addition of yarn generate-barrels to the pre-commit hook is a good practice to ensure barrel files are always up-to-date. However, consider the following suggestions:

  1. Verify the order of operations: Ensure that running generate-barrels after lint-staged doesn't create any conflicts or undo any linting fixes.

  2. For efficiency, you might want to combine these commands using the && operator:

yarn lint-staged && yarn generate-barrels

This ensures that generate-barrels only runs if lint-staged passes, potentially saving time on failed commits.

src/sdk/tx/account.test.ts (3)

16-49: LGTM: Test suite for accountFromEthAccount is comprehensive.

The test suite for accountFromEthAccount covers both error handling and successful execution scenarios. The tests are well-structured and use appropriate assertions.

Consider adding the following test cases to improve coverage:

  1. Test with a baseAccount that has a null pubKey.
  2. Test with extreme values for accountNumber and sequence.
  3. Test with a baseAccount that has all fields set to their minimum allowed values.

51-105: LGTM: Test suite for accountFromNibiru is well-structured.

The test suite for accountFromNibiru covers both EthAccount and non-EthAccount scenarios. The tests are comprehensive and use appropriate mocking techniques.

Consider the following improvements:

  1. Add a test case for handling invalid input (e.g., malformed Any object).
  2. Test edge cases such as empty address or extremely large accountNumber/sequence values.
  3. In the second test case, consider asserting on more properties of the returned account object, not just the address.

To improve test isolation, consider moving the mock setup for cosmjs.accountFromAny outside the test case:

let mockAccountFromAny: jest.SpyInstance;

beforeEach(() => {
  mockAccountFromAny = jest.spyOn(cosmjs, "accountFromAny").mockReturnValue({
    address: "nibi1otheraddress",
    pubkey: null,
    accountNumber: 789,
    sequence: 3,
  });
});

afterEach(() => {
  mockAccountFromAny.mockRestore();
});

This setup allows for easier modification of the mock behavior in individual test cases if needed.


1-105: Overall, the test file is well-structured and provides good coverage.

The test suites for both accountFromEthAccount and accountFromNibiru are comprehensive and well-implemented. They cover the main scenarios and use appropriate mocking and assertion techniques.

To further improve the test file:

  1. Consider adding more edge cases and error scenarios to increase robustness.
  2. Implement parameterized tests for scenarios that can be tested with multiple inputs.
  3. Add tests for any untested error conditions in the original functions.
  4. Consider using a test coverage tool to identify any uncovered code paths.

These improvements will help ensure the reliability and maintainability of the account-related functions in your SDK.

src/sdk/core/cosmwasmclient.ts (1)

54-55: Clarify the error message when an account does not exist

The current error message suggests sending tokens to the account, which might not always be the solution. An account can exist without tokens, especially in certain blockchain networks.

Consider revising the error message for accuracy:

`Account '${address}' does not exist on chain. Send some tokens there before trying to query sequence.`
+`Account '${address}' does not exist on the chain. Ensure the account has been initialized before querying the sequence.`
src/sdk/core/signingcosmwasmclient.ts (1)

199-243: Efficient compression level in 'upload' method

In the upload method (lines 199-243), the WASM bytecode is compressed using pako.gzip with a compression level of 9. While level 9 offers maximum compression, it may have performance implications. Consider using a lower compression level (e.g., 6 or 7) for a balance between compression efficiency and performance.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b89a700 and 087d569.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (14)
  • .husky/pre-commit (1 hunks)
  • jest.config.ts (1 hunks)
  • package.json (2 hunks)
  • src/gql/heart-monitor/heart-monitor.test.ts (0 hunks)
  • src/gql/heart-monitor/heart-monitor.ts (0 hunks)
  • src/gql/query/index.ts (0 hunks)
  • src/gql/query/stats.ts (0 hunks)
  • src/gql/utils/defaultObjects.ts (1 hunks)
  • src/sdk/core/cosmwasmclient.ts (1 hunks)
  • src/sdk/core/signingcosmwasmclient.ts (1 hunks)
  • src/sdk/tx/account.test.ts (1 hunks)
  • src/sdk/tx/account.ts (1 hunks)
  • src/sdk/tx/index.ts (1 hunks)
  • src/sdk/tx/txClient.ts (3 hunks)
💤 Files with no reviewable changes (4)
  • src/gql/heart-monitor/heart-monitor.test.ts
  • src/gql/heart-monitor/heart-monitor.ts
  • src/gql/query/index.ts
  • src/gql/query/stats.ts
✅ Files skipped from review due to trivial changes (1)
  • src/sdk/tx/index.ts
🧰 Additional context used
🔇 Additional comments (15)
jest.config.ts (1)

25-26: Exclusion of Cosmjs implementations from coverage is appropriate.

The addition of these two files to the coverage exclusion list is reasonable:

  1. src/sdk/core/cosmwasmclient.ts
  2. src/sdk/core/signingcosmwasmclient.ts

These files are noted as implementations from Cosmjs, which is an external library. It's generally a good practice to exclude external implementations from your project's test coverage metrics, as you're not responsible for testing third-party code.

However, to ensure this change aligns with the project's goals:

  1. Verify that these files are indeed direct implementations from Cosmjs without significant modifications.
  2. Ensure that the functionality these files provide is still adequately tested through integration or end-to-end tests.
  3. Consider adding a comment in the respective files indicating why they are excluded from coverage, to prevent future confusion.

To confirm the nature of these files, let's examine their contents:

This will help us confirm that these files are indeed Cosmjs implementations and that excluding them from coverage is appropriate.

✅ Verification successful

Exclusion of Cosmjs Implementations from Coverage Confirmed.

Based on the contents of the excluded files:

  1. src/sdk/core/cosmwasmclient.ts
  2. src/sdk/core/signingcosmwasmclient.ts

Both files primarily import and extend classes from Cosmjs libraries without significant custom modifications. Excluding these files from test coverage is appropriate, as they rely on well-tested external implementations.

Recommendations:

  • Add Explanatory Comments: Include comments in each excluded file explaining the reason for their exclusion from coverage. This will aid future developers in understanding the rationale and prevent unnecessary confusion.

    // Excluded from test coverage as this is a direct implementation from Cosmjs.
  • Ensure Adequate Testing: Verify that the functionalities provided by these implementations are covered through integration or end-to-end tests to maintain overall test reliability.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the contents of the excluded files

# Check if the files exist and display their contents
for file in src/sdk/core/cosmwasmclient.ts src/sdk/core/signingcosmwasmclient.ts; do
    if [ -f "$file" ]; then
        echo "Contents of $file:"
        cat "$file" | head -n 20  # Display first 20 lines
        echo "..."
    else
        echo "File $file does not exist."
    fi
done

Length of output: 1669

src/sdk/tx/account.test.ts (2)

1-7: LGTM: Import statements are appropriate and concise.

The import statements are well-organized and include all necessary dependencies for the tests. No unused imports are present.


9-14: LGTM: Mock setup for decodeOptionalPubkey is correct.

The mock setup for decodeOptionalPubkey is implemented correctly using Jest. The use of jest.Mock for typing is a good practice for maintaining type safety in tests.

package.json (2)

Line range hint 1-124: Changes align with PR objectives and version update.

The modifications to package.json are minimal and focused, adding only the necessary dependencies. The version number (4.5.2) is consistent with the release update mentioned in the PR objectives. These changes contribute to the overall goal of improving the stability and functionality of the codebase.


49-50: LGTM. Please provide more context on the usage of pako.

The addition of pako and its type definitions is syntactically correct and follows best practices. However, it would be helpful to understand the specific use case for this compression library in the project.

To ensure pako is being utilized in the project, let's search for its usage:

Can you provide more information on where and how pako will be used in the project?

Also applies to: 71-71

✅ Verification successful

Verified usage of pako in the project.

The pako library is imported in src/sdk/core/signingcosmwasmclient.ts, confirming its usage within the project.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for pako usage in TypeScript files
rg --type typescript 'import.*pako' || echo "No direct imports of pako found."
rg --type typescript 'require.*pako' || echo "No require statements for pako found."

Length of output: 306


Script:

#!/bin/bash
# Search for pako usage in TypeScript (.ts and .tsx) files
rg --glob "*.ts" 'import.*pako' || echo "No direct imports of pako found in .ts files."
rg --glob "*.ts" 'require.*pako' || echo "No require statements for pako found in .ts files."
rg --glob "*.tsx" 'import.*pako' || echo "No direct imports of pako found in .tsx files."
rg --glob "*.tsx" 'require.*pako' || echo "No require statements for pako found in .tsx files."

Length of output: 826

src/gql/utils/defaultObjects.ts (1)

345-346: LGTM. Verify impact and update documentation.

The changes to defaultFeatureFlags look good. Disabling the perp and spot flags by default aligns with the PR objectives of transitioning between branches and implementing various fixes.

To ensure this change doesn't introduce unintended side effects:

  1. Verify that all code depending on these flags handles the disabled state correctly.
  2. Update any relevant documentation or configuration guides to reflect this change.

Run the following script to find potential areas affected by this change:

Review the results to ensure that the disabled state is handled appropriately in all cases.

✅ Verification successful

Verified: No usages of perp and spot feature flags found.

The changes to defaultFeatureFlags are safe and do not affect other parts of the codebase. Disabling the perp and spot flags by default does not introduce any unintended side effects.

  • No references to featureFlags.perp or featureFlags.spot were found in the codebase.
  • Ensure that any related documentation is updated to reflect these changes.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of perp and spot feature flags
echo "Searching for perp feature flag usage:"
rg --type typescript 'featureFlags.perp' -C 3
echo "Searching for spot feature flag usage:"
rg --type typescript 'featureFlags.spot' -C 3

Length of output: 335


Script:

#!/bin/bash
# Search for usages of perp and spot feature flags in .ts files
echo "Searching for perp feature flag usage:"
fd --extension ts --type file | xargs rg 'featureFlags\.perp' -C 3
echo "Searching for spot feature flag usage:"
fd --extension ts --type file | xargs rg 'featureFlags\.spot' -C 3

Length of output: 311

src/sdk/tx/account.ts (1)

1-6: LGTM on import statements

The import statements are well-structured and correctly include all necessary dependencies. They align with the project's conventions.

src/sdk/core/cosmwasmclient.ts (2)

51-61: 🛠️ Refactor suggestion

Leverage existing methods from the superclass

The getSequence method may already be provided by the CosmWasmClient superclass. Reimplementing it can lead to code duplication.

Check if CosmWasmClient has a getSequence method and use it directly:

-public async getSequence(address: string): Promise<SequenceResponse> {
-  const account = await this.getAccount(address)
-  if (!account) {
-    throw new Error(
-      `Account '${address}' does not exist on the chain. Ensure the account has been initialized before querying the sequence.`
-    )
-  }
-  return {
-    accountNumber: account.accountNumber,
-    sequence: account.sequence,
-  }
-}
+// Remove this method if it's already implemented in the superclass

If additional functionality is needed, consider calling super.getSequence(address) and extending the result.

Likely invalid or redundant comment.


32-32: ⚠️ Potential issue

Avoid accessing private properties of the superclass

Accessing cosmWasmClient["cometClient"] directly may lead to issues if cometClient is a private or protected property of CosmWasmClient. This approach can break encapsulation and may cause errors if the internal implementation changes in future versions.

Consider modifying the CosmWasmClient class or using public APIs to obtain the necessary client. Here's a possible correction assuming tmClient is a public property:

-return new NibiCosmWasmClient(cosmWasmClient["cometClient"], options)
+return new NibiCosmWasmClient(cosmWasmClient.tmClient, options)

If tmClient is not accessible, you might need to adjust your approach to avoid accessing private properties.

⛔ Skipped due to learnings
Learnt from: CalicoNino
PR: NibiruChain/ts-sdk#379
File: src/sdk/core/cosmwasmclient.ts:32-32
Timestamp: 2024-10-16T19:03:21.863Z
Learning: In our codebase, it's acceptable to access private properties of base classes using bracket notation when necessary.
src/sdk/core/signingcosmwasmclient.ts (1)

659-697: Ensure consistent signer type checks in 'sign' method

In the sign method, the check for isOfflineDirectSigner(this.signer) is performed, and based on that, it calls either signDirect or signAmino. Ensure that the signer supports both signing methods or handle cases where only one method is supported to prevent runtime errors.

src/sdk/tx/txClient.ts (5)

55-55: Update calls to 'connectWithSigner' with new options type

The connectWithSigner method now accepts NibiSigningCosmWasmClientOptions for wasmOptions. Ensure that:

  • All calls to NibiruTxClient.connectWithSigner are updated to pass the correct wasmOptions.
  • The options provided are compatible with NibiSigningCosmWasmClientOptions.

Run the following script to locate and review method calls:

#!/bin/bash
# Description: Find all calls to 'NibiruTxClient.connectWithSigner' and check the options parameter.

# Test: Search for 'NibiruTxClient\.connectWithSigner' calls.
# Expect: 'wasmOptions' parameter matches the new type.

rg 'NibiruTxClient\.connectWithSigner' --type ts -A 5

29-29: Ensure compatibility with 'NibiSigningCosmWasmClient'

The wasmClient property and constructor parameter have been updated to use NibiSigningCosmWasmClient. Verify that:

  • All methods and properties used from wasmClient are compatible with NibiSigningCosmWasmClient.
  • Any extensions or plugins relying on SigningCosmWasmClient are updated accordingly.

Run the following script to find usages of wasmClient methods:

#!/bin/bash
# Description: Find all usages of 'wasmClient' methods to ensure compatibility.

# Test: Search for 'this\.wasmClient\.\w+' pattern.
# Expect: Methods used are compatible with 'NibiSigningCosmWasmClient'.

rg 'this\.wasmClient\.\w+' --type ts

Also applies to: 35-35


63-63: Validate 'accountParser' implementation with 'accountFromNibiru'

The accountParser option is set to accountFromNibiru. Ensure that:

  • accountFromNibiru correctly implements the expected interface.
  • The parser properly handles account data in the context of Nibiru.

Run the following script to inspect the implementation:

#!/bin/bash
# Description: Verify that 'accountFromNibiru' conforms to expected standards.

# Test: Check the definition of 'accountFromNibiru'.
# Expect: Function matches the required signature and behavior.

fd 'account.ts' | xargs rg 'export function accountFromNibiru' -A 5

Also applies to: 74-74


58-63: Confirm proper usage of 'NibiSigningCosmWasmClient.connectWithSigner'

The instantiation of NibiSigningCosmWasmClient replaces the previous client. Verify that:

  • The parameters passed to connectWithSigner are correct and complete.
  • The gasPrice and accountParser options are appropriate for the new client.

Run the following script to check for other invocations and ensure consistency:

✅ Verification successful

Usage of NibiSigningCosmWasmClient.connectWithSigner is properly configured

Parameters passed to connectWithSigner are correct and complete. Both gasPrice and accountParser options are appropriately set and consistent with the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all invocations of 'NibiSigningCosmWasmClient.connectWithSigner'.

# Test: Search for 'NibiSigningCosmWasmClient\.connectWithSigner' calls.
# Expect: Parameters are correctly set.

rg 'NibiSigningCosmWasmClient\.connectWithSigner' --type ts -A 5

Length of output: 140


Script:

#!/bin/bash
# Description: Find the definition of 'GasPrice.fromString'.

rg 'GasPrice\.fromString' --type ts -A 5

Length of output: 689


Script:

#!/bin/bash
# Description: Find the definition and usages of 'accountFromNibiru'.

rg 'accountFromNibiru' --type ts -A 5

Length of output: 2822


15-21: Verify new imports and dependencies

The imports of setupWasmExtension, accountFromNibiru, NibiSigningCosmWasmClient, and NibiSigningCosmWasmClientOptions introduce new dependencies and modules.

  • Ensure that these modules are correctly installed and the import paths are accurate.
  • Verify that the versions of the imported packages are compatible with the existing codebase.

Run the following script to verify the existence and export of these modules:

Comment on lines +11 to +14
* @param {EthAccount} ethAccount - The EthAccount object containing the account's base information.
* @returns {Account} The Cosmos account object.
*/
export const accountFromEthAccount = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix parameter type mismatch in JSDoc comment

The JSDoc comment specifies that the parameter ethAccount is of type EthAccount, but the function actually destructures a BaseAccount. To maintain accuracy and avoid confusion, update the JSDoc comment to reflect the correct parameter type.

Apply this diff to correct the JSDoc comment:

 /**
- * @param {EthAccount} ethAccount - The EthAccount object containing the account's base information.
+ * @param {BaseAccount} baseAccount - The BaseAccount object containing the account's base information.
  * @returns {Account} The Cosmos account object.
  */
 export const accountFromEthAccount = ({
📝 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
* @param {EthAccount} ethAccount - The EthAccount object containing the account's base information.
* @returns {Account} The Cosmos account object.
*/
export const accountFromEthAccount = ({
/**
* @param {BaseAccount} baseAccount - The BaseAccount object containing the account's base information.
* @returns {Account} The Cosmos account object.
*/
export const accountFromEthAccount = ({

Comment on lines +36 to +38
const baseAccount = EthAccount.decode(value).baseAccount
assert(baseAccount)
return accountFromEthAccount(baseAccount)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance error handling for missing baseAccount

Currently, the code uses assert(baseAccount) to ensure baseAccount exists. If baseAccount is undefined, this will throw a generic assertion error. Consider throwing a more descriptive error to provide clearer context during debugging.

Apply this diff to improve error handling:

 if (typeUrl === "/eth.types.v1.EthAccount") {
   const baseAccount = EthAccount.decode(value).baseAccount
-  assert(baseAccount)
+  if (!baseAccount) {
+    throw new Error("Failed to decode baseAccount from EthAccount.")
+  }
   return accountFromEthAccount(baseAccount)
 }
📝 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 baseAccount = EthAccount.decode(value).baseAccount
assert(baseAccount)
return accountFromEthAccount(baseAccount)
const baseAccount = EthAccount.decode(value).baseAccount
if (!baseAccount) {
throw new Error("Failed to decode baseAccount from EthAccount.")
}
return accountFromEthAccount(baseAccount)

)
return account ? this.accountParser(account) : null
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid suppressing ESLint rules by properly typing errors

Disabling ESLint rules can mask potential issues. Instead of using any for the error type and disabling the rule, use unknown and perform type checking within the catch block.

Here's how you can modify the code:

-// eslint-disable-next-line @typescript-eslint/no-explicit-any
-} catch (error: any) {
+} catch (error: unknown) {

Then, inside the catch block, you can narrow down the error type:

if (error instanceof Error) {
  // Now you can safely access error properties
}


public async getAccount(searchAddress: string): Promise<Account | null> {
try {
const account = await this.forceGetQueryClient().auth.account(
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use public methods instead of protected ones

The method forceGetQueryClient() is a protected method in CosmWasmClient. Calling it from a subclass can lead to tight coupling and potential issues if the superclass changes its implementation.

Use the public getQueryClient() method instead:

-const account = await this.forceGetQueryClient().auth.account(
+const account = await this.getQueryClient().auth.account(
  searchAddress
)
📝 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 account = await this.forceGetQueryClient().auth.account(
const account = await this.getQueryClient().auth.account(

Comment on lines +42 to +46
} catch (error: any) {
if (/rpc error: code = NotFound/i.test(error.toString())) {
return null
}
throw error
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve error handling by avoiding string matching

Relying on regular expressions to match error messages can be fragile and may fail if the error message format changes. It's better to handle errors based on error codes or specific error types.

If the error object contains a code property, you can handle it like this:

-} catch (error: any) {
-  if (/rpc error: code = NotFound/i.test(error.toString())) {
+} catch (error) {
+  if (error.code === "NotFound" || error.code === 5) { // 5 is the gRPC code for NOT_FOUND
     return null
   }
   throw error
 }

Ensure that the error object conforms to a known error interface to reliably access the code property.

Committable suggestion was skipped due to low confidence.

Comment on lines +570 to +607
public async signAndBroadcast(
signerAddress: string,
messages: readonly EncodeObject[],
fee: FeeOption,
memo = "",
timeoutHeight?: bigint
): Promise<DeliverTxResponse> {
let usedFee: StdFee
if (fee == "auto" || typeof fee === "number") {
assertDefined(
this.gasPrice,
"Gas price must be set in the client options when auto gas is used."
)
const gasEstimation = await this.simulate(signerAddress, messages, memo)
const multiplier =
typeof fee === "number" ? fee : this.defaultGasMultiplier
usedFee = calculateFee(
Math.round(gasEstimation * multiplier),
this.gasPrice
)
} else {
usedFee = fee
}
const txRaw = await this.sign(
signerAddress,
messages,
usedFee,
memo,
undefined,
timeoutHeight
)
const txBytes = TxRaw.encode(txRaw).finish()
return this.broadcastTx(
txBytes,
this.broadcastTimeoutMs,
this.broadcastPollIntervalMs
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Refactor duplicated code in 'signAndBroadcast' methods

The signAndBroadcast (lines 570-607) and signAndBroadcastSync (lines 625-657) methods contain duplicated code for fee calculation and transaction signing. To follow the DRY (Don't Repeat Yourself) principle, consider extracting the shared logic into a private helper method.

Apply this diff to refactor the common code:

+private async prepareSignedTx(
+  signerAddress: string,
+  messages: readonly EncodeObject[],
+  fee: FeeOption,
+  memo: string,
+  timeoutHeight?: bigint
+): Promise<TxRaw> {
+  let usedFee: StdFee
+  if (fee == "auto" || typeof fee === "number") {
+    assertDefined(
+      this.gasPrice,
+      "Gas price must be set in the client options when auto gas is used."
+    )
+    const gasEstimation = await this.simulate(signerAddress, messages, memo)
+    const multiplier = typeof fee === "number" ? fee : this.defaultGasMultiplier
+    usedFee = calculateFee(
+      Math.round(gasEstimation * multiplier),
+      this.gasPrice
+    )
+  } else {
+    usedFee = fee
+  }
+  return await this.sign(
+    signerAddress,
+    messages,
+    usedFee,
+    memo,
+    undefined,
+    timeoutHeight
+  )
+}

 public async signAndBroadcast(
   signerAddress: string,
   messages: readonly EncodeObject[],
   fee: FeeOption,
   memo = "",
   timeoutHeight?: bigint
 ): Promise<DeliverTxResponse> {
-  let usedFee: StdFee
-  if (fee == "auto" || typeof fee === "number") {
-    assertDefined(
-      this.gasPrice,
-      "Gas price must be set in the client options when auto gas is used."
-    )
-    const gasEstimation = await this.simulate(signerAddress, messages, memo)
-    const multiplier =
-      typeof fee === "number" ? fee : this.defaultGasMultiplier
-    usedFee = calculateFee(
-      Math.round(gasEstimation * multiplier),
-      this.gasPrice
-    )
-  } else {
-    usedFee = fee
-  }
-  const txRaw = await this.sign(
-    signerAddress,
-    messages,
-    usedFee,
-    memo,
-    undefined,
-    timeoutHeight
-  )
+  const txRaw = await this.prepareSignedTx(
+    signerAddress,
+    messages,
+    fee,
+    memo,
+    timeoutHeight
+  )
   const txBytes = TxRaw.encode(txRaw).finish()
   return this.broadcastTx(
     txBytes,
     this.broadcastTimeoutMs,
     this.broadcastPollIntervalMs
   )
 }

 public async signAndBroadcastSync(
   signerAddress: string,
   messages: readonly EncodeObject[],
   fee: FeeOption,
   memo = "",
   timeoutHeight?: bigint
 ): Promise<string> {
-  let usedFee: StdFee
-  if (fee == "auto" || typeof fee === "number") {
-    assertDefined(
-      this.gasPrice,
-      "Gas price must be set in the client options when auto gas is used."
-    )
-    const gasEstimation = await this.simulate(signerAddress, messages, memo)
-    const multiplier =
-      typeof fee === "number" ? fee : this.defaultGasMultiplier
-    usedFee = calculateFee(
-      Math.round(gasEstimation * multiplier),
-      this.gasPrice
-    )
-  } else {
-    usedFee = fee
-  }
-  const txRaw = await this.sign(
-    signerAddress,
-    messages,
-    usedFee,
-    memo,
-    undefined,
-    timeoutHeight
-  )
+  const txRaw = await this.prepareSignedTx(
+    signerAddress,
+    messages,
+    fee,
+    memo,
+    timeoutHeight
+  )
   const txBytes = TxRaw.encode(txRaw).finish()
   return this.broadcastTxSync(txBytes)
 }

Also applies to: 625-657

isDeliverTxFailure,
logs,
} from "@cosmjs/stargate"
import { findAttribute } from "@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Incorrect import path for 'findAttribute'

The import statement on line 56 is importing findAttribute from an internal build path, which is not recommended and could lead to issues if the internal structure changes. It's better to import from the public API provided by the package.

Apply this diff to correct the import path:

-import { findAttribute } from "@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient"
+import { findAttribute } from "@cosmjs/cosmwasm-stargate"
📝 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
import { findAttribute } from "@cosmjs/cosmwasm-stargate/build/signingcosmwasmclient"
import { findAttribute } from "@cosmjs/cosmwasm-stargate"

@cgilbe27 cgilbe27 closed this Oct 18, 2024
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