Skip to content

fix: injective-cosmwasm-stargate-example test fixes for chain 1.18#264

Merged
gorgos merged 1 commit into
devfrom
feat/upgrade-to-chain-1.18
Mar 3, 2026
Merged

fix: injective-cosmwasm-stargate-example test fixes for chain 1.18#264
gorgos merged 1 commit into
devfrom
feat/upgrade-to-chain-1.18

Conversation

@jbernal87
Copy link
Copy Markdown
Contributor

@jbernal87 jbernal87 commented Mar 3, 2026

Summary by CodeRabbit

  • Build & Infrastructure

    • Enhanced build script with improved argument validation and explicit alias resolution
    • Added architecture detection support (ARM64 and others) in build pipeline
    • Updated Docker optimizer to version 0.17.0
  • Build Tools

    • Updated Rust toolchain from 1.87.0 to 1.86.0

- Pin Rust toolchain to 1.86.0 to avoid bulk-memory wasm-opt failures
- Fix spot market query to use ExchangeQuerierV2 (InjectiveQuerier broken in 1.18)
- Fix test_query_derivative_market_mid_price_and_tob: switch to v2 query
  path and update assertions for human-readable price format
- Add workspace root build.sh with contract aliases (stargate, mock, atomic, dummy)
- Add contract-level build.sh for injective-cosmwasm-stargate-example
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

This pull request introduces infrastructure improvements and API migrations. The root build script is refactored to support contract alias resolution with architecture detection and Docker optimization, a new build script is added for ARM64-specific compilation, derivative query types are migrated from v1beta1 to v2, and Rust toolchain version is downgraded.

Changes

Cohort / File(s) Summary
Configuration & Toolchain
.gitignore, rust-toolchain.toml
Added CLAUDE.md to .gitignore; downgraded Rust toolchain version from 1.87.0 to 1.86.0.
Build Infrastructure
build.sh, contracts/injective-cosmwasm-stargate-example/build.sh
Refactored root build script with new resolve_alias() function for contract directory mapping; added mandatory argument validation; changed Docker mount paths and updated optimizer image tag to 0.17.0. Added new build script for ARM64 architecture-specific cosmwasm optimization.
Contract Query API
contracts/injective-cosmwasm-stargate-example/src/query.rs
Migrated from InjectiveQuerier to ExchangeQuerierV2 for spot market queries; updated market ID handling to use string-based input.
Test API Migrations
contracts/injective-cosmwasm-stargate-example/src/testing/test_exchange_derivative.rs
Updated derivative mid-price queries from v1beta1 to v2; changed result parsing from human_to_dec to FPDecimal::must_from_str; adjusted test ignore attribute to use conditional compilation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant build.sh as build.sh Script
    participant resolve_alias as resolve_alias()
    participant validate as Validation
    participant Docker as Docker Runner
    participant Optimizer as cosmwasm/optimizer

    User->>build.sh: Invoke with contract alias/path
    build.sh->>build.sh: Check if argument provided
    alt No argument
        build.sh->>User: Print usage & available contracts
    else Argument provided
        build.sh->>resolve_alias: Pass argument
        activate resolve_alias
        resolve_alias->>resolve_alias: Match against aliases
        resolve_alias-->>build.sh: Return contract directory
        deactivate resolve_alias
        build.sh->>validate: Check contract dir exists
        alt Invalid directory
            validate-->>User: Print error message
        else Valid
            validate-->>build.sh: Proceed
            build.sh->>build.sh: Detect host architecture
            build.sh->>Docker: Prepare mount paths & optimizer tag
            Docker->>Optimizer: Run container with detected arch
            Optimizer-->>Docker: Return optimized WASM
            Docker-->>User: Build complete
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 With aliases resolved and arms optimized for race,

Docker dances in ARM64's embrace,

Queries leap from v1 to v2's new place,

Build scripts unified at a quickened pace! 🚀✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: injective-cosmwasm-stargate-example test fixes for chain 1.18' accurately describes the main changes, which include test updates, query API migrations (InjectiveQuerier to ExchangeQuerierV2, v1beta1 to v2 query types), and infrastructure changes to support chain 1.18 compatibility.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/upgrade-to-chain-1.18

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@contracts/injective-cosmwasm-stargate-example/build.sh`:
- Around line 4-6: The architecture check currently only tests for "arm64" via
`arch` and misses Linux `aarch64`; update the detection in the build scripts so
they test for both "arm64" and "aarch64" (or use `uname -m` equivalently) and
set ARCH=-arm64 when either is present; apply the same change to the occurrences
in the three build scripts referenced, targeting the conditional that sets ARCH
and the use of `arch`/`uname -m`.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cbac7f2 and dda4034.

📒 Files selected for processing (6)
  • .gitignore
  • build.sh
  • contracts/injective-cosmwasm-stargate-example/build.sh
  • contracts/injective-cosmwasm-stargate-example/src/query.rs
  • contracts/injective-cosmwasm-stargate-example/src/testing/test_exchange_derivative.rs
  • rust-toolchain.toml

Comment on lines +4 to +6
if [[ $(arch) = "arm64" ]]; then
ARCH=-arm64
fi
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify architecture detection in build scripts

echo "=== Checking contracts/injective-cosmwasm-stargate-example/build.sh ==="
if [ -f "contracts/injective-cosmwasm-stargate-example/build.sh" ]; then
  echo "File exists. Content (first 30 lines):"
  head -n 30 contracts/injective-cosmwasm-stargate-example/build.sh | cat -n
else
  echo "File not found"
fi

echo ""
echo "=== Checking root build.sh ==="
if [ -f "build.sh" ]; then
  echo "File exists. Content (first 30 lines):"
  head -n 30 build.sh | cat -n
else
  echo "File not found"
fi

echo ""
echo "=== All shell scripts with 'arch' references ==="
rg -l "arch" --type sh 2>/dev/null | head -20

Repository: InjectiveLabs/cw-injective

Length of output: 1900


🏁 Script executed:

#!/bin/bash
# Check for other architecture detection patterns and verify behavior

echo "=== Searching for other architecture/platform detection patterns ==="
rg "(arch|aarch64|uname)" --type sh -A 2 -B 2 | head -80

echo ""
echo "=== Check if there are any Docker-related files that specify images ==="
rg "cosmwasm/optimizer" --type sh --type docker

Repository: InjectiveLabs/cw-injective

Length of output: 1016


🌐 Web query:

arch command output aarch64 vs arm64 Linux ARM64 systems

💡 Result:

On Linux, arch is essentially equivalent to uname -m (it prints the machine hardware name of the running kernel/userspace environment, not a distro “marketing” name). On ARM 64-bit systems you’ll commonly see either aarch64 or arm64, but in practice they refer to the same ISA/CPU execution state (ARMv8+ 64-bit). (en.wikipedia.org)

Why you often see aarch64 on Linux

  • aarch64 is the canonical GNU/ELF/GCC naming (e.g., toolchain triplets like aarch64-linux-gnu) and is what many Linux environments report via uname -m / arch. (lwn.net)
  • The Linux kernel port is commonly referred to as arm64 (a kernel-community naming choice), even though uname/arch may still say aarch64. (lwn.net)

How distros use the names

  • Debian/Ubuntu package architecture: arm64
  • Debian multiarch GNU triplet: aarch64-linux-gnu (wiki.debian.org)

Practical interpretation (Linux)

  • arch/uname -maarch64 ⇒ you’re in a 64-bit ARM environment.
  • arch/uname -marmv7l (etc.) ⇒ you’re in a 32-bit ARM environment.

Also note: in containers/VMs, arch reflects the container/guest environment’s kernel view, which can differ from what you think you’re targeting. (geekchamp.com)

Citations:


🏁 Script executed:

#!/bin/bash
# Search for any comments about Docker image variants or cosmwasm/optimizer documentation

echo "=== Search for comments about optimizer image variants ==="
rg "optimizer" -A 3 -B 3 --type sh | head -40

echo ""
echo "=== Check if there are README or doc files that mention architecture ==="
find . -maxdepth 2 -type f \( -name "README*" -o -name "*.md" \) | head -10

Repository: InjectiveLabs/cw-injective

Length of output: 1357


🏁 Script executed:

#!/bin/bash
# Check README and look for cosmwasm/optimizer image documentation

echo "=== README content (relevant sections) ==="
cat README.md | head -100

echo ""
echo "=== Search for build-related instructions in README ==="
rg -i "build|docker|arm" README.md -A 2 -B 2 | head -60

Repository: InjectiveLabs/cw-injective

Length of output: 5755


🌐 Web query:

cosmwasm/optimizer docker image arm64 aarch64 variants

💡 Result:

  • There isn’t a single multi-arch cosmwasm/optimizer image that automatically serves arm64/aarch64. CosmWasm publishes separate ARM64 images with an -arm64 suffix. aarch64 == arm64 in Docker platform terms. [1]
  • ARM64/AArch64 variants you can use:
    • cosmwasm/optimizer-arm64 (combined image; ARM, marked experimental) [1][2]
    • Deprecated but still listed: cosmwasm/rust-optimizer-arm64, cosmwasm/workspace-optimizer-arm64 [1][2]
  • Important note: the project warns the native ARM images can produce different wasm artifacts than the x86_64 images, so they’re discouraged for reproducible/production releases (primarily meant for Apple Silicon dev/testing). [1]
  • Publishing/building detail: releases are done separately (e.g., make publish-x86_64 and make publish-arm64). [3]

Sources: [1] CosmWasm/optimizer README, [2] Docker Hub cosmwasm org image list, [3] CosmWasm/optimizer “Releasing” wiki.


Architecture detection is too narrow and fails on Linux ARM64 hosts.

The arch command on Linux ARM64 systems returns aarch64, not arm64, so the current check never activates and ARM runners pull the wrong optimizer image. This issue exists in three files: contracts/injective-cosmwasm-stargate-example/build.sh (lines 4–6), build.sh (lines 10–13), and build_release.sh.

Suggested fix (apply to all three files)
-ARCH=""
-
-if [[ $(arch) = "arm64" ]]; then
-  ARCH=-arm64
-fi
+ARCH=""
+case "$(uname -m)" in
+  arm64|aarch64) ARCH="-arm64" ;;
+esac

Note: CosmWasm publishes separate ARM64 images (cosmwasm/optimizer-arm64), but these can produce different wasm artifacts than x86_64 images and are not recommended for production releases.

📝 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
if [[ $(arch) = "arm64" ]]; then
ARCH=-arm64
fi
case "$(uname -m)" in
arm64|aarch64) ARCH="-arm64" ;;
esac
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@contracts/injective-cosmwasm-stargate-example/build.sh` around lines 4 - 6,
The architecture check currently only tests for "arm64" via `arch` and misses
Linux `aarch64`; update the detection in the build scripts so they test for both
"arm64" and "aarch64" (or use `uname -m` equivalently) and set ARCH=-arm64 when
either is present; apply the same change to the occurrences in the three build
scripts referenced, targeting the conditional that sets ARCH and the use of
`arch`/`uname -m`.

@gorgos gorgos merged commit 37de961 into dev Mar 3, 2026
9 checks passed
@gorgos gorgos deleted the feat/upgrade-to-chain-1.18 branch March 3, 2026 21:02
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