Skip to content

test(wasm): cover stargate ibc transfer - #164

Merged
beer-1 merged 1 commit into
mainfrom
test/wasm-stargate-ibc-transfer
May 14, 2026
Merged

beer-1 merged 1 commit into
mainfrom
test/wasm-stargate-ibc-transfer

Conversation

@beer-1

@beer-1 beer-1 commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Closes: N/A

Adds a minimal CosmWasm contract that dispatches /ibc.applications.transfer.v1.MsgTransfer through stargate, plus a wasmtesting regression test that stores, instantiates, and executes it. The test registers a capture MsgServer for the transfer service so it can verify the decoded MsgTransfer fields without requiring a live IBC channel.

Critical files to review:

  • app/wasmtesting/stargate-ibc-transfer/src/lib.rs
  • app/wasmtesting/stargate-ibc-transfer/src/proto.rs
  • app/wasmtesting/stargate_test.go
  • app/wasmtesting/common_test.go

Validation:

  • go test ./app/wasmtesting -run 'Test_Stargate(Query|IBCTransfer)' -count=1
  • cargo test in app/wasmtesting/stargate-ibc-transfer
  • cosmwasm/optimizer-arm64:0.17.0 generated artifacts/stargate_ibc_transfer.wasm

Breaking changes: none.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change: N/A, no breaking change
  • targeted the correct branch: main
  • provided a link to the relevant issue or specification: N/A, requested directly
  • reviewed "Files changed" and left comments if necessary: N/A
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code: N/A
  • confirmed all CI checks have passed: pending CI

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • New WASM smart contract for executing IBC token transfers with configurable parameters (channel, receiver, denom, amount, timeout, memo).
  • Tests

    • Added comprehensive test suite validating IBC transfer message execution and field correctness.
  • Chores

    • Enhanced test infrastructure with extended module support.
    • Added build configurations and development tooling for WASM contract development.

@coderabbitai

coderabbitai Bot commented May 14, 2026 •

Copy link
Copy Markdown

Walkthrough

This PR adds support for testing IBC transfer contracts within the CosmWasm testing environment. It introduces a new stargate-ibc-transfer WASM contract that constructs and executes IBC transfer messages, extends the test infrastructure to support IBC transfer module operations, and provides an end-to-end integration test validating contract execution.

Changes

IBC Transfer WASM Contract Support

Layer / File(s) Summary
Contract message types and entry points
app/wasmtesting/stargate-ibc-transfer/src/msg.rs, app/wasmtesting/stargate-ibc-transfer/src/lib.rs
InstantiateMsg, ExecuteMsg (with IbcTransfer variant), and QueryMsg message types are defined. The execute entry point constructs a Stargate CosmosMsg via encode_msg_transfer, populates transfer attributes (action, port/channel, sender/receiver, denom, amount), and returns the response.
Stargate protobuf encoding for transfers
app/wasmtesting/stargate-ibc-transfer/src/proto.rs
Protobuf-style serialization for MsgTransfer is implemented via encode_msg_transfer and low-level encoding helpers (encode_coin, write_string, write_message, write_uint64, write_key, write_varint). Conditional omission of zero timeout_timestamp and empty/missing memo fields is handled. Unit test validates the exact encoded byte output.
Build configuration and artifacts
app/wasmtesting/stargate-ibc-transfer/Cargo.toml, app/wasmtesting/stargate-ibc-transfer/.cargo/config.toml, app/wasmtesting/stargate-ibc-transfer/.gitignore, app/wasmtesting/stargate-ibc-transfer/artifacts/checksums.txt
Cargo manifest defines package metadata, cdylib/rlib crate types, library feature, and release-mode optimizations; pinned cosmwasm-std and cosmwasm-schema dependencies with stargate feature. Build aliases (wasm, unit-test) and ignore patterns for macOS, backup files, build outputs, and IDE directories are configured. Artifact checksum for the compiled WASM binary is recorded.
Test environment setup
app/wasmtesting/common_test.go
ibctransfer module is imported and registered in ModuleBasics. TestKeepers struct gains a MsgRouter field, wired in _createTestInput to enable message routing during contract execution.
Integration test
app/wasmtesting/stargate_test.go
New Test_StargateIBCTransfer test validates end-to-end contract execution: WASM artifact is deployed (store code, instantiate), a custom MsgServer captures the MsgTransfer message, contract execution is invoked with transfer parameters, and assertions verify captured transfer fields (port, channel, token, sender, receiver, timeout, memo).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hoppy hops through chains with IBC cheer,
A WASM contract, crystal clear—
Stargate messages encoded fine,
Transfers flow cross-chain divine!
Tests confirm the contract's might, 🌟
IBC transfers done just right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the primary change: adding test coverage for a stargate IBC transfer capability in WebAssembly contracts.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/wasm-stargate-ibc-transfer

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

@beer-1
beer-1 marked this pull request as ready for review May 14, 2026 02:15
@beer-1
beer-1 requested a review from a team as a code owner May 14, 2026 02:15

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/wasmtesting/stargate-ibc-transfer/src/proto.rs (1)

76-99: ⚡ Quick win

Add a regression test for omitted default fields.

Lines 77-99 only validate the “memo+timeout present” path. Add a case with timeout_timestamp = 0 and memo = None/empty to lock in omission semantics for fields 7 and 8.

Suggested test addition
 #[cfg(test)]
 mod tests {
     use super::{encode_msg_transfer, MsgTransfer};
@@
     fn encodes_ibc_transfer_msg() {
@@
     }
+
+    #[test]
+    fn omits_zero_timeout_and_empty_memo() {
+        let encoded = encode_msg_transfer(MsgTransfer {
+            source_port: "transfer",
+            source_channel: "channel-0",
+            denom: "uinit",
+            amount: "123",
+            sender: "init1sender",
+            receiver: "cosmos1receiver",
+            timeout_timestamp: 0,
+            memo: None,
+        });
+
+        assert_eq!(
+            encoded,
+            vec![
+                10, 8, 116, 114, 97, 110, 115, 102, 101, 114, 18, 9, 99, 104, 97, 110, 110, 101,
+                108, 45, 48, 26, 12, 10, 5, 117, 105, 110, 105, 116, 18, 3, 49, 50, 51, 34, 11,
+                105, 110, 105, 116, 49, 115, 101, 110, 100, 101, 114, 42, 15, 99, 111, 115, 109,
+                111, 115, 49, 114, 101, 99, 101, 105, 118, 101, 114,
+            ]
+        );
+    }
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/wasmtesting/stargate-ibc-transfer/src/proto.rs` around lines 76 - 99, Add
a regression test inside the encodes_ibc_transfer_msg test (or as a new #[test])
that covers the omitted-defaults path by calling encode_msg_transfer with a
MsgTransfer where timeout_timestamp is 0 and memo is None (or empty) and assert
the produced bytes match the expected encoding that omits fields 7 and 8; locate
the encode_msg_transfer function and the MsgTransfer struct in this file to
craft the input and generate the expected vector, ensuring the assertion pins
omission semantics for those fields.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/wasmtesting/stargate-ibc-transfer/src/msg.rs`:
- Around line 14-16: Change ExecuteMsg::IbcTransfer's timeout_timestamp from u64
to cosmwasm_std::Uint64 in msg.rs so it serializes as a JSON string and
preserves 64-bit precision; then update the call site that builds the IBC
transfer proto (where proto::encode_msg_transfer is invoked in lib.rs) to
convert the Uint64 back to a raw u64 (e.g., timeout_timestamp.u64()) or
appropriate representation expected by encode_msg_transfer. Ensure imports for
Uint64 are added and types adjusted wherever ExecuteMsg::IbcTransfer is
constructed or pattern-matched.

---

Nitpick comments:
In `@app/wasmtesting/stargate-ibc-transfer/src/proto.rs`:
- Around line 76-99: Add a regression test inside the encodes_ibc_transfer_msg
test (or as a new #[test]) that covers the omitted-defaults path by calling
encode_msg_transfer with a MsgTransfer where timeout_timestamp is 0 and memo is
None (or empty) and assert the produced bytes match the expected encoding that
omits fields 7 and 8; locate the encode_msg_transfer function and the
MsgTransfer struct in this file to craft the input and generate the expected
vector, ensuring the assertion pins omission semantics for those fields.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7951b79a-6034-4682-9772-1e36e33d31c8

📥 Commits

Reviewing files that changed from the base of the PR and between e3d479f and f9dbdbd.

⛔ Files ignored due to path filters (2)
  • app/wasmtesting/stargate-ibc-transfer/Cargo.lock is excluded by !**/*.lock
  • app/wasmtesting/stargate-ibc-transfer/artifacts/stargate_ibc_transfer.wasm is excluded by !**/*.wasm
📒 Files selected for processing (9)
  • app/wasmtesting/common_test.go
  • app/wasmtesting/stargate-ibc-transfer/.cargo/config.toml
  • app/wasmtesting/stargate-ibc-transfer/.gitignore
  • app/wasmtesting/stargate-ibc-transfer/Cargo.toml
  • app/wasmtesting/stargate-ibc-transfer/artifacts/checksums.txt
  • app/wasmtesting/stargate-ibc-transfer/src/lib.rs
  • app/wasmtesting/stargate-ibc-transfer/src/msg.rs
  • app/wasmtesting/stargate-ibc-transfer/src/proto.rs
  • app/wasmtesting/stargate_test.go

@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.54%. Comparing base (325d4ab) to head (f9dbdbd).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #164   +/-   ##
=======================================
  Coverage   42.54%   42.54%           
=======================================
  Files          49       49           
  Lines        3154     3154           
=======================================
  Hits         1342     1342           
  Misses       1675     1675           
  Partials      137      137           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

traviolus
traviolus approved these changes May 14, 2026 •
@traviolus
traviolus self-requested a review May 14, 2026 04:29

@traviolus traviolus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@beer-1
beer-1 merged commit 6c1c8e5 into main May 14, 2026
11 checks passed
@beer-1
beer-1 deleted the test/wasm-stargate-ibc-transfer branch May 14, 2026 05:01
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