Skip to content

fix: launch_spot_market_atom#257

Merged
jbernal87 merged 6 commits into
devfrom
fix/injective_testing
Jun 7, 2025
Merged

fix: launch_spot_market_atom#257
jbernal87 merged 6 commits into
devfrom
fix/injective_testing

Conversation

@jbernal87
Copy link
Copy Markdown
Contributor

@jbernal87 jbernal87 commented Jun 7, 2025

chore: add launch_spot_market_custom_v2

Summary by CodeRabbit

  • New Features

    • Added a build script to automate the building of CosmWasm smart contracts with Docker, supporting contract selection and system architecture detection.
    • Introduced a new function to support launching spot markets with customizable decimal precision in the testing utilities.
  • Refactor

    • Updated test and utility code to use mock denomination and decimal constants for improved consistency in testing.
    • Replaced local utility functions with imports from shared testing modules.
  • Bug Fixes

    • Ensured uniform use of mock values in test setups and validations.
  • Chores

    • Removed unused dependencies from the testing package and incremented its version.

chore: add launch_spot_market_custom_v2
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 7, 2025

Walkthrough

A new build.sh script is introduced to automate CosmWasm contract builds using Docker. Several Rust files are refactored to replace hardcoded denomination and decimal constants with mock constants for consistency in testing. Unused local utility functions are removed. The injective-testing package version is incremented, and a new function is added for launching spot markets with custom decimal support.

Changes

Files/Groups Change Summary
build.sh New shell script added for Docker-based CosmWasm contract builds with architecture detection and caching.
contracts/injective-cosmwasm-mock/src/testing/test_exchange.rs
contracts/injective-cosmwasm-mock/src/utils.rs
Replaced hardcoded denom/decimal constants with mock constants; updated imports; removed local utility functions.
packages/injective-testing/Cargo.toml Version bumped to 1.1.10; removed base64 and test-tube-inj dependencies.
packages/injective-testing/src/test_tube/exchange.rs Updated denom/decimal usage in functions; added launch_spot_market_custom_v2 supporting custom decimals.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant build.sh
    participant Docker
    participant CosmWasm Optimizer

    User->>build.sh: Run script with optional contract name
    build.sh->>build.sh: Validate contract directory
    alt ARM64 platform
        build.sh->>Docker: Use ARM64 image tag
    else
        build.sh->>Docker: Use default image tag
    end
    build.sh->>Docker: Mount workspace and caches, run optimizer
    Docker->>CosmWasm Optimizer: Build contract
    CosmWasm Optimizer-->>Docker: Output optimized .wasm
    Docker-->>build.sh: Build complete
    build.sh-->>User: Optimized contract artifact available
Loading

Poem

In the garden where code does grow,
A script hops in to build and show—
With Docker's help, the contracts bloom,
Mock denoms now in every room.
Version bumps and functions new,
The testing fields are fresh with dew!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 277a435 and 76b3e20.

📒 Files selected for processing (1)
  • Cargo.toml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Cargo.toml
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Lints
  • GitHub Check: Test Suite
  • GitHub Check: Lints
  • GitHub Check: Test Suite

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@jbernal87 jbernal87 marked this pull request as ready for review June 7, 2025 16:06
Copy link
Copy Markdown

@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

🔭 Outside diff range comments (4)
packages/injective-testing/src/test_tube/exchange.rs (1)

533-547: ⚠️ Potential issue

Verify ticker parameter usage in launch_spot_market_atom.

The function parameter ticker is accepted but then overridden with a hardcoded "ATOM/USDT" string on line 533. This seems inconsistent - either use the parameter or remove it.

 pub fn launch_spot_market_atom(exchange: &Exchange<InjectiveTestApp>, signer: &SigningAccount, ticker: String) -> String {
     exchange
         .instant_spot_market_launch_v2(
             v2::MsgInstantSpotMarketLaunch {
                 sender: signer.address(),
-                ticker: "ATOM/USDT".to_owned(),
+                ticker: ticker.clone(),
contracts/injective-cosmwasm-mock/src/utils.rs (3)

329-329: 🛠️ Refactor suggestion

Incomplete migration to mock constants.

This line still uses the hardcoded QUOTE_DECIMALS constant instead of MOCK_QUOTE_DECIMALS.

-                    amount: human_to_dec("1_000", QUOTE_DECIMALS).to_string(),
+                    amount: human_to_dec("1_000", MOCK_QUOTE_DECIMALS).to_string(),

344-346: 🛠️ Refactor suggestion

Hardcoded constants remain in perpetual market launch.

The launch_perp_market function still uses hardcoded QUOTE_DENOM and BASE_DENOM constants instead of mock constants.

                ticker: ticker.to_owned(),
-                quote_denom: QUOTE_DENOM.to_string(),
-                oracle_base: BASE_DENOM.to_string(),
-                oracle_quote: QUOTE_DENOM.to_string(),
+                quote_denom: MOCK_QUOTE_DENOM.to_string(),
+                oracle_base: MOCK_BASE_DENOM.to_string(),
+                oracle_quote: MOCK_QUOTE_DENOM.to_string(),

430-430: 🛠️ Refactor suggestion

Multiple locations still use hardcoded decimal constants.

Several functions still reference the local BASE_DECIMALS and QUOTE_DECIMALS constants instead of the mock equivalents.

Apply these fixes for complete consistency:

    for order in orders {
-        let (price, quantity) = scale_price_quantity_for_spot_market(order.price.as_str(), order.quantity.as_str(), &BASE_DECIMALS, &QUOTE_DECIMALS);
+        let (price, quantity) = scale_price_quantity_for_spot_market(order.price.as_str(), order.quantity.as_str(), &MOCK_BASE_DECIMALS, &MOCK_QUOTE_DECIMALS);
        add_spot_order_as(app, market_id.to_owned(), &trader, price, quantity, order.order_type);
    }
    for order in orders {
        let (price, quantity, order_margin) =
-            scale_price_quantity_perp_market(order.price.as_str(), order.quantity.as_str(), &margin, &QUOTE_DECIMALS);
+            scale_price_quantity_perp_market(order.price.as_str(), order.quantity.as_str(), &margin, &MOCK_QUOTE_DECIMALS);
        add_derivative_order_as(app, market_id.to_owned(), &trader, price, quantity, order.order_type, order_margin);
    }

Also applies to: 547-548, 556-556

🧹 Nitpick comments (3)
build.sh (3)

18-20: Consider using more portable architecture detection.

The current architecture detection only checks for arm64. Consider using a more comprehensive approach that handles other architectures.

-if [[ $(arch) = "arm64" ]]; then
+if [[ $(uname -m) = "arm64" || $(uname -m) = "aarch64" ]]; then

35-39: Review Docker security considerations.

The script mounts the current directory and home cargo cache. Ensure this is appropriate for your security model, especially in CI/CD environments.

Consider adding a note in documentation about the security implications of mounting these directories, particularly in shared or CI environments.


42-46: Remove trailing empty lines.

Multiple empty lines at the end of the file should be cleaned up for better code style.

-


-

-
+
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad2b508 and a6d6c03.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • build.sh (1 hunks)
  • contracts/injective-cosmwasm-mock/src/testing/test_exchange.rs (16 hunks)
  • contracts/injective-cosmwasm-mock/src/utils.rs (7 hunks)
  • packages/injective-testing/Cargo.toml (1 hunks)
  • packages/injective-testing/src/test_tube/exchange.rs (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/injective-testing/src/test_tube/exchange.rs (2)
packages/injective-testing/src/utils.rs (1)
  • dec_to_proto (26-28)
packages/injective-math/src/fp_decimal/from_str.rs (1)
  • must_from_str (46-48)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Suite
  • GitHub Check: Test Suite
🔇 Additional comments (11)
packages/injective-testing/Cargo.toml (1)

8-8: Version bump follows semantic versioning.

The patch version increment from 1.1.9 to 1.1.10 is appropriate for the changes introducing new functionality and refactoring to use mock constants.

contracts/injective-cosmwasm-mock/src/testing/test_exchange.rs (2)

27-30: Good refactoring to use centralized mock constants.

The import changes from local hardcoded constants to shared mock constants (MOCK_BASE_DENOM, MOCK_QUOTE_DENOM, etc.) and moving get_spot_market_id from local utils to the shared testing module improves maintainability and consistency across the codebase.


220-222:

Details

✅ Verification successful

Verify price scaling calculation logic.

The price calculation uses MOCK_BASE_DECIMALS - MOCK_BASE_DECIMALS which equals 0. This might be intentional but should be verified as it could indicate a copy-paste error where different constants should be used.


🏁 Script executed:

#!/bin/bash
# Check for similar price calculation patterns in the codebase
rg -A 2 -B 2 "MOCK_BASE_DECIMALS.*-.*MOCK_BASE_DECIMALS"

Length of output: 719


🏁 Script executed:

#!/bin/bash
# Locate the definition of MOCK_BASE_DECIMALS
rg -n "const MOCK_BASE_DECIMALS" -g "*.rs"

Length of output: 130


Price scaling logic verified
Both base and quote assets in the mocks use 18 decimals, so subtracting MOCK_BASE_DECIMALS – MOCK_BASE_DECIMALS intentionally yields zero—leaving the price at its human-entered value. No changes required.

build.sh (1)

1-14: Excellent documentation and usage examples.

The script header provides clear usage instructions and examples, making it easy for developers to understand how to use the build script.

packages/injective-testing/src/test_tube/exchange.rs (2)

578-607: New function implementation looks correct.

The launch_spot_market_custom_v2 function properly accepts custom base and quote decimals as parameters and uses them correctly in the v2 message. This provides good flexibility for testing scenarios.


642-644: Good consistency in using mock constants.

The replacement of hardcoded denomination strings with MOCK_ATOM_DENOM and MOCK_QUOTE_DENOM constants improves maintainability and consistency with the rest of the codebase.

contracts/injective-cosmwasm-mock/src/utils.rs (5)

34-38: LGTM! Clean import organization for mock constants.

The imports are well-organized and correctly bring in the necessary mock constants and utility functions from the injective_testing package.


85-86: Good replacement with mock constants.

Correctly replacing hardcoded denomination strings with mock constants for consistency in testing.


97-97: Consistent use of mock constants in account setup.

The mock constants are being used consistently for validator and owner account initialization and transfers.

Also applies to: 102-103, 106-106


107-114: Proper mock constant usage in denomination setup.

The add_denom_notional_and_decimal calls correctly use mock constants for both denomination and decimal values.


121-122: Good consistency in user setup and price scaling.

Mock constants are properly used in user account initialization and decimal conversion.

Also applies to: 162-162

Comment thread contracts/injective-cosmwasm-mock/src/testing/test_exchange.rs Outdated
Comment thread contracts/injective-cosmwasm-mock/src/utils.rs
@jbernal87 jbernal87 merged commit 22d8dfa into dev Jun 7, 2025
7 checks passed
@jbernal87 jbernal87 deleted the fix/injective_testing branch June 7, 2025 17:39
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