Skip to content

Conversation

@jfrank-summit
Copy link
Member

@jfrank-summit jfrank-summit commented Nov 6, 2025

Improve XDM Messenger Developer Experience

Summary

Enhances the developer experience for XDM messenger functions by improving type safety, documentation, and testing. This PR refactors initiateChannel and closeChannel to use user-friendly Chain types instead of raw Codec types, adds comprehensive JSDoc documentation with examples, and introduces explicit return type annotations across messenger and transfer functions.

Motivation and Context

The XDM messenger functions (initiateChannel and closeChannel) previously required developers to work with low-level Polkadot.js Codec types and lacked proper documentation.

This PR aligns the messenger functions with the existing patterns established in transfer.ts and info.ts, providing:

  • Consistent, type-safe APIs using the Chain type ('consensus' | { domainId: number })
  • Comprehensive documentation with real-world examples
  • Explicit return types for better IDE support and type safety
  • Full integration test coverage

Implementation Details

Type Safety Improvements

packages/auto-xdm/src/messenger.ts:

  • Changed initiateChannel parameter from Codec to Chain type
  • Changed closeChannel parameters from Codec and string to Chain and number | string | bigint
  • Added explicit return type: SubmittableExtrinsic<'promise', ISubmittableResult>
  • Utilizes existing chainToChainIdCodec helper for internal type conversion
  • Changed from async to sync (functions only create transactions, don't submit them)

packages/auto-xdm/src/transfer.ts:

  • Added explicit return type annotation: SubmittableExtrinsic<'promise', ISubmittableResult>
  • Removed outdated file header comment

Documentation Enhancements

Both initiateChannel and closeChannel now include:

  • Comprehensive JSDoc descriptions
  • Parameter documentation
  • Usage examples showing both consensus and domain chains
  • Best practices (e.g., checking allowlist before initiating channels)
  • Return type documentation

Testing

integration-tests/suites/auto-xdm/messenger.test.ts (new file):

  • E2E test for initiateChannel: verifies transaction creation, submission, and channel opening
  • E2E test for closeChannel: verifies transaction creation, submission, and channel closing
  • Tests use the wrapper functions (not raw API calls) to ensure proper type conversion
  • Tests include proper async handling with waitUntil helper

integration-tests/helpers/xdm.ts:

  • Updated setupXDM helper to use initiateChannel wrapper function instead of raw API calls
  • Improves consistency across the codebase and ensures type-safe channel initiation

@jfrank-summit jfrank-summit force-pushed the update-messenger branch 4 times, most recently from 112c459 to 0d2f71b Compare November 6, 2025 16:17
… initiateChannel function for improved clarity and maintainability
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the XDM messenger functions to improve developer experience through enhanced type safety, comprehensive documentation, and consistent API design. The changes align messenger functions with patterns established in transfer.ts and info.ts, making the SDK more intuitive to use.

  • Refactored initiateChannel and closeChannel to accept user-friendly Chain types instead of low-level Codec types
  • Added comprehensive JSDoc documentation with practical usage examples for all messenger functions
  • Introduced explicit return type annotations across messenger and transfer functions for better IDE support

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/auto-xdm/src/messenger.ts Complete refactoring with type-safe Chain parameters, comprehensive JSDoc documentation, explicit return types, and conversion from async to sync functions
packages/auto-xdm/src/transfer.ts Added explicit return type annotation and removed incorrect file header comment
integration-tests/suites/auto-xdm/messenger.test.ts New comprehensive integration tests for initiateChannel and closeChannel with proper async handling and state verification
integration-tests/helpers/xdm.ts Updated setupXDM to use the new type-safe initiateChannel wrapper function instead of raw API calls

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jfrank-summit jfrank-summit merged commit 3faea53 into main Nov 12, 2025
9 checks passed
@jfrank-summit jfrank-summit deleted the update-messenger branch November 12, 2025 13:33
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